Solved (1.8.8) NullPointerException on reload

Discussion in 'Spigot Plugin Development' started by Heretere, May 10, 2016.

  1. Everytime I reload the server on version 1.8.8 I get a NullPointerException

    The error when I reload
    Code (Text):

    [16:26:40 WARN]: Unexpected exception while parsing console command "reload"
    org.bukkit.command.CommandException: Unhandled exception executing 'reload' in org.bukkit.command.defaults.ReloadCommand(reload)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:148) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
            at net.minecraft.server.v1_8_R3.WorldData.setDifficulty(WorldData.java:592) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:692) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            ... 7 more
     
    now I see the null pointer is at WorldData.setDifficulty() but I don't see how that relates to my plugin.
     
  2. This might be null
    May I see this method, please?
     
  3. @Pr0totype2
    This isn't from my plugin. This is an NMS method the only thing I could think it would relate to is the NPC I spawn which would be this
    Code (Text):

        public static void spawnNPC(Plugin plugin, Server server, Player player) {
            if (getNPC(player) != null) {
                return;
            }

            try {
                Bukkit.broadcastMessage("spawn");
                Object enumAddPlayer = Reflections.getClass("{nms}.PacketPlayOutPlayerInfo").getDeclaredClasses()[2].getField("ADD_PLAYER").get(null);
                Object enumRemovePlayer = Reflections.getClass("{nms}.PacketPlayOutPlayerInfo").getDeclaredClasses()[2].getField("REMOVE_PLAYER").get(null);
                Constructor<?> entityPlayer = Reflections.getClass("{nms}.EntityPlayer").getConstructor(Reflections.getClass("{nms}.MinecraftServer"), Reflections.getClass("{nms}.WorldServer"), GameProfile.class, Reflections.getClass("{nms}.PlayerInteractManager"));

                Object minecraftServer = Reflections.getClass("{cb}.CraftServer").cast(server);
                Object worldServer = Reflections.getClass("{cb}.CraftWorld").cast(player.getWorld());
                Object playerInteractManager = Reflections.getClass("{nms}.PlayerInteractManager").getConstructor(Reflections.getClass("{nms}.World")).newInstance(worldServer.getClass().getMethod("getHandle").invoke(worldServer));

                Object npc = Array.newInstance(Reflections.getClass("{nms}.EntityPlayer"), 1);
                Array.set(npc, 0, entityPlayer.newInstance(minecraftServer.getClass().getMethod("getServer").invoke(minecraftServer), worldServer.getClass().getMethod("getHandle").invoke(worldServer), new GameProfile(UUID.randomUUID(), ""), playerInteractManager));

                Array.get(npc, 0).getClass().getMethod("teleportTo", Location.class, boolean.class).invoke(Array.get(npc, 0), getLocation(player.getLocation()), false);

                Constructor<?> packetPlayOutPlayerInfo = Reflections.getClass("{nms}.PacketPlayOutPlayerInfo").getConstructors()[1];
                Constructor<?> packetPlayOutNamedEntitySpawn = Reflections.getClass("{nms}.PacketPlayOutNamedEntitySpawn").getConstructor(Reflections.getClass("{nms}.EntityHuman"));

                Reflections.sendPlayerPacket(player, packetPlayOutPlayerInfo.newInstance(enumAddPlayer, npc));
                Reflections.sendPlayerPacket(player, packetPlayOutNamedEntitySpawn.newInstance(Array.get(npc, 0)));
                Reflections.sendPlayerPacket(player, packetPlayOutPlayerInfo.newInstance(enumRemovePlayer, npc));

                addNPC(player, Array.get(npc, 0));
                Bukkit.getPluginManager().callEvent(new NPCSpawnEvent(plugin, player));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
     
     
  4. Oh dang wait this might not even be from any plugin at all
     
  5. @Pr0totype2
    Alright I just tested and this error only happens when I have an NPC spawned and the server is reloaded.
     
  6. Huh
     
  7. What difficulty is your server and what are you trying to spawn?
     
  8. @ExoticCode
    The difficulty is normal and I am spawning a player NPC.
    At this point I believe I pinpointed the problem i just need to figure out how to fix it.
    The problem is that the server is trying to send a packet to the fake player but the fake player doesn't have a playerConnection so it is causing an NullPointerException.
     
  9. 4chan

    Supporter

    why are you reloading
    it says not to reload
    stop it i say
    stop it
     
    • Funny Funny x 2
  10. I managed to fix the problem by creating an NPC wrapper for each version of minecraft that my plugin supports. The NPC wrappers handle packets sent to the NPC's and "cancels" them. Thank you for all your help! :)