Skip to content

jiyun233/NyaEvent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NyaEvent

A simple and easy-to-use open source event bus

Example

public class TestClass implements EventListenerOwner {

    private final NyaEventBus EVENT_BUS = new NyaEventBus();

    public static void main(String[] args) {
        new TestClass().init();
    }

    public void init() {
        EVENT_BUS.registerListener(this);
        EVENT_BUS.postEvent(new ExampleEvent(0));
    }

    @EventHandler(priority = ListenerPriority.HIGHEST,ignoreCancel = false)
    public void onEvent(ExampleEvent event) {
        System.out.println(event);
    }

}

class ExampleEvent extends Event implements Cancellable {

    public ExampleEvent(int stage) {
        super("Example",stage);
    }

    boolean cancel = false;

    @Override
    public boolean isCanceled() {
        return cancel;
    }

    @Override
    public void cancel() {
        cancel = true;
    }
}