FireWorks Plugin causes ServerCrash

Discussion in 'Spigot Plugin Development' started by dmmk218, Nov 28, 2018.

  1. Hey everybody,

    so I coded in my Plugin an extension for fireworks. When you do /feuerwerk for everybody is started an firework. So far so good. But I tried spamming the Command and my Server crashes because of the Tick speed. Can anybody tell me how to fix this?

    //edit: Another Problem is that not only one Rocket ist fired there are fired several Rockets.

    Here is the LINK to the Code Snippet

    Regards dmmk218
     
  2. Umm I think it's a bad idea to spawn the firework asynchronously. Everything related to changing the world like editing a block/spawning an entity should be done synchronously.

    Anyway, do you also have a crash log or anything?
     
  3. Yes sure I will upload it here.

    //edit: So now I changed the task to the following.

    Code (Java):
    this.task111 = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
     
  4. Code (Text):
    Description: Exception in server tick loop

    java.util.ConcurrentModificationException
    @MightyOne already told you the solution: Don't spawn fireworks asynchronously.
     
    • Funny Funny x 1
  5. Okay but how about the Problem that are several Rockets are deployed instead of only one?
    And is it maybe good to change the string to BukkitRunnable instead of Runnable?
     
  6. @dmmk218 each time you run your command your name is added another time to this weird list spieler111. So everytime there will spawn one more rocket.
     
    • Useful Useful x 1
  7. Okay so i need to do
    Code (Java):
    this.spieler111.set(task111, p.getName());
    instead of add?

    //edit: spieler is german for player
     
    #7 dmmk218, Nov 28, 2018
    Last edited: Nov 28, 2018
  8. If you want to have a list of players that won't have duplicates look into using a HashSet, similar to a list but it wont accept duplicate values, you could also just first check to see if the value is already in the list or not before adding it. Asl I'm not sure if you are or not but remember to clean out unneeded values in the list/maps otherwise you'll get a memory leak per say.In regard to the server crashing, depending on your version fireworks absolutely destroy the serve and specially client (something I've noticed with 1.13, all it takes is a handful of fireworks at once and you drop almost every frame you once had).
     
  9. Thanks for the information so im now a bit confused as i already said, im very new to java coding and I really dont know how to setup a hashset. Could you please explain or give me an example how to setup this?
     
  10. And is it possible to spawn the Firework just for the CommandSender? I'm getting crazy xD

    BTW: I'm Conding for version 1.8.8
     
  11. yes if they're a player
    if(cs instanceof HumanEntity) { } or just the typical if(cs instanceof Player)
     
  12. I put this into the code but the problem still persists:

    Code (Java):
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            Player p = (Player)sender;
             
            if ((p.hasPermission("wps.feuerwerk")) || (sender instanceof Player) || (cmd.getName().equalsIgnoreCase("feuerwerk")))
            {
                p.sendMessage("§2Du hast ein Feuerwerk gemacht!");
                this.spieler111.add(p.getName());
                timer();
                return true;
              }
           
            else {
                p.sendMessage("");
                p.sendMessage("§c§lDu benötigst für das Feuerwerk den §d§lSupreme-Rang!");
                p.sendMessage("§6§lKaufe ihn im Shop um /feuerwerk zu nutzen!");
                p.sendMessage("§f§lshop.woodpixel.net");
                p.sendMessage("");
            }

            return false;
          }
     
  13. First of all rhe CommandsSender sender in onCommand() can be a player, command block or just the console.
    Before you cast the sender to class Player, check if it really is one
    Code (Text):
    if (sender instanceof Player) {
        Player p =(Player) sender;
        ...
    }
       
    If you want your timer() method to have access to this player, you have to pass this object to it.
    The method's head should therefore look like:
    Code (Text):
    public void timer (Player theOneYouWantFireworkFor) {...}
    Then you can the use player in the Runnable for spawning firework
     
    #13 MightyOne, Nov 29, 2018
    Last edited: Nov 29, 2018