Solved Interface of listeners?

Discussion in 'Plugin Development' started by r0llingthund3r, Jul 18, 2014.

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

    r0llingthund3r

    In a plugin I'm making, I want to implement passive abilities for some players. These could range from fall damage immunity to extra damage towards certain other people. The cleanest way I can think to implement this is to make an interface that has all of the listeners necessary for my list of passive abilities. Then I could just make an abstract class that implements IPassive (for example) and only use the listeners I needed right? And they would already be registered from the IPassive class? I haven't really dealt with interfaces at all and am unfamiliar with how listeners behave in a scenario like this so sorry for my probably vague question...
     
  2. Offline

    aninsanellama

    I apologise if what I write is not what you want to do at all, but here it is:

    As you've most likely seen in interfaces, methods are empty (bodies are not allowed) and you cannot create constructors. For these methods (which classes will later implement) annotations are allowed, so you could have 'event methods':

    Code:java
    1. public interface IPassive {
    2.  
    3. @EventHandler
    4. public void onDeath(PlayerDeathEvent e);
    5.  
    6. @EventHandler
    7. public void onJoin(PlayerJoinEvent e);
    8.  
    9. @EventHandler
    10. public void onQuit(PlayerQuitEvent e);
    11. }
    12.  


    You can also make interfaces extend other interfaces, so you could extend the Listener interface.
    Other classes when implementing this interface could just contain the line to register the events within the constructor, which can be called on the onEnable.

    Code:java
    1. public interface IPassive extends Listener {}


    The interface would also force you to implement every event (or method) that is in the interface, you could not just pick certain methods.
     
  3. Offline

    r0llingthund3r

    aninsanellama Then this method would not suffice for my ideas. I want to be able to have one class to contain all of the listeners I need for my passives to work, register them all from there, and simply pass instances of those listeners to other classes as necessary. Any suggestions are welcome.
     
  4. Offline

    Zupsub

    I don't understand you, if you register a Listener, you can already use all events.
     
Thread Status:
Not open for further replies.

Share This Page