Brent Scheinman
Brent Scheinman

Reputation: 13

Bukkit Java Coding, on disable not working

Hey so I searched a lot of places and found nothing, so I decided to ask why here, for some reason, I keep getting an error with the onDisable method in my plugin. All it has is that it saves the HashMaps of the 3 teams and puts it in the config. Here is what it is:

    @Override
    public void onDisable() {
            // *********************Saving Human Team**************************
            List<String> h = getConfig().getStringList("humanTeam");

            for (Player p : humanTeam.keySet()) {
                    h.add(p.getName());
            }

            getConfig().set("humanTeam", h);
            // ****************************************************************

            // *********************Saving Monster Team************************
            List<String> m = getConfig().getStringList("monsterTeam");

            for (Player p : monsterTeam.keySet()) {
                    h.add(p.getName() + ":" + monsterTeam.get(p));
            }

            getConfig().set("monsterTeam", m);
            // ****************************************************************

            // *********************Saving Monster Team************************
            List<String> r = getConfig().getStringList("runnerRole");

            for (Player p : runnerRole.keySet()) {
                    r.add(p.getName());
            }

            getConfig().set("runnerRole", r);
            // ****************************************************************

            saveConfig();

    }

and here is the error from the server:

[20:20:48 INFO]: [MineRunner] Disabling MineRunner v1.0
[20:20:48 ERROR]: Error occurred while disabling MineRunner v1.0 (Is it up to da
te?)
java.lang.NullPointerException
        at me.joejoethemonkey.MineRunner.onDisable(MineRunner.java:70) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:323) ~[c
raftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoade
r.java:351) [craftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManag
er.java:423) [craftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginMana
ger.java:416) [craftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.clearPlugins(SimplePluginManage
r.java:457) [craftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:69
4) [craftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.Bukkit.reload(Bukkit.java:543) [craftbukkit.jar:git-Bukkit
-33d5de3]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
25) [craftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
0) [craftbukkit.jar:git-Bukkit-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
r.java:625) [craftbukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
nection.java:1058) [craftbukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
:919) [craftbukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:37) [craft
bukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:9) [craftb
ukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [cra
ftbukkit.jar:git-Bukkit-33d5de3]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
?:1.8.0_31]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
56) [craftbukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:2
84) [craftbukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
09) [craftbukkit.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
:517) [craftbukkit.jar:git-Bukkit-33d5de3]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]`enter code here`

Upvotes: 0

Views: 214

Answers (1)

Bizzycola
Bizzycola

Reputation: 119

Well there is a few things that could be wrong here. First off, as you may know, a NullPointerException means something is null. Not set to anything. This could be caused by the get config method you use. When you get a configuration option I suggest testing the variable you place it in with an if statement like if(h == null). If it is null, you will need to check your config and the Bukkit docs to make sure you've used it correctly.

It is possible to know where the error comes from, according to your exception information it is on line 70. Since you only showed me one method I cannot determine which line that is.

Next thing I see is you are using Player in your for loop for a list full of strings. I don't know a lot about bukkkit but I am not sure if they can be initialised that way. If I am wrong then it's fine. But maybe one of the players in your loop is null so be sure to check if p == null as well.

You can probably output to the bukkkit console with something to let you know if your if statement said they were null. It might be only for one player and safety ignored as long as you only use them when they aren't null

Let me know how it goes.

Upvotes: 1

Related Questions