Register consumer as event listeners

XMLWordPrintable

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Minor
    • None
    • 1.16
    • Yes

      UPDATE: Sorry ! Wrong project ! I've created a new one in Spigot !

      Most of popular programming language have a event system.

      The main difference with Java was that until Java 8, an event system is based on classes : the developer has to register a Listener wich contains one or more methods called when an event is created. 

      With the introduction of Java 8's Functions (Consumers, Functions and Lambdas), it resolve this gap.

      Currently, @EventHandler in Listener classes marks methods to be called. By using Java 8's consumers, it resolves 

      I would introduce an new way to consume an event :

      pluginManager.registerEvent(PlayerJoinEvent.class, (event) -> {
          event.getPlayer().sendMessage("Hello !");
      }, priority plugin, ignoreCancelled);

      This feature should not replace the current system for compatibility reasons and for code organisation reasons.

      Another way to use this feature can be :

      pluginManager.registerEvent(PlayerJoinEvent.class, MyClass.PLAYER_JOIN_CONSUMER, priority, plugin, ignoreCancelled);

       

      public class MyClass {
          public static final Consumer<PlayerJoinEvent> PLAYER_JOIN_CONSUMER = (event) -> event.getPlayer().sendMessage("Hello !");
      }

      Tell me what do you think.

       

       

            Assignee:
            Unassigned
            Reporter:
            Vinetos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: