Last active
September 10, 2018 09:16
-
-
Save Exerosis/6246b917a31632ca40b0bccf049d049a to your computer and use it in GitHub Desktop.
A simpler faster system for registering bukkit event listeners. Scala Version: https://git.io/fAaV0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.Bukkit; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.EventPriority; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.HandlerList; | |
import org.bukkit.plugin.Plugin; | |
import org.bukkit.plugin.EventExecutor; | |
import java.util.function.Consumer; | |
public interface Events extends Listener, EventExecutor { | |
static <T extends Event> Events listen( | |
Plugin plugin, | |
Class<T> type, | |
Consumer<T> listener | |
) { return listen(plugin, type, EventPriority.NORMAL, listener); } | |
static <T extends Event> Events listen( | |
Plugin plugin, | |
Class<T> type, | |
EventPriority priority, | |
Consumer<T> listener | |
) { | |
final Events events = ($, event) -> listener.accept((T) event); | |
Bukkit.getPluginManager().registerEvent(type, events, priority, events, plugin); | |
return events; | |
} | |
default void unregister() { | |
HandlerList.unregisterAll(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment