EventException Error on Left air click

Discussion in 'Spigot Plugin Development' started by pr0c0dd3r1337, Apr 13, 2017.

  1. When I Left click to air I get this error

    Error:
    [21:40:13 ERROR]: Could not pass event PlayerInteractEvent to test v0.1
    org.bukkit.event.EventException
    at org.bukkit.plugin.EventExecutor$1.execute(EventExecutor.java:46) ~[patched_1.11.2.jar:git-Paper-1063]
    at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78) ~[patched_1.11.2.jar:git-Paper-1063]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[patched_1.11.2.jar:git-Paper-1063]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:517) ~[patched_1.11.2.jar:git-Paper-1063]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:502) ~[patched_1.11.2.jar:git-Paper-1063]
    at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:233) ~[patched_1.11.2.jar:git-Paper-1063]
    at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:200) ~[patched_1.11.2.jar:git-Paper-1063]
    at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:196) ~[patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1422) ~[patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:24) ~[patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:5) ~[patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14) ~[patched_1.11.2.jar:git-Paper-1063]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
    at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:830) [patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:403) [patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:754) [patched_1.11.2.jar:git-Paper-1063]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:652) [patched_1.11.2.jar:git-Paper-1063]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.NullPointerException
    at me.dave.test.Main.onInteract(Main.java:57) ~[?:?]
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor496.execute(Unknown Source) ~[?:?]
    at org.bukkit.plugin.EventExecutor$1.execute(EventExecutor.java:44) ~[patched_1.11.2.jar:git-Paper-1063]
    ... 19 more



    Code:

    @EventHandler
    public void onInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();

    if (e.getItem().getItemMeta().getDisplayName() == null) {
    return;
    }


    if ((e.getAction() == Action.RIGHT_CLICK_AIR) && (e.getItem().getType() == Material.STAINED_CLAY)
    &&(e.getItem().getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', "&aasd")))) {
    if(e.getPlayer().isOnGround()){

    p.sendMessage("u are on the ground");

    } else {

    p.sendMessage("u are not on the ground");

    }
    }
    }
     
  2. Check if e.getItem is null and if e.getItem().getItemMeta() is null
     
  3. Not working :c
     
  4. Please send your new code inside a code tag
     
  5. Code (Text):
    @EventHandler
    public void onInteract(PlayerInteractEvent e) {
    Player p = e.getPlayer();

    if (e.getItem().getItemMeta().getDisplayName() == null) {
    return;
    }


    if ((e.getAction() == Action.RIGHT_CLICK_AIR) && (e.getItem().getType() == Material.STAINED_CLAY)
    &&(e.getItem().getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', "&aasd")))) {
    if(e.getPlayer().isOnGround()){

    p.sendMessage("u are on the ground");

    } else {

    p.sendMessage("u are not on the ground");

    }
    }
    }
     
  6. You asked the same question on bukkit -_-
     
  7. What's the new error in a code tag and what is on the line of the error
     
  8. Like mentioned before, they might not be holding an ItemStack at all (which might result into null, I heard rumours about AIR stacks instead. As for ItemMeta, it'll only be null when you call getItemMeta() on AIR stacks (but this doesn't mean you should call it, since it creates a new ItemMeta instance for no good reason). What you should effectively check before accessing it's display name:
    • PlayerInteractEvent::getItem() != null
    • ItemStack::hasItemMeta()
    • ItemMeta::hasDisplayName()