[SOLVED] My Plugin Spams Console Like Crazy! Please Help.

Discussion in 'Plugin Development' started by SnowGears, Aug 1, 2012.

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

    SnowGears

    My plugin keeps throwing errors like crazy and I have been looking into this trying to figure out what is causing them and why it will not work but I just can't get it to work. If someone would help me look through my class and find any errors that would be super helpful. I have been looking through this for hours and am starting to get very annoyed so you would help me with a big headache. Thanks in advance.

    This is my listener class.

    http://pastebin.com/M82Hn000

    This is the error message it keeps spamming.

    Code:
     
    16:14:20 [SEVERE] Could not pass event PlayerMoveEvent to ArmorAbilities
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:198)
    at net.minecraft.server.Packet10Flying.handle(SourceFile:126)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:246)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:102)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:82)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:559)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    at com.pluggertech.armorabilities.ArmorListener.onPlayerMove(ArmorListener.java:136)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)
    ... 11 more
    16:14:25 [SEVERE] Could not pass event InventoryCloseEvent to ArmorAbilities
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at net.minecraft.server.NetServerHandler.handleContainerClose(NetServerHandler.java:1039)
    at net.minecraft.server.Packet101CloseWindow.handle(SourceFile:16)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:246)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:102)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:82)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:559)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    at com.pluggertech.armorabilities.ArmorListener.eventInventoryClose(ArmorListener.java:115)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)
    ... 11 more
    16:14:27 [INFO] op lost connection: disconnect.quitting
    >
    
     
  2. Offline

    Slayer9x9

    If you read the error message, the problem is in your "onPlayerMove" event.
    Post line numbers so we can see exactly what line throws the Null Pointer exception.
     
  3. Offline

    SnowGears

    I know it is with onPlayerMove but I don't know what is causing it. It also throws exceptions for onInventoryClose. How do I post line numbers?
     
  4. Offline

    lazertester

    Your offending method call:

    Code:
    if(player.hasPermission("armorabilities.waterhaste") && getAbility(player).equalsIgnoreCase("SCUBA")){
    Which is trying a string comparison on the result of this:

    Code:
    public String getAbility(Player player)
    {
    if(powerMap.containsValue(player.getName()))
    return powerMap.get(player.getName());
    else
    return null; // Or whatever a string of whatever you want, like "none"
    }
    Which returns null if a player does not have the ability.

    I would recommend creating an AbilityManager with a hasAbility(Player, Ability) method where Ability is an enum constant instead of using a bunch of string comparisons. This would allow you to make your call something like

    Code:
    if(player.hasPermission("armorabilities.waterhaste") && hasAbility(player,Ability.SCUBA)){
     
  5. Offline

    Slayer9x9

    Eclipse should show you line numbers, just post the content of line "ArmorListener.java:136".
     
  6. Offline

    JjPwN1

    lazertester
    Post all of your code onto a new paste at Pastebin and it will automatically put line numbers. Give us the link once you've pasted it there.
     
  7. Offline

    SnowGears

    http://pastebin.com/M82Hn000

    EDIT: I also updated the error message up in the top

    How would I do that? Would I make an AbilityManager class with those methods in it? Would those comparisons be the reason my plugin is not working?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  8. Offline

    lazertester

    Your issue is that your comparison method is returning null if the player does not have the ability or is not in the map. When you get null back you are calling null.equalsIgnoreCase("SCUBA")

    If you don't want to make the ability manager and use a constant Enumeration to represent abilities then I recommend doing something like:

    Code:
    public String getAbility(Player player)
    {
    if(!powerMap.containsKey(player.getName()))
        powerMap.put(player.getName(),"NONE");
    return powerMap.get(player.getName());
    }
    To avoid getting null back from that method.

    NEVERMIND

    you are calling

    powerMap.containsValue(player.getName())

    instead of

    powerMap.containsKey(player.getName())

    I still recommend you change the structure of the method as I posted above to avoid returning null if you do not plan on checking for null every time you call the method. At least make it return an empty string if necessary.
     
    Tooner101 likes this.
  9. Offline

    SnowGears

Thread Status:
Not open for further replies.

Share This Page