Issue spawning HumanEntity

Discussion in 'Plugin Development' started by Aetherspawn, Jan 26, 2012.

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

    Aetherspawn

    New Problem:

    Code:
    public class Generals extends JavaPlugin {
    public void onEnable() {
    //
    }
    public void onDisable() {
    //
    }
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = null;
    if (sender instanceof Player) {
    player = (Player) sender;
    }
    if(cmd.getName().equalsIgnoreCase("spawnnpc") && (player != null)) {
    WorldServer ws = getWorldServer(player.getWorld());
    Human hTest = new Human(getMinecraftServer(player.getServer()), ws, "Bob", new ItemInWorldManager(ws), player.getLocation());
    return true;
    }
    return false; 
    }
    private static WorldServer getWorldServer(World world) {
            return ((CraftWorld) world).getHandle();
        }
        private static MinecraftServer getMinecraftServer(Server server) {
            return ((CraftServer) server).getServer();
        }
    }
    Code:
    public class Human extends EntityPlayer {
    public Human(MinecraftServer msServer, World wTargetWorld, String s,
    ItemInWorldManager iwmItemManager, Location loc) {
    super(msServer, wTargetWorld, s, iwmItemManager);
    iwmItemManager.setGameMode(0);
    this.setPosition(loc.getX(), loc.getY(), loc.getZ());
    wTargetWorld.addEntity(this);
    wTargetWorld.players.remove(this);
    }
     
    }
    And I get this error when I /spawnnpc although the NPC called "Bob" does appear inside the server (and the server stops running).

    Code:
    [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'spawnnpc' in plugin Generals v0.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:386)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:777)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:737)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:725)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:33)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
    at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:536)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.NullPointerException
    at net.minecraft.server.EntityTrackerEntry.b(EntityTrackerEntry.java:191)
    at net.minecraft.server.EntityTracker.track(EntityTracker.java:33)
    at net.minecraft.server.WorldManager.a(WorldManager.java:16)
    at net.minecraft.server.World.c(World.java:918)
    at net.minecraft.server.WorldServer.c(WorldServer.java:175)
    at net.minecraft.server.World.addEntity(World.java:911)
    at net.minecraft.server.World.addEntity(World.java:864)
    at com.aetherspawn.generals.Human.<init>(Human.java:20)
    at com.aetherspawn.generals.Generals.onCommand(Generals.java:35)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    ... 12 more
    2012-01-27 11:33:35 [SEVERE] java.lang.NullPointerException
    2012-01-27 11:33:35 [SEVERE]at net.minecraft.server.EntityTrackerEntry.b(EntityTrackerEntry.java:191)
    2012-01-27 11:33:35 [SEVERE]at net.minecraft.server.EntityTracker.updatePlayers(EntityTracker.java:144)
    2012-01-27 11:33:35 [SEVERE]at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:541)
    2012-01-27 11:33:35 [SEVERE]at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
    2012-01-27 11:33:35 [SEVERE]at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    2012-01-27 11:33:35 [SEVERE] Unexpected exception
    java.lang.NullPointerException
    at net.minecraft.server.EntityTrackerEntry.b(EntityTrackerEntry.java:191)
    at net.minecraft.server.EntityTracker.updatePlayers(EntityTracker.java:144)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:541)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    
    Any help about why the error happens is appreciated.
     
  2. Offline

    Nitnelave

    Try and put the plyer.getServer() between parenthesis to do the cast, that might help
     
  3. Offline

    Aetherspawn

    Okay I'll give it a shot
    Edit: Tried putting brackets around all the (xx)player.__() casts and it didn't help.

    -- Bump --

    Got it working, but there is a new problem now.

    fullwall

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
Thread Status:
Not open for further replies.

Share This Page