I am receiving a NPE, and I made sure not a thing was null. Here is my stack trace:
11:08:08,790 ERROR [EventDispatcher] Error handling event:PlayerEvent[mythruna.s
erver.PlayerConnectionContext@516b7a] for type:PlayerJoined in handler:me.shzyl
o.essentials.Essentials$2@148a67a
java.lang.NullPointerException
at me.shzylo.essentials.commands.CmdSethome.registerCommand(CmdSethome.j
ava:54)
at me.shzylo.essentials.commands.Command.registerCommands(Command.java:3
2)
at me.shzylo.essentials.Essentials$2.newEvent(Essentials.java:42)
at me.shzylo.essentials.Essentials$2.newEvent(Essentials.java:1)
at mythruna.event.EventDispatcher.publishEvent(EventDispatcher.java:65)
at mythruna.server.GameServer$MessageObserver.login(GameServer.java:831)
at mythruna.server.GameServer$MessageObserver.messageReceived(GameServer
.java:841)
at mythruna.server.GameServer$MessageObserver.messageReceived(GameServer
.java:625)
at com.jme3.network.base.MessageListenerRegistry.messageReceived(Message
ListenerRegistry.java:74)
at com.jme3.network.base.DefaultServer.dispatch(DefaultServer.java:283)
at com.jme3.network.base.DefaultServer$Redispatch.messageReceived(Defaul
tServer.java:570)
at com.jme3.network.base.DefaultServer$Redispatch.messageReceived(Defaul
tServer.java:566)
at com.jme3.network.base.KernelAdapter.dispatch(KernelAdapter.java:184)
at com.jme3.network.base.KernelAdapter.createAndDispatch(KernelAdapter.j
ava:238)
at com.jme3.network.base.KernelAdapter.run(KernelAdapter.java:281)
me.shzylo.essentials.commands.CmdSethome.registerCommand(CmdSethome.java:54):
shell
.registerCommand( // THIS LINE
name,
cmd);
me.shzylo.essentials.commands.Command.registerCommands(Command.java:32):
new CmdSethome
(ess)
.registerCommand(); // THIS LINE
me.shzylo.essentials.Essentials$2.newEvent(Essentials.java:42):
command.registerCommands();
====
Full class codes:
Essentials.java:
package me.shzylo.essentials;
import java.io.File;
import me.shzylo.essentials.commands.Command;
import mythruna.event.EventDispatcher;
import mythruna.event.EventListener;
import mythruna.event.EventType;
import mythruna.event.PlayerEvent;
import mythruna.event.PlayerEvents;
import mythruna.server.event.ServerEvent;
import mythruna.server.event.ServerEvents;
public class Essentials {
public static final String NAME = "Essentials";
public static final File FOLDER = new File("scripts/" + NAME);
private static Command command;
@SuppressWarnings("rawtypes")
public static void onServerStart() {
EventDispatcher.getInstance().addListener(ServerEvents.serverStarted, new EventListener<ServerEvent>() {
public void newEvent(EventType<ServerEvent> type, ServerEvent e) {
if (!FOLDER.exists())
FOLDER.mkdir();
System.out.println("[Essentials] Loaded Successfully!");
}
});
}
public static void onPlayerJoin() {
command = new Command(new Essentials());
System.out.println("essentials debug 1");
EventDispatcher.getInstance().addListener(PlayerEvents.playerJoined, new EventListener<PlayerEvent>() {
public void newEvent(EventType<PlayerEvent> type, final PlayerEvent e) {
System.out.println("essentials debug 2");
command.setShell(e.getContext().getShell());
System.out.println("essentials debug 3");
command.setPlayerEvent(e);
System.out.println("essentials debug 4");
command.registerCommands();
System.out.println("essentials debug 5");
}
});
}
}
Command.java:
package me.shzylo.essentials.commands;
import me.shzylo.essentials.Essentials;
import mythruna.event.PlayerEvent;
import org.progeeks.tool.console.Shell;
public class Command {
protected Essentials ess;
protected Shell shell;
protected PlayerEvent event;
public Command(Essentials instance) {
System.out.println("command debug 1");
this.ess = instance;
}
public void setShell(Shell shell) {
System.out.println("command debug 2");
this.shell = shell;
}
public void setPlayerEvent(PlayerEvent e) {
System.out.println("command debug 3");
this.event = e;
}
public void registerCommands() {
System.out.println("command debug 4");
new CmdSethome
(ess)
.registerCommand();
}
}
CmdSethome.java:
package me.shzylo.essentials.commands;
import me.shzylo.essentials.Essentials;
import org.progeeks.cmd.Environment;
import org.progeeks.cmd.Result;
import org.progeeks.tool.console.ShellCommand;
import org.progeeks.tool.console.ShellEnvironment;
public class CmdSethome extends Command {
public CmdSethome(Essentials ess) {
super(ess);
System.out.println("cmdsethome debug 1");
}
public void registerCommand() {
System.out.println("cmdsethome debug 2");
String name = "sethome";
final String desc = "set your home at your current location.";
final String[] help = null;
System.out.println("cmdsethome debug 3");
ShellCommand cmd = new ShellCommand() {
private static final long serialVersionUID = 1L;
public Result execute(Environment env) {
return null;
}
public boolean isSimple() {
System.out.println("cmdsethome debug 4");
return false;
}
public String[] getHelp() {
System.out.println("cmdsethome debug 5");
return help;
}
public String getDescription() {
System.out.println("cmdsethome debug 6");
return desc;
}
public int execute(ShellEnvironment shellEnv, String str) {
System.out.println("cmdsethome debug 7");
executeCommand();
return 0;
}
};
System.out.println("cmdsethome debug 8");
shell
.registerCommand(
name,
cmd);
}
public void executeCommand() {
/*try {
EntityId playerEntity = event.getContext().getPlayer();
GameSystems systems = event.getContext().getSystems();
EntityData ed = systems.getEntityData();
Position pos = ed.getComponent(playerEntity, Position.class);
Vector3f location = pos.getLocation(); // null float playerX
float playerX = location.getX();
float playerY = location.getY();
float playerZ = location.getZ();
String playerName = event.getContext().getPlayerData().get("characterInfo.name");
System.out.println(playerName + "'s location is: " + playerX + ", " + playerY + ", " + playerZ);
} catch (Exception e) {
e.printStackTrace();
}*/
event.getContext().echo("setting home randomly");
}
}
As you can see, I did the debug test for it all, and when I did the debug this was the order, everything was set accordingly so nothing went null:
essentials debug 2
command debug 2
essentials debug 3
command debug 3
essentials debug 4
command debug 4
command debug 1
cmdsethome debug 1
cmdsethome debug 2
cmdsethome debug 3
cmdsethome debug 8
If you can just tell me what is causing this problem, I will feel so stupid if it was just a silly little mistake.