Solved Could not pass PlayerInteractEvent

Discussion in 'Plugin Development' started by aman207, Jan 18, 2014.

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

    aman207

    My plugin was originally built on 1.6.4 I believe and when I migrated it over to 1.7.2, I had gotten no deprecated methods, however, I am getting a Could not pass PlayerInteractEvent error when punching a sign

    Full stacktrace
    Code:
    Could not pass event PlayerInteractEvent to DonatorExpress v1.6
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:165) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:978) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.a(SourceFile:43) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
    Caused by: java.lang.NullPointerException
        at net.targetcraft.donatorexpress.SignEvent.onPlayerInteract(SignEvent.java:215) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
        at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        ... 15 more
    
    The line of code that it doesn't like is this
    Code:java
    1. if(e.getClickedBlock().getType() == Material.SIGN_POST || e.getClickedBlock().getType() == Material.WALL_SIGN)


    If you want to view the full class file, you can go here
    https://github.com/aman207/DonatorE...net/targetcraft/donatorexpress/SignEvent.java

    So the code runs fine, it does what it is supposed to do, however it just gives an error which leads me to suspect that I am using an old method somewhere. I just don't know where that is.

    Any help is appreciated
    Thanks!
     
  2. Offline

    Gater12

    aman207 Check if the ClickedBlock is not null first.
     
  3. Offline

    aman207

    Gater12 Can't be null, e.getClickedBlock is grabbing the block from the event.

    Code:java
    1. public void onPlayerInteract(PlayerInteractEvent e)
     
  4. Offline

    aman207

    Bump
    This is still unresolved.
     
  5. Offline

    L33m4n123


    if you right click in the Air.. And then try to get the block you get null
     
  6. Offline

    aman207

    So how can it not be null? The code runs fine if I right click a sign, but as soon as I left click, it gives an error and still runs the code. This worked perfectly in 1.6.4.
     
  7. Offline

    Niknea

    aman207 as gater said check if the block is null.
     
  8. Offline

    aman207

  9. Offline

    Niknea

    aman207 mind just checking if it's null in the code and see if you still get the error?
     
  10. Offline

    aman207

    This is the code I am using to test what's being set to "e"
    And the image above was the result.
    I still do get an error.
    Code:java
    1. e.getPlayer().sendMessage(e.getClickedBlock().toString());
     
  11. Offline

    Niknea

    aman207 Do something like
    Code:java
    1. if(e.getClickedBlock == null) return;

    Not sure if that is right however its around there
     
  12. Offline

    aman207

    Alright so I did that and there was no error anymore. I tried commenting it out and there was an error. So I guess it was null?

    Now I am confused, it still ran the code even though the return; was supposed to take it out of the method.
    This is the only event in my plugin that runs this specific code so I know it can't be running anything else.
     
  13. Offline

    Niknea

    aman207 So that line of code fixed the error? If so then your set :)!
     
  14. Offline

    aman207

    Well yes I am set but I am left very confused. Do you know why that works and then runs the code anyways? Even though the "return" is supposed to kill the method?
     
  15. Offline

    Niknea

    aman207 It's suppose to kill the method if the block is null, if it insist then it would carry on ;).
     
  16. Offline

    aman207

    So why would that one little bitty line fix it then? If its not going to be null anyways.
    Bukkit is silly sometimes.
     
Thread Status:
Not open for further replies.

Share This Page