PlayerInteractEvent - getClickedBlock().getType() - NullPointerException

Discussion in 'Bukkit Help' started by MetalGearDaner, Nov 4, 2014.

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

    MetalGearDaner

    My problem is that when I click the air, it produces a NullPointerException. This is the piece of my plugin that contains the problem:

    Code:java
    1. @EventHandler
    2. public void onWaterFillTry(PlayerInteractEvent event) {
    3. Player p = event.getPlayer();
    4. ItemMeta meta = p.getItemInHand().getItemMeta();
    5. Material m = event.getClickedBlock().getType();
    6. if (m.equals(Material.GLASS)) {
    7. event.getPlayer().sendMessage("No puedes recoger agua con una botella de almacenamiento de experiencia.");
    8. event.setCancelled(true);
    9. }else{
    10. p.sendMessage("Nada");
    11. }
    12. }


    Code:
    [16:32:48 ERROR]: Could not pass event PlayerInteractEvent to CatExp v1.1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:225) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-
    g07d4558-b3116jnks]
            at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:195) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-
    g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :993) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.PacketPlayInArmAnimation.a(SourceFile:43
    ) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.PacketPlayInArmAnimation.handle(SourceFi
    le:9) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157
    ) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:6
    67) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    58) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    58) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.NullPointerException
            at com.github.mcat95.CatExp.CatExp.onWaterFillTry(CatExp.java:138) ~[?:?
    ]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _67]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _67]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_67]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_67]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            ... 15 more
     
  2. Offline

    AdamQpzm

    MetalGearDaner 1) This should be in the Plugin Development section, not Bukkit Help
    2) Put in a null check (hint: in this context, air is not a block)
     
  3. Offline

    tjehu

    I believe you are trying to get the type of a block that does not exist(Air), and that means it's accessing invalid information. That is what's throwing the errors, I'm pretty sure.
     
Thread Status:
Not open for further replies.

Share This Page