I am getting an error on my spigiot(based on bukkit) plugin that I was developing. I followed a code tutorial on a minigame plugin and downloaded the source code()which worked fine. I edited the code after and added my own weapon and started developing a multi-player spawn system. Now, when I left the game, I get a null pointer exception, even with the checks I put in place after getting this the first time.
[11:36:49] [Server thread/INFO]: Zippynik issued server command: /mb l 1[11:36:49] [Server thread/ERROR]: nullorg.bukkit.command.CommandException: Unhandled exception executing command 'mb' in plugin MagicBattle v1.2.0at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_80]at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_80]at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]at java.lang.Thread.run(Unknown Source) [?:1.7.0_80]Caused by: java.lang.NullPointerExceptionat me.pogostick29dev.magicbattle.PlayerData.restorePlayer(Arena.java:212) ~[?:?]at me.pogostick29dev.magicbattle.Arena.removePlayer(Arena.java:86) ~[?:?]at me.pogostick29dev.magicbattle.commands.Leave.onCommand(Leave.java:17) ~[?:?]at me.pogostick29dev.magicbattle.CommandManager.onCommand(CommandManager.java:65) ~[?:?]at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.8.8-R0.1.jar:git-Bukkit-d3e0b6f]... 15 more
Heres the code for the PlayerData class(part of Arena.java)
public int playerNumber;
private Player puu;
private String playerName;
private ItemStack[] contents, armorContents;
private Location location;
protected PlayerData(Player p,int pnum) {
this.playerName = p.getName();
this.contents = p.getInventory().getContents();
this.armorContents = p.getInventory().getArmorContents();
this.location = p.getLocation();
this.playerNumber = pnum;
this.puu = p;
}
protected Player getPlayer() {
return puu;
}
protected void restorePlayer() {
Player p;
if (puu != null){
p = puu;}
else{
Bukkit.broadcastMessage("puu is invalid");
return;
}
if (contents !=null){
p.getInventory().setContents(contents);}
if (armorContents !=null){
p.getInventory().setArmorContents(armorContents);}
if (location !=null){
p.teleport(location);}
return;
}
protected boolean isForPlayer(Player p) {
return playerName.equalsIgnoreCase(p.getName());
}
}
, for the Arena class code concerning leaving the arena.
public void removePlayer(Player p) {
if(getPlayerData(p) !=null){
PlayerData d = getPlayerData(p);
d.restorePlayer();
data.remove(d);
}else{
Bukkit.broadcastMessage("PlayerData is null");
}
currentPlayers--;
for (Sign s : signs) {
s.setLine(2, currentPlayers + "");
s.update();
}
if (currentPlayers == 1) {
stop(data.get(0).getPlayer());
} else if (currentPlayers == 0) {
stop();
}
}
and finally for Leave.java
public class Leave extends MagicCommand {
public void onCommand(Player p, String[] args) {
if (ArenaManager.getInstance().getArena(p) == null) {
MessageManager.getInstance().msg(p, MessageType.BAD, "You are not already in an arena!");
return;
}
ArenaManager.getInstance().getArena(p).removePlayer(p);
}
public Leave() {
super("Leave an arena.", "", "l");
}
}
if you need anything else, its on github https://github.com/Zippynik/MagicBattle
Edit: 212 the beggining of restorePlayer 86 the beggining of RemovePlayer 17: Beginning of ArenaManager.getInstance().getArena(p).removePlayer(p);
Edit 2: Added null checks for all variables used in restorePlayer and removePlayer... Still returning null. Could the problem be ArenaManager.getInstance() or getArena()