mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-02 16:05:29 +00:00
functional event API
This commit is contained in:
parent
af1520eb83
commit
67c45b7be3
@ -0,0 +1,7 @@
|
||||
package com.dfsek.terra.api.event;
|
||||
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
|
||||
public interface EventHandler {
|
||||
void handle(Event event);
|
||||
}
|
@ -2,6 +2,8 @@ package com.dfsek.terra.api.event;
|
||||
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.event.functional.EventContext;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
/**
|
||||
* Manages event registration and triggering.
|
||||
@ -22,4 +24,10 @@ public interface EventManager {
|
||||
* @param listener Listener to register.
|
||||
*/
|
||||
void registerListener(TerraAddon addon, EventListener listener);
|
||||
|
||||
<T extends Event> EventContext<T> register(Class<T> clazz);
|
||||
|
||||
<T extends Event> EventContext<T> register(TypeKey<T> clazz);
|
||||
|
||||
void registerHandler(EventHandler handler);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.dfsek.terra.api.event.functional;
|
||||
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface EventContext<T extends Event> {
|
||||
EventContext<T> then(Consumer<T> action);
|
||||
|
||||
EventContext<T> priority(int priority);
|
||||
|
||||
EventContext<T> failThrough();
|
||||
|
||||
EventContext<T> global();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user