Can't register events?

Discussion in 'Plugin Development' started by NeonLightMC, Dec 13, 2016.

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

    NeonLightMC

    Hello,

    I just started working on a plugin but i dont know how to register my events.
    Could anyone explain me how?

    c8d66c55175d4352bb2f10084a5760c9.png

    Pce.

    What am i doing wrong?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    NeonLightMC

  4. Offline

    Lordloss

    It takes the name of your Listener class as argument, not the Listener names.
     
  5. Offline

    Zombie_Striker

    @NeonLightMC
    In other words, the first parameter is the class instance that has the events. The second one is the main class. Since your main class is the one with all the events, put "this" as the argument.
     
  6. Offline

    MaxFireIce

    There are only two arguments. The first is the listener class name with parentheses. The second is in your main class, aka "this". Also, try defining plugin manager as an object, see if it helps.
     
  7. try this
    Code:
    Bukkit.getPluginManager().registerEvents(this, this);
     
  8. @NeonLightMC

    #registerEvents() takes only two arguments. The first is an instance of the class that contains the event handlers, and the second is the instance of your plugin.

    If the code is in your Core class (which also happens to be the 'instance of the plugin'), you can register it as a Listener by using the keyword 'this', which returns the instance of the class the code is running in. So, it will return the instance of Core:

    #registerEvents(this, this);

    This will register the Core class as a Listener (the first parameter), and gives a reference to the Core class (your main class, the 'plugin').

    From there, you can just add event listeners by using @EventHandler annotations followed by a method with a parameter of an instance of the event you want to handle, for example PlayerJoinEvent:

    Code:
    @EventHandler
    public void onEvent(PlayerJoinEvent event) {
           //Do stuff here.
    }
    
    Then write the code for what you want to happen. Hope this helped!
     
Thread Status:
Not open for further replies.

Share This Page