This project has been discontinued in favour of DietrichEvents2 which is faster and has more features.
A fast and feature rich but still easy to use Event library for Java
If you encounter any issues, please report them on the
issue tracker.
If you just want to talk or need help with DietrichEvents feel free to join my
Discord.
To use DietrichEvents with Gradle/Maven you can use Lenni0451's repository or Jitpack.
You can also find instructions how to implement it into your build script there.
If you just want the latest jar file you can download it from the GitHub Actions or use the Release.
You can use either DietrichEvents.createThreadSafe() or DietrichEvents.createDefault() to create an instance of the EventSystem, if you want to specify the mapping function yourself, there is also a normal DietrichEvents.create(). For a thread safe DietrichEvents there is already a global instance that you can call with DietrichEvents.global().
This function allows you to override the comparator used for sorting the priorities:
setPriorityOrder(Comparator<Subscription<?>> priorityOrder);
This function allows you to override the error handling:
setErrorHandler(Consumer errorHandler);
This function allows you to replace the sorting algorithm used for sorting the priorities:
setSortCallback(BiConsumer<List<Subscription>, Comparator>> sortCallback);
To get an DietrichEvents that uses FastUtil, you can do this:
DietrichEvents.create(new ConcurrentHashMap<>(), Object2ObjectArrayMap::new);
public interface ExampleListener extends Listener {
void onPreExample();
void onExample(final EventStateType eventStateType);
class ExampleEvent extends AbstractEvent<ExampleListener> {
private final EventStateType eventStateType;
public ExampleEvent(final EventStateType eventStateType) {
this.eventStateType = eventStateType;
}
@Override
public void call(final ExampleListener listener) {
listener.onExample(eventStateType);
if (eventStateType == EventStateType.PRE) {
listener.onPreExample();
}
}
@Override
public Class<ExampleListener> getListenerType() {
return ExampleListener.class;
}
}
}
public class ExampleListenerUsage implements ExampleListener {
// You can also use subscribeClass and subscribeClassInternal to subscribe all listeners from a specific class / object
public void registerListeners() {
DietrichEvents.global().subscribe(ExampleListener.class, this);
}
public void unregisterListeners() {
DietrichEvents.global().unsubscribe(ExampleListener.class, this);
}
@Override
public void onPreExample() {
}
@Override
public void onExample(EventStateType eventStateType) {
}
}
// You can use either the post or the postInternal function, where postInternal has no error handling.
DietrichEvents.global().post(new ExampleListener.ExampleEvent(EventStateType.PRE));
For a comparison you can look here