Solved Item check in the InventoryCloseEvent

Discussion in 'Plugin Development' started by tacticalsk8er, Mar 15, 2014.

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

    tacticalsk8er

    Whenever the InventoryCloseEvent is called it keeps throwing this error:

    StackTrace (open)
    Code:
    [03:10:11] [Server thread/ERROR]: Could not pass event InventoryCloseEvent to KitPVP v0.5
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleInventoryCloseEvent(CraftEventFactory.java:701) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1154) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInCloseWindow.a(PacketPlayInCloseWindow.java:15) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInCloseWindow.handle(PacketPlayInCloseWindow.java:27) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
    at com.minevast.plugin.KitPVP.Events.onInvClose(Events.java:41) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_21]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_21]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    ... 14 more


    Here is the code that corresponds with the error:

    Code (open)
    Code:java
    1. @EventHandler
    2. public void onInvClose(final InventoryCloseEvent e){
    3. Inventory inv = e.getInventory();
    4. final Inventory pinv = e.getPlayer().getInventory();
    5. if(inv.getName().equalsIgnoreCase("Head Hunter")){
    6. for(ItemStack item: inv.getContents()){
    7. /*Error at this line*/ if(item.getType().equals(Material.SKULL_ITEM)){
    8. //TODO Player add money
    9. } else {
    10. pinv.addItem(item);
    11. plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
    12. @Override
    13. public void run() {
    14. pinv.setContents(pinv.getContents());
    15. }
    16. }, 20l);
    17. }
    18. }
    19. }
    20. }
     
  2. Offline

    Dudemister1999

    I need to see line 41, or I cannot tell you what is wrong with it.
     
  3. Offline

    tacticalsk8er

    I commented at which line the error is at

    Code:java
    1.  
    2. @EventHandler
    3. public void onInvClose(final InventoryCloseEvent e){
    4. Inventory inv = e.getInventory();
    5. final Inventory pinv = e.getPlayer().getInventory();
    6. if(inv.getName().equalsIgnoreCase("Head Hunter")){
    7. for(ItemStack item: inv.getContents()){
    8. /* This is where the error is at ---------->>>>*/if(item.getType().equals(Material.SKULL_ITEM)){
    9. //TODO Player add money
    10. } else {
    11. pinv.addItem(item);
    12. plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
    13. @Override
    14. public void run() {
    15. pinv.setContents(pinv.getContents());
    16. }
    17. }, 20l);
    18. }
    19. }
    20. }
    21. }
    22.  
     
  4. Offline

    jeussa

    Try add a return; statement between line 9 and 10. Right now if the item indeed is made out of Material.SKULL_ITEM, there is nothing for the plugin to perform.

    Also note that in line 15, you are setting the contents of an inventory to it's own contents, which basicly does nothing.
     
  5. Offline

    Dudemister1999

    tacticalsk8er Thanks! Now, here's what I'd do in order to fix it.

    Code:java
    1. if(item != null && item.getType().equals(Material.SKULL_ITEM))
     
  6. Offline

    tacticalsk8er

    Dudemister1999
    Thanks that worked

    jeussa
    I was trying to see if I could make it so when a player gets there inventory added with items, that it wouldn't have items that are invisible. Unfortunately this doesn't work, do you happen to know of anything that would work?
     
Thread Status:
Not open for further replies.

Share This Page