Solved "Unhandled exception executing command"

Discussion in 'Plugin Development' started by AlfieJay, Feb 29, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    AlfieJay

    So I'm fairly new to coding and have been poking around with ArrayLists which was going fine until this function decided not to work properly
    Code:
        public void delarenaCommand(Player p, String pluginTag, String[] args) {
            if (p.hasPermission("pvpt.delarena")) {
                if (args.length == 2) {
                    checkBOO = false;
                    for (String x : arenaLST) {
                        if (args[1].equalsIgnoreCase(x)) {
                            checkBOO = true;
                            arenaLST.remove(x);
                            p.sendMessage(pluginTag + "Arena '" + x + "' succefully deleted!");
                        }
                    }
                    if (checkBOO == false) {
                        p.sendMessage(pluginTag + "Sorry, the arena '" + args[1] + "' doesn't exist");
                    }
                } else {p.sendMessage(pluginTag + "Invalid format! Please use the format '/pvpt delarena [name]'");}
            } else {p.sendMessage(pluginTag + "Sorry, you don't have permission for this command!");}
        }
    The weird thing is, it does successfully delete commands but also gives the error afterwards. I've tried emitting the arena-doesn't-exit error but that didn't change it. Also if args[1] isn't present in the ArrayList then you get the custom error message I made with no error. Here's what pops up in the console when it fails:

    Code:
    [12:38:23 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'pvpt' in plugin PvPT v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:151) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:685) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1479) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1284) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:5) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:850) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:423) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:774) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:666) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        at java.lang.Thread.run(Thread.java:830) [?:?]
    Caused by: java.util.ConcurrentModificationException
        at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1009) ~[?:?]
        at java.util.ArrayList$Itr.next(ArrayList.java:963) ~[?:?]
        at jay.plugin.pvpt.main.delarenaCommand(main.java:68) ~[?:?]
        at jay.plugin.pvpt.main.onCommand(main.java:46) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        ... 15 more
    Any and as much help as possible would be appreciated, thanks :D
     
  2. Offline

    timtower Moderator Moderator

    @AlfieJay You can't loop over an arraylist and remove an item from it at the same time.
     
  3. Offline

    AlfieJay

    Oooh, I thought it might be something simple I was overlooking. Thanks for your help :D
     
Thread Status:
Not open for further replies.

Share This Page