EventException Error on Left air click

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

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

    davekov5

    When left click to air with simple hand 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
     
  2. @davekov5
    Can you please paste your code? There is an error in class "Main.java" at line 57. But if you don't show what's in there, I cannot help you ;)
     
  3. Offline

    davekov5

    @Erumeldor

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

    @Erumeldor
    @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");

    }
    }
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 13, 2017
  4. Offline

    yPedx

    @davekov5
    Change "&aasd" to "§" here;
    Code:
    ChatColor.translateAlternateColorCodes('&', "&aasd")))) {
    Aren't you able to use replaceAll("&", "§") instead?
     
  5. Offline

    Zombie_Striker

    @yPedx
    NO. Do not add paragraph symbols. There have been many threads discussing this. If you want to add color to text, use Chatcolors. If you want the chatcolors or strings to be configurable, then you would use TransleateColorCodes.

    @davekov5
    The item can be null. You have to null check item before getting the item meta, and you have to check if the item has item meta before getting the display name. That is most likely what is causing the problem.
     
    Ragnarok_ likes this.
  6. Offline

    Ragnarok_

    @davekov5 Don't know if this awnser's you're question but you don't need a curly bracket for returning something. Simply just return it like so:
    Code:
    if (e.getItem().getItemMeta().hasDisplayName() == null) return;
    Also, from what zombie said, you're checking the if the item by using a get method, and that's not going to go well for you. I updated the code, didn't notice it to be honest, but you should fix that as well.
     
    Last edited: Apr 13, 2017
  7. Offline

    Zombie_Striker

    @Ragnarok_
    Don't null check the string, as it would be a blank string if the display name dis not exist. Instead, use hasDisplayName()
     
  8. Offline

    davekov5

    Thanks i will try it :D
     
Thread Status:
Not open for further replies.

Share This Page