Solved registerEvents(this, this) HELP ME

Discussion in 'Plugin Development' started by Indevios, Oct 6, 2014.

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

    Indevios

    Hi everyone! I've been learning coding lately from PogoStick29Dev (youtube.com/pogostick29dev) and I was confused in a certain part while registering the events.

    Heres my question. In the following method/line, what do the two 'this' mean?
    getServer().getPluginManager().registerEvents(this, this);

    Example: getServer().getPluginManager().registerEvents(this, this); is written in the main class however, my class with all my events that need to be listened are in a seperate class. How would I make that work?

    Also, I have seen one of the 'this' saying plugin rather than 'this'. What does that mean?

    Please just explain getServer().getPluginManager().registerEvents(this, this); as good as you can and aswell as what the 'this' fields are used for. Please do not link me to another thread or help topic as I've read em all.

    Thanks fellow developers!
    - Indevios
     
  2. Offline

    Gater12

    Indevios
    this keyword explanation: http://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html Basically it means the current object.

    registerEvents(Listener l, Plugin p) takes in 2 parameters the first one being a Listener instance, and the second a Plugin instance. Your main class is an instance of JavaPlugin which is an instance of Plugin somewhere down the line.
     
    acer5999 and es359 like this.
  3. Offline

    Indevios

    Gater12 So basically, the first 'this' is referring to the location of the listeners for the events and the second 'this' just refers to the plugin? So basically if I just put the second 'this' as plugin all the time it shouldn't change anything? What if my listener is located within another plugin. Such as if I hooked into the worldedit api thingy? Would the second 'this' still be the same?

    Thanks btw :)

    Also, what do you mean by object?

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

    fireblast709

    Indevios a Listener is a class which covering l contains several event handlers. The first parameter is an instance of that class. Listeners are always located on your own plugin, since they should be registered as yours.
     
  5. Offline

    Indevios

    Thank you for clearing this up fireblast709 . I now understand, the first 'this' classifies the instance of the class that has listener meanwhile the second 'this' I'll just put plugin as it will always be my code in my plugin.
     
Thread Status:
Not open for further replies.

Share This Page