Solved Array List in Abstract Class uneditable

Discussion in 'Plugin Development' started by AlfieJay, Mar 25, 2020.

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

    AlfieJay

    So I've been working on a plugin, this specific part of it stores players who have joined and lets you view the players who are currently playing by storing them in an ArrayList<Player>. Below is the code and the error message I get from the playerjoin command. Thanks for any help you're able to give :D

    Code:
        // PLAYERJOIN COMMAND //
       
        public void playerjoinCommand(Player p) {
            if (p.hasPermission("timereapers.join")) {
                if (data.gameOpenBOO) {
                    if (!(data.playerLST.contains(p))) {
                        data.playerLST.add(p);
                        p.sendMessage(config.pluginTag + "You have successfully joined the game!");
                    } else p.sendMessage(config.pluginTag + "It appears you have already joined the game!");
                } else p.sendMessage(config.pluginTag + "The game is not currently open to join!");
            } else p.sendMessage(config.nopermsMSG);
        }
       
        // LISTPLAYERS COMMAND //
       
        public void listplayersCommand(Player p) {
            if (p.hasPermission("timereapers.listplayers")) {
                if (!(data.playerLST.isEmpty())) {
                    p.sendMessage(config.pluginTag + "The following players are in the game:");
                    for (Player x : data.playerLST) {
                        p.sendMessage(ChatColor.GRAY + "- " + x);
                    }
                } else p.sendMessage(config.pluginTag + "It appears there aren't any players!");
            } else p.sendMessage(config.nopermsMSG);
        }
    Code:
    public abstract class data {
       
        static ArrayList<Player> playerLST = null;
       
        static Boolean gameOpenBOO = true;
       
    }
    Error message:

    Code:
    [19:38:00 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tr' in plugin TimeReapers 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.lang.NullPointerException
        at jay.plugin.timereapers.main.playerjoinCommand(main.java:69) ~[?:?]
        at jay.plugin.timereapers.main.onCommand(main.java:23) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Paper-1.12.2-b1574.jar:git-Paper-1574]
        ... 15 more
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    AlfieJay

    Oooh, that fixed it. Thanks :D
     
Thread Status:
Not open for further replies.

Share This Page