Custom Events (Two Issues, Both solved)

Discussion in 'Plugin Development' started by number1_Master, Aug 29, 2012.

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

    number1_Master

    Issue 1 - SOLVED (open)
    Solved. I just needed to change getHandlerList method to static inside my custom events.

    So, for my plugin TestqUiz I decided to create a custom event. After reading about custom events, and look at some sources, I realized that it shouldn't be too hard to create a custom event. So I create a bunch of custom events.
    Afterward, I created a listener and listend for each event. I registered the listeners in my onEnable, started the plugin, and ... well ... got an error.
    Error (open)
    Code:
    21:01:57 [SEVERE] Error occurred while enabling TestqUiz v2.4 (Is it up to date?)
    org.bukkit.plugin.IllegalPluginAccessException: java.lang.NullPointerException
        at org.bukkit.plugin.SimplePluginManager.getEventListeners(SimplePluginManager.java:550)
        at org.bukkit.plugin.SimplePluginManager.registerEvents(SimplePluginManager.java:508)
        at me.number1_Master.TestqUiz.TestqUiz.onEnable(TestqUiz.java:59)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:365)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:265)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:247)
        at net.minecraft.server.MinecraftServer.i(MinecraftServer.java:296)
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:275)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:225)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:140)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:378)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)

    Line 58 - 61 I get errors, which are where I register the listeners (with the custom events):
    Code (open)
    Code:java
    1. PreprocessListener ppListener = new PreprocessListener();
    2. IncorrectListener iListener = new IncorrectListener();
    3. CorrectListener cListener = new CorrectListener();
    4. FinishListener fListener = new FinishListener();
    5. // Now for registering the listeners
    6. getServer().getPluginManager().registerEvents(ppListener, this);
    7. getServer().getPluginManager().registerEvents(iListener, this);
    8. getServer().getPluginManager().registerEvents(cListener, this);
    9. getServer().getPluginManager().registerEvents(fListener, this);

    I call the event just like any other event: public class className implements Listener then the @EventHandler then public void onEvent(EventName e) and then code. Yet, it throws an error ...

    Can I please get information on why this null pointer is occurring? What typiclly causes the error?

    Thanks in advance!

    Issue 2 - SOLVED (open)
    Solved. I was just try to get an empty player :)

    So I finally fixed all startup issues for my plugin, and I went on to testing. I joined, and no errors occurred Nothing bad happened. Since that was done, I decided to start creating my test (since this is a testing plugin).

    Now, since I got everything done, it was time to actually test the test. I had three answers to choose from, incorrect, correct, and finish. Since correct is the simplest, I decided to go over that. Well:
    Error (open)
    Code:
    2012-08-30 10:48:16 [SEVERE] Could not pass event AnswerPreprocessEvent to TestqUiz
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:332)
    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 me.number1_Master.TestqUiz.Listeners.PlayerListener.onPlayerMove(PlayerListener.java:40)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    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:330)
    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:213)
    at net.minecraft.server.Packet10Flying.handle(SourceFile:136)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:276)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:581)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at me.number1_Master.TestqUiz.Listeners.PreprocessListener.onPreprocess(PreprocessListener.java:23)
    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:330)
    ... 22 more
    2012-08-30 10:48:16 [SEVERE] Could not pass event CorrectAnswerEvent to TestqUiz
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:332)
    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 me.number1_Master.TestqUiz.Listeners.PlayerListener.onPlayerMove(PlayerListener.java:53)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    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:330)
    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:213)
    at net.minecraft.server.Packet10Flying.handle(SourceFile:136)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:276)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:581)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at me.number1_Master.TestqUiz.Listeners.CorrectListener.onCorrect(CorrectListener.java:26)
    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:330)
    ... 22 more

    Now you may ask what lines 40 and 53 are. Well, those are the lines where I call my event.

    What did I do wrong when calling my event?
     
  2. Offline

    messageofdeath

    number1_Master
    Are you sure those listeners are listeners and not the actual custom event.
     
  3. Offline

    number1_Master

    yup. They implement Listener, and the event they call is my custom event.

    Thanks for the help! -_-

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

    MucTweezer

    Looking at line 550 of SimplePluginManager makes me think that the issue might be with the custom events you wrote (or at least, the custom event involved with the listener that is throwing errors when it is being registered).
     
  5. Offline

    number1_Master

    At first, I got a handler error which was because I didn't have the getHandlerList() method.
    Is it necessary to put @Override above these methods? I didn't see that on the wiki.
     
  6. Offline

    MucTweezer

    I'm guessing that it's probably just a small error with one of the events. I'm guessing this because it looks like the error is (if I understand) being thrown when you're registering the second listener (iListener), which means that ppListener (your first listener) and its custom are probably fine. So my thinking is that you have custom events that are fine, but one (at least) that has an error.
     
  7. Offline

    number1_Master

    It occurs on all of the listeners. The reason why it occurred on the second listener in this situation is because I made the first one a comment.
     
  8. Offline

    MucTweezer

    Well darn; there goes that theory. I want to be more help, but I'm stuck away from my dev environment so I can't test anything.
     
  9. Offline

    number1_Master

    I forgot to put a link to the source. Maybe you can look into it.
     
  10. Offline

    MucTweezer

    I think I'm mostly grasping at straws here, but the only thing that I noticed was that getHandlerList() is not static. I've noticed that it is in the wiki and in bukkit events. Will that fix the issue? (Grasping at straws...)
     
  11. Offline

    number1_Master

    You could be right! Testing it right now.

    You were right. Now I have a Vault error but I think I can fix it.

    Thanks!

    MucTweezer . Since you seem to know more about Events then I do, can you please help me with my second issue? Read the first post (I edited it).

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

    Giant

    Code:
    Caused by: java.lang.NullPointerException
    at me.number1_Master.TestqUiz.Listeners.PreprocessListener.onPreprocess(PreprocessListener.java:23
    
    Player seems to be null...
     
  13. Offline

    number1_Master

    I missed that null pointer. I was only looking at the top of the error :p
    hmm Then what is wrong here? Am I assigning player incorrectly?

    Edit: Ya, I am assigning player incorrectly...
     
  14. Offline

    MucTweezer

    Haha, I'm not sure I'm all that knowledgeable about events, but hey, I try.

    Based on Giant's comment, I compared your events again to bukkit events. I noticed that in BlockBreakEvent, player is declared final. Again, more grasping at straws, but I'm left with little else in the absence in my dev environment. However, maybe that will help?
     
  15. Offline

    number1_Master

    You have lucky straws. Ima test it.

    MucTweezer Giant
    I set the player to final and flipped player = this.player to this.player = player. Well, I got this error:
    Show Spoiler
    Code:
    11:36:40 [SEVERE] Could not pass event PlayerMoveEvent to TestqUiz
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:332)
    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:213)
    at net.minecraft.server.Packet10Flying.handle(SourceFile:136)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:276)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:581)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at me.number1_Master.TestqUiz.Listeners.PlayerListener.onPlayerMove(PlayerListener.java:69)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    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:330)
    ... 14 more
    

    Line 69 ( ;) ) is where I remove the player if he is cheating, but apparently there might be something wrong with the System.currentTimeMillis? Dunno. Looks like my preprocess is messed up (in a way). The good thing though is that the answers somewhat work. :D

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

    MucTweezer

    I'm thinking it has to do with TestqUiz.p.cheaters.get(player) instead of TestqUiz.p.cheaters.get(playerName).
     
    number1_Master likes this.
  17. Offline

    Giant

    I agree with MucTweezer you are kind of getting a "null" object now, which you then compare to System.currentTimeMillis....
     
  18. Offline

    number1_Master

    Yup you people are right. I should be getting a string, not a player.

    Thanks Giant and MucTweezer. You guys helped me a lot!

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

    Giant

    Glad to have been of service! :)
     
    number1_Master likes this.
Thread Status:
Not open for further replies.

Share This Page