Skip to content

PenguThePenguin/Event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event

Event is a publishing / subscribing event api based off the publish-subscribe pattern.

Why event?

Event is fully optimized for any implementation, with support for events to be fired on different threads.

Examples

Setting up a bus

EventBus<ExampleEvent> bus = EventBus.of(ExampleEvent.class);

Create an event

This is a base event you can extend for different actions

You can also intercept event posting by implementing Cancellable or using a custom bus Acceptor
public static class ExampleEvent {
    
}

Register a handler

// Using java 8's lambdas
bus.register(ExampleEvent.class, (EventHandler<ExampleEvent>) event -> {
    System.out.println("Hey!");
});

// Using regular java
bus.register(ExampleEvent.class, new EventHandler<ExampleEvent>() {
    @Override
    public void handle(ExampleEvent event) throws Throwable {
        System.out.println("Hey!");
    }
});

Create a subscriber

You can also make a subscriber from a class with methods annotated with @Subscribe

bus.register(new ExampleSubscriber());

public static class ExampleSubscriber {

	@Subscribe(order = 1)
	private void onExampleEvent(ExampleEvent event) {
		System.out.println("Hey!");
	}
}

About

A event bus API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages