Skip to content

Instantly share code, notes, and snippets.

@Exerosis
Last active September 10, 2018 09:16
Show Gist options
  • Save Exerosis/6246b917a31632ca40b0bccf049d049a to your computer and use it in GitHub Desktop.
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
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