Weird Null Pointer

Discussion in 'Spigot Plugin Development' started by JacobUNIQUE, Jul 24, 2018.

  1. I am getting this crazy weird error,

    [14:44:46 ERROR]: Could not pass event PlayerInteractEvent to phoenix v1
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot.jar:git-Spigot-3d850ec-809c399]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot.jar:git-Spigot-3d850ec-809c399]
    at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:235) [spigot.jar:git-Spigot-3d850ec-809c399]
    at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:202) [spigot.jar:git-Spigot-3d850ec-809c399]
    at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:198) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:989) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:26) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-3d850ec-809c399]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-3d850ec-809c399]
    at java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.NullPointerException
    at com.glorial.phoneix.spells.lowerWand.lowerWand(lowerWand.java:20) ~[?:?]
    at com.glorial.phoneix.spells.wandMechanics.wandStateListener(wandMechanics.java:68) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    ... 18 more
    [14:44:46 FATAL]: Error executing task
    java.util.concurrent.ExecutionException: java.lang.AssertionError: TRAP
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:?]
    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:47) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-3d850ec-809c399]
    at java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.AssertionError: TRAP
    at net.minecraft.server.v1_12_R1.ItemStack.F(ItemStack.java:100) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.ItemStack.setCount(ItemStack.java:831) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PlayerInteractManager.a(PlayerInteractManager.java:413) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1004) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:26) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) ~[spigot.jar:git-Spigot-3d850ec-809c399]
    ... 5 more

    But you see, on line twenty I am making sure the item ISNT null.
    Code (Java):
    Player player = event.getPlayer();
            Inventory newInv = raisedInv.get(player.getUniqueId());
            player.getInventory().clear();
            for(ItemStack item : newInv.getContents()) {

                if( !(item == null)&& !item.getType().equals(Material.AIR) && item.hasItemMeta()) {
                    player.getInventory().addItem(item);

                }


            }
    *line twenty is the one with the if statement*
    I am storing a player inventory in a hashmap, because I am working on something like inventory swapping, where they have two inventories. If someone could help me with this what would be perfect :)
     
    #1 JacobUNIQUE, Jul 24, 2018
    Last edited: Jul 24, 2018
  2. this is what throws it
    Object#equals can only be called on, well, objects. null is not an object. `null.equals(null)` does not return true, but throws an NPE. You need to use ==.
     
    • Like Like x 1
  3. o
    h thanks, i didnt know that :) but i am still getting that second error, do you know anything about that?
     
  4. A quick google search shows that there is an existing bug report for that error. My suggestion would be to try cancelling the interact event (both main-hand and off-hand) when your code is triggered. Alternatively, you could try waiting 1 tick after the interact event and then apply the inventory changes. I don't know if either of these will work, but they seem likely to me -shrug-
     
  5. When I cancel the event, the error goes away, but it still doesnt work right


    OH NVM! it is when in survival the error goes away, but my thing still isnt working, that might be my fault