Errors appear when getting the contents of an empty inventory slot?

Discussion in 'Plugin Development' started by Lemoncakecake, Aug 12, 2013.

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

    Lemoncakecake

    When I try to get the contents of an empty inventory slot:
    event.getPlayer().getInventory().getItem(x).getType() == Material.AIR;
    I receive a "Could not pass event" error, and the thread stops running.

    I'm using the beta 1.6.2-R0.1 bukkit build.

    Any ideas what's going wrong here?
     
  2. Offline

    1Rogue

    Mind posting the error?
     
  3. Offline

    Lemoncakecake

    This is the exact error

    20:04:23 [SEVERE] Could not pass event InventoryCloseEvent to HopperCraft v0.1
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
    at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.handleInventor
    yCloseEvent(CraftEventFactory.java:682)
    at net.minecraft.server.v1_6_R2.PlayerConnection.handleContainerClose(Pl
    ayerConnection.java:1158)
    at net.minecraft.server.v1_6_R2.Packet101CloseWindow.handle(SourceFile:1
    7)
    at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296
    )
    at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java
    :116)
    at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3
    0)
    at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    90)
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    26)
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.NullPointerException
    at me.lemoncakecake.hoppercraft.CraftingTable.onInventoryClose(CraftingT
    able.java:292)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425)
    ... 15 more
    >
     
  4. Offline

    Lemoncakecake

    With the first line being 292 (The line in question)

    Code:java
    1. if (inventory.getItem(1).getType() != Material.AIR) {
    2. craftingSlot1.put(workbench, inventory.getItem(1));
    3. Bukkit.getServer().getPlayer(event.getPlayer().getName()).sendMessage("Slot 1 is not empty"); //debug
    4. } else {
    5. Bukkit.getServer().getPlayer(event.getPlayer().getName()).sendMessage("Slot 1 is empty"); //debug
    6. }
     
  5. Lemoncakecake
    I think you are using the wrong event. When you close a crafting bench, it ejects all the items.
     
  6. Offline

    lazycat040

    Lemoncakecake

    Did you register the event?

    Did you put "Implements Listener" After the class?

    Is there and @EventHandler before the sub?
     
  7. Offline

    Lemoncakecake

    I seem to have found a solution by using:
    Code:java
    1. if (inventory.getItem(1) != null) {
    2. craftingSlot1.put(workbench, inventory.getItem(1));
    3. }


    I'm not sure why the other attempts didn't work, but for some reason this one did.

    Thanks for all of you who tried to help!
     
    lazycat040 likes this.
Thread Status:
Not open for further replies.

Share This Page