Events registered but don't fire?

Discussion in 'Plugin Development' started by Axanite, Jun 26, 2014.

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

    Axanite

    Hi, I'm trying to make it so when I join my server it will give me items (right now: compass, etc) and when you right-click, say the compass, it will do something. I've grabbed code from an old plugin that works but it doesn't work when I put it into my new plugin. Any ideas why and if so, am I making a noob mistake??? :/

    CODE: http://pastebin.com/X1kaG4yU


    I SHOULD MENTION THAT THE EVENTS ARE IN THEIR OWN METHODS...

    Any help is greatly appreciated!
     
  2. Offline

    JoeyDevs

    Try:
    Code:java
    1. public void onEnable() {
    2. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    3. }


    If the codes are in the same class.
     
  3. Offline

    Axanite

    JoeyDevs Problem is, I did it the way I did because I don't like having @EventHandler's all around my main file without being organised. I like them in their own methods. :/
     
  4. Offline

    maved145

    Here use this.

    http://pastebin.com/8pm8fwMT

    rf2minecraft

    Alright so create a class called EventsListener and put all the Events in there, then add to your onEnable in your main class:
    Bukkit.getServer().getPluginManager().registerEvents(new EventsListener(), this);

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

    Axanite

    Gives me a syntax error where you put the "new" on this in the registering of the events...
     
  6. Offline

    JoeyDevs

    O i see you have added all classes to 1 file in pastebin.
    But i can't find it real quik because you code on a other way then me.
     
  7. Offline

    maved145

    rf2minecraft remove the new, forgot to remove it from your code.
     
  8. Offline

    JoeyDevs

    Why all in one class? You can do it in seperate classes. I do that 2 but never problems with registering events.
     
  9. Offline

    Axanite

    This is what I don't get, I do this way all the time but there is always this one thing that I've probably done wrong but Eclipse nor my server is picking it up....
     
  10. Offline

    maved145

    Yeah i know you can do that too, but i like all the Events in one class.
     
    Axanite likes this.
  11. Offline

    Axanite

    I put it in the seperate class like you said and it still doesn't work... =/
     
  12. Offline

    maved145

    rf2minecraft JoeyDevs
    Ill have my main class, MyPlayerListeners class and then MyOtherListeners class.
    That how i like it keeps it organised.

    rf2minecraft Ok one minute ill test it myself.

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

    Axanite

    This might help...
    Code:
    26.06 18:09:11 [Server] INFO ... 16 more
    26.06 18:09:11 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
    26.06 18:09:11 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
    26.06 18:09:11 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_51]
    26.06 18:09:11 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
    26.06 18:09:11 [Server] INFO at net.rf2minecraft.CJI.EventsListener.onPlayerInteract(EventsListener.java:57) ~[?:?]
    26.06 18:09:11 [Server] INFO Caused by: java.lang.NullPointerException
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:489) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:583) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:283) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:720) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:180) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.handle(SourceFile:9) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.PacketPlayInBlockPlace.a(SourceFile:60) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:618) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:203) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:233) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[spigot.jar:git-Spigot-1494]
    26.06 18:09:11 [Server] INFO org.bukkit.event.EventException
    26.06 18:09:11 [Server] ERROR Could not pass event PlayerInteractEvent to CustomJoinItems v1.0
     
  14. Offline

    JoeyDevs

    Here real quik what i have done in my plugin.

    Core: (Main Class, Path: Package.Core.java)
    Code:java
    1. //BlaBlaBla Imports etc
    2. import Package.Listeners.FListener;
    3. public void onEnable(){
    4. getServer().getConsoleSender().sendMessage(Prefix + ChatColor.GREEN + "Enabled");
    5.  
    6. getServer().getPluginManager().registerEvents(new FListener(null), this);
    7.  
    8. }

    FListener: (Food Listener, Path: Package.Listeners.FListener.java)
    Code:java
    1. public class FListener implements Listener {
    2. // Class Constructor ( From Main Class )
    3. Core plugin;
    4.  
    5. public String Prefix = ChatColor.DARK_GRAY + "[" + ChatColor.LIGHT_PURPLE + "MineLeague" + ChatColor.DARK_GRAY + "] ";
    6.  
    7. public FListener(Core Plugin) {
    8. this.plugin = Plugin;
    9. }
    10.  
    11. // ========================================================
    12.  
    13. @EventHandler(priority = EventPriority.HIGHEST)
    14. public void onFoodChange(FoodLevelChangeEvent e) {
    15. e.setCancelled(true);
    16. }
    17. }
     
  15. Offline

    Axanite

    Okay, I don't think there is anything on my server preventing it as my old plugin worked with the same plugins =/
     
  16. Offline

    maved145

    rf2minecraft
    Well that error looks like its something to do with the event, not the registering of it.
    when your registering the event in the main class, on new EventsListener() remove the () so it will be
    getServer().getPluginManager().registerEvents(new EventsListener, this);
     
  17. Offline

    Axanite

    "Syntax Error, insert '()' to complete ArgumentList"
     
  18. Offline

    maved145

    rf2minecraft

    Whoops. i forgot to add, add this to you EventsListener Class
    so beneath public class EventsListener implementsListener{
    add this.

    main pl;

    public EventsListener(main pl){

    this.pl = pl;
    }
     
  19. Offline

    Axanite

    I put that and now in my main class its saying "The constructor EventsListener() is undefinedCustomJoinItems.java"

    Anybody? Need this kind of urgently.

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

    dsouzamatt


    Did you try this? That code, otherwise, looked alright.
     
Thread Status:
Not open for further replies.

Share This Page