Solved Could not pass event PlayerMoveEvent

Discussion in 'Plugin Development' started by KillerOfPie, May 1, 2014.

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

    KillerOfPie

    I get this error every time the player move/turns. I've been working on it for about a week and i've tried checking if all its variables are null before hand. I would appreciate some help asap!! Thanks!!

    code(the arrow is where the error is pointing to)
    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent event)
    3. {
    4. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("OmniHub");
    5. @SuppressWarnings("unchecked")
    6. List<String> worlds = (List<String>) plugin.getConfig().getList("Worlds");
    7.  
    8. Player p = event.getPlayer();
    9. if(p.getGameMode().equals(GameMode.CREATIVE))
    10. return;
    11. if(worlds.equals(null))
    12. return;
    13. if(p.getLocation().getWorld().getName() == null)
    14. return;
    15. -> if(!worlds.contains(p.getLocation().getWorld().getName()))
    16. return;
    17.  
    18. Location loc = p.getLocation();
    19.  
    20. if(!loc.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.NORTH).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.SOUTH).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.EAST).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.WEST).getType().equals(Material.AIR))
    21. p.setAllowFlight(true);
    22. }


    Stacktrace
    Code:
    [07:31:30] [Server thread/ERROR]: Could not pass event PlayerMoveEvent to OmniDoubleJump v1.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 net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:234) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInFlying.a(SourceFile:137) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInFlying.handle(SourceFile:8) [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.enjin.omniacrafters.DJListener.onMove(DJListener.java:69) ~[?:?]
        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
     
  2. Offline

    Onlineids

    What's line 69
     
  3. KillerOfPie Slight problem with this line:

    Code:
    if(worlds.equals(null))
    This line will always either do nothing, or throw a NullPointerException. If worlds happens to be null, then you can't use .equals() on it. If it's not null, then it doesn't execute. Change the line to use == instead of .equals()
     
  4. Offline

    garbagemule

    Just a quick note, "if(worlds.equals(null))" will never return true, and if worlds is indeed null, a NullPointerException will be thrown. You cannot call methods on a null reference. If you want to check if something is null, use the == operator, which, when used with two non-wrapper (i.e. not Integer, Boolean, Character, Double, etc. [note, capital first letter]) reference types compares the memory addresses of the references. This operator is also preferable (subjective) for enum types (such as Material and GameMode), because enum values are singletons (there is only one of each value).

    Anyway, it's probably that line that messes up. Another thing is that every time you choose to use the SuppressWarnings annotation (or blindly have your IDE spit it out for you), you should think to yourself "this is wrong", because it is in most cases. Never suppress warnings unless you know why the warning pops up, i.e. what you're doing to trigger it, and why it's okay to suppress it. If you can't answer those questions, you have no business using it. This is the method you want to be using.

    Edit: Ninja'd.
     
    AdamQpzm likes this.
  5. Offline

    KillerOfPie


    I added that after the errors were occurring to check for null before hand, the problem line is the one with the arrow next to it(15). Thanks for the info though i'll change it when i get home from school.

    I changed .equals to == and the errors do not appear anymore, however it seems that is because worlds is always null. I'm assuming this because it not allowing me to double jump.

    Please reply asap and thank you for correcting that..i completely derped when i was doing that part. If you need any other info to help me just ask and i will supply it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  6. Offline

    garbagemule

    If the worlds variable is always null, it means that no String list (assuming you changed your getList to getStringList as advised) with the name "Worlds" exists in the configuration, that's really all there is to it.
     
  7. Offline

    BillyGalbreath

    use .getStringList instead of .getList

    Edit: ninja'd for the first time ever :eek:
     
    garbagemule likes this.
  8. Offline

    KillerOfPie


    tried that, it worked, however did not fix the problem. i added some debug messages and its telling me "not in correct world".

    heres the new code for that section:
    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent event)
    3. {
    4. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("OmniHub");
    5.  
    6. List<String> worlds = plugin.getConfig().getStringList("Worlds");
    7.  
    8. Player p = event.getPlayer();
    9. if(p.getLocation().getWorld().getName() == null)
    10. {
    11. p.sendMessage("World = Null");
    12. return;
    13. }
    14. if(worlds == null)
    15. {
    16. p.sendMessage("Worlds = Null");
    17. return;
    18. }
    19. if(!worlds.contains(p.getLocation().getWorld().getName()))
    20. {
    21. p.sendMessage("Not in correct word");
    22. return;
    23. }
    24.  
    25. Location loc = p.getLocation();
    26.  
    27. if(!loc.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.NORTH).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.SOUTH).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.EAST).getType().equals(Material.AIR) || !loc.getBlock().getRelative(BlockFace.WEST).getType().equals(Material.AIR))
    28. p.setAllowFlight(true);
    29. }


    and heres the config:
    Code:
    Multiplier: 1.5
    Height: 1
    TakeFallDamage: false
    Worlds:
    - world
    
     
  9. Offline

    BillyGalbreath

    Add debug messages of player's world and the world retrieved from config to compare.
     
  10. Offline

    KillerOfPie

    new if statement
    Code:java
    1. if(!worlds.contains(p.getLocation().getWorld().getName()))
    2. {
    3. p.sendMessage("Not in correct word! player in world: "
    4. + p.getLocation().getWorld().getName()
    5. + " Worlds in config: "
    6. + worlds.toString());
    7. return;
    8. }

    what it says in chat:
    Code:
    Not in correct world! Player in world: world worlds in config: []
    -_- the error popped up again.
    i changed
    Code:java
    1. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("OmniHub");

    to
    Code:java
    1. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("OmniDJ");

    because i was using the wrong plugin name

    heres the error:
    Code:
    [16:22:36] [Server thread/ERROR]: Could not pass event PlayerMoveEvent to OmniDoubleJump v1.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 net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:234) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInFlying.a(SourceFile:137) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInLook.handle(SourceFile:98) [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.enjin.omniacrafters.DJListener.onMove(DJListener.java:68) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source) ~[?:?]
        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
    line 68 is
    Code:java
    1. List<String> worlds = plugin.getConfig().getStringList("Worlds");


    Someone please respond asap.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Offline

    garbagemule

    Are you doing /reload when you rebuild your plugin, by chance? Because /reload has a tendency of not working correctly sometimes when you just replace the jar files. That would explain your "worlds in config: []" print statement. Restarting (i.e. stop, replace jar, start) is the safest way to install a new version.

    Anyway, you get a NullPointerException, but you don't tell us which reference is null - why not? Print stuff! Figure out what's null instead of just throwing your arms up in the air. NullPointerExceptions are the easiest exceptions to debug, because Java stacktraces tell you EXACTLY what line to start dissecting.

    Oh, also. This:
    Completely unnecessary. There is nothing that "triggers" when you write that. People see it when they see it, and there's no way writing it is going to make people think "OH SHIT, I gotta reply RIGHT NOW!" - just relax and accept that forum communication is asynchronous :p
     
  12. Offline

    KillerOfPie


    Oh, sorry i thought i pointed out what is returning null. It seems to be the Worlds from the config, however it isn't null. and i have reload through console as well as stop, replace, start.

    and as for the please respond asap, it helps me think that someone will reply sooner =P its more for me then to get people to reply quickly. I've been trying to fix this for like a week and every bit of anxietic release is nice.
     
  13. Offline

    Superckl1

    What is your plugin's name in the plugin.yml? You are using OmniDJ to retrieve it, but from your stack trace it looks like the name is actually OmniDoubleJump;
     
    KillerOfPie likes this.
  14. Offline

    KillerOfPie


    Thank you for pointing that out, it should have been OmiDoubleJump. However its throwing an NPE at:
    Code:java
    1. List<String> worlds = plugin.getConfig().getStringList("Worlds");

    in multiple places now.

    Ignore my last post, i forgot to export it.. and THANK YOU!
    I must have derped when playing with it and put that in instead. that was the problem. Also thank you to every one else that was helping me, you found a few other things wrong with the code. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page