public class SimpleEventBus implements EventBus { private final JavaPlugin plugin; private final Map, AttachableConsumer> subscriptions = new ConcurrentHashMap<>(); public SimpleEventBus(JavaPlugin plugin) { this.plugin = plugin; } @Override public void subscribe(Class eventClass, Consumer action) { AttachableConsumer existing = (AttachableConsumer) subscriptions.get(eventClass); if(existing == null) { existing = new AttachableConsumer<>(); subscriptions.put(eventClass, existing); AttachableConsumer finalExisting = existing; Bukkit.getPluginManager().registerEvent(eventClass, this, EventPriority.NORMAL, (listener, event) -> { if (eventClass.isInstance(event)) { finalExisting.accept(eventClass.cast(event)); } }, plugin); } existing.attach(action); } @Override public void dispose() { HandlerList.unregisterAll(this); } }