Solved EventException on InteractEvent (ItemMeta issue)

Discussion in 'Plugin Development' started by Anonymous350, Jan 26, 2015.

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

    Anonymous350

    I'm checking if the item has a certain ItemMeta (If so open Gui). The whole point of this is that when using a regular chest/item it won't open the GUI, which works perfectly fine. However when I click without a block in my inventory (hand) it throws a EventException. Error on line 183 (InfoManager) and 220 (Navigator).

    Line 183 & 220:
    Code:
    ItemMeta im = is.getItemMeta();
    Event: (Same events for both classes)
    Code:
    @EventHandler
       public void onPlayerInteract(PlayerInteractEvent event) {
           Action a = event.getAction();
                   ItemStack is = event.getItem();
                   ItemMeta im = is.getItemMeta();
               
        if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
            return;
    
        if(event.getPlayer().getWorld().getName().equals("Spawnworld")) {
        
            if (is.getType() == Material.COMPASS)
                if(im.hasDisplayName()) {
                    if(ChatColor.stripColor(im.getDisplayName()).equals("Navigation")) {
                        openGUI(event.getPlayer());
                    }
                }
           }
       }
    
    }
    Error:
    Console Error (open)

    [00:25:06 ERROR]: Could not pass event PlayerInteractEvent to UltimateHub v1.7.4

    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:297) ~[craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:209) [craftbukkit_server.jar:git-Bukkit-1092acb
    ]
    at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInt
    eractManager.java:462) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :693) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:50) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:80) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [cra
    ftbukkit_server.jar:git-Bukkit-1092acb]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_25]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_25]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    43) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:2
    84) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:5
    98) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :506) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
    Caused by: java.lang.NullPointerException
    at me.anonymous350.hub.Navigator.onPlayerInteract(Navigator.java:220) ~[
    ?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:295) ~[craftbukkit_server.jar:git-Bukkit-1092acb]
    ... 16 more
    [00:25:06 ERROR]: Could not pass event PlayerInteractEvent to UltimateHub v1.7.4

    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:297) ~[craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:209) [craftbukkit_server.jar:git-Bukkit-1092acb
    ]
    at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInt
    eractManager.java:462) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :693) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:50) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:80) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [cra
    ftbukkit_server.jar:git-Bukkit-1092acb]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_25]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_25]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    43) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:2
    84) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:5
    98) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :506) [craftbukkit_server.jar:git-Bukkit-1092acb]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
    Caused by: java.lang.NullPointerException
    at me.anonymous350.hub.InfoManager.onPlayerInteract(InfoManager.java:183
    ) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:295) ~[craftbukkit_server.jar:git-Bukkit-1092acb]
    ... 16 more
     
    Last edited: Jan 26, 2015
  2. Offline

    mine-care

    Caused by: java.lang.NullPointerException
    Hmm...
    ItemMeta im = is.getItemMeta();
    You get the item meta of something being null first of all,
    and secondly try debiging :p
     
  3. Offline

    Lolmewn

    Oooh, InteractEvent :p Your title says InternetEvent, I wondered what that was lol.
     
  4. Offline

    Anonymous350

    @mine-care

    I already debugged it multiple times, otherwise I wouldn't have posted. It would be helpful you explained how to fix this. (Don't need to spoon-fed)
     
  5. Offline

    WinX64

    Check if your ItemStack is not null before getting its ItemMeta, or it will mostly likely throw an exception when you interact while holding nothing.
     
  6. Offline

    Anonymous350

    @WinX64

    I don't know if you meant something else but it already checks.

    Code:
    if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
            return;
     
  7. Offline

    WinX64

    Yep, that's exactly what i meant, you just got wrong order in here:
    [​IMG]
     
    Anonymous350 likes this.
  8. Offline

    Anonymous350

    @WinX64

    *facepalm*
    I didn't even notice that. Thank you so much.

    Fixed and working.

    Fixed Code (open)

    Code:
    @EventHandler
       public void onPlayerInteract(PlayerInteractEvent event) {
           Action a = event.getAction();
           ItemStack is = event.getItem();
                
        if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
            return;
     
        if(event.getPlayer().getWorld().getName().equals("Spawnworld")) {
            ItemMeta im = is.getItemMeta();
            if (is.getType() == Material.CHEST)
                if(im.hasDisplayName()) {
                    if(ChatColor.stripColor(im.getDisplayName()).equals("Info")) {
                        openGUI(event.getPlayer());
                    }
                }
              }
            }
         
        }
     
  9. Offline

    mine-care

    :p it is like what @WinX64 visually represented.
     
    WinX64 likes this.
Thread Status:
Not open for further replies.

Share This Page