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 which 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 !"); }
I have implemented this system in Bukkit but I need your points of view to know if I should create a Pull Request.
Tell me what do you think.