Solved The Code works, but the console gives me an error

Discussion in 'Plugin Development' started by multikus, Mar 16, 2014.

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


    I am making a team plugin and made it so players will have wool on their heads. I made a code so they won't be able to take these wool blocks of the helmet slot:
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void disablephat(InventoryClickEvent event){
    4. if(event.getCurrentItem().getType() == Material.WOOL){
    5. event.setCancelled(true);
    6. }
    7. }

    So when I try to take the wool of the helmet slot, it won't let me (as it should), but the problem is that I always get an error message in the console everytime I click outside my inventory:

    [17:19:18 ERROR]: Could not pass event InventoryClickEvent to ZCapturePoint v1.0
    va:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(
    :1361) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInWindowClick.a(SourceFile:32)
            at net.minecraft.server.v1_7_R1.PacketPlayInWindowClick.handle(SourceFil
    e:10) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
            at me.multikus.ZCapturePoint.Teams.disablephat( ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
    va:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 13 more
    I've tried to change the code, but I get the same error over and over again.
    I hope someone could help me with this :)
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    getCurrentItem might be null (if the slot clicked is empty), meaning that the line calling a method on the current item could trigger a NPE (as it does in your code). Check for null first!
  3. Offline


    Fixed it now :D. Thanks for the help
Thread Status:
Not open for further replies.

Share This Page