Resource Simple Listener API

Discussion in 'Spigot Plugin Development' started by NyxCode, Apr 21, 2017.

  1. Hey Spigot-community!
    Currently I had to write a lot of code like this:
    Code (Text):
    plugin.getServer().getPluginManager().registerEvents(new org.bukkit.event.Listener() {
                    @EventHandler
                    public void onSomething(MyEvent e) {
                        if(someCondition) e.setCancelled(true);
                    }
    }, plugin);
    And I got really pissed about it. So I created a small API for simplifying listener like this.
    Code (Text):
    eventApi.cancelIf(MyEvent.class, e -> myCondition);
    If you don't want to cancel the event but just listen for it, you can use this method:
    Code (Text):
    eventApi.listen(MyEvent.class, e -> doSomething());
    If you want to use this library, download/clone and compile it from https://github.com/NyxMC/SimpleEventAPI or just copy the classes in your project.
     
    • Funny Funny x 1
  2. If you're using lambdas to do event listening you're generally doing something wrong, but I could definitely see this being useful for smaller projects. Nice resource.
     
  3. Why? Imagine an gamemode where players may not break blocks until the game has started.
    Code (Text):
    eventApi.cancelIf(BlockBreakEvent.class, e -> !hasStarted())
     
  4. Is cancelIf the only method? Where can the documentation be found? And personally, i think an API like this is kinda silly and unnceccecary.
     
    • Agree Agree x 1
  5. The code contains javadocs. There are methods for canceling and listening for events. If you have no need for such an API, don't use it.