Solved Could not pass event InventoryClickEvent

Discussion in 'Plugin Development' started by galaipa, Jun 26, 2014.

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

    galaipa

    Hi, I have an error in my plugin and I don't know what am I doing wrong.
    The error:
    Code:
    [12:54:38] [Server thread/ERROR]: Could not pass event InventoryClickEvent to TheTowersS v1.0
    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 net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1361) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInWindowClick.a(SourceFile:32) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInWindowClick.handle(SourceFile:10) [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 io.github.galaipa.TheTowersS.Listener.onInventoryClick(Listener.java:44) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 13 more
    And my listener:
    Code:java
    1.  
    2. package io.github.galaipa.TheTowersS;
    3.  
    4. import java.util.logging.Logger;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.inventory.InventoryClickEvent;
    10. import org.bukkit.inventory.ItemStack;
    11.  
    12.  
    13. /**
    14. *
    15. * @author galaipa
    16. */
    17. public final class Listener implements org.bukkit.event.Listener {
    18. public static final Logger log = Logger.getLogger("Minecraft");
    19. @EventHandler
    20. public void onInventoryClick(InventoryClickEvent e) {
    21. Player player = (Player) e.getWhoClicked();
    22. if ( e.getSlot()== 39){
    23. e.setCancelled(true);
    24. player.sendMessage(ChatColor.RED +"1");
    25. }
    26.  
    27. else if (e.getCurrentItem().getType() == Material.LEATHER_HELMET || (e.getCurrentItem().getType() == Material.LEATHER_CHESTPLATE ) || (e.getCurrentItem().getType() == Material.LEATHER_BOOTS ) || (e.getCurrentItem().getType() == Material.LEATHER_LEGGINGS )){
    28. ItemStack a = e.getCurrentItem();
    29. player.getInventory().removeItem(a);
    30.  
    31.  
    32. }
    33.  
    34.  
    35.  
    36. }
    37.  
    38. }
    39.  
     
  2. Offline

    Seadragon91

    The clicked item can be null add a null check to fix that problem.
     
  3. Offline

    galaipa

    Seadragon91
    Thanks!
    I added this
    Code:java
    1. if (e.getCurrentItem() == null){
    2. }
     
Thread Status:
Not open for further replies.

Share This Page