- Type Parameters:
T
- The event type accepted by this node
- All Known Implementing Classes:
GlobalEventHandler
A node may contain any number of children and/or listeners. When an event is called, the node will filter it based on the parameters given at creation and then propagate it down to child nodes and listeners if it passes.
-
Method Summary
Modifier and TypeMethodDescriptionDirectly adds a child node to this node.addListener
(Class<E> eventType, Consumer<E> listener) addListener
(EventListener<? extends T> listener) Creates an event node which accepts any event type with no filtering.default void
Calls an event starting from this node.default void
callCancellable
(T event, Runnable successCallback) Execute a cancellable event with a callback to execute if the event is successful.event
(String name, EventFilter<E, V> filter, Predicate<E> predicate) Creates an event node which accepts any event of the given type which passes the provided condition.findChildren
(String name) Locates all child nodes with the given name and event type recursively starting at this node.findChildren
(String name, Class<E> eventType) Locates all child nodes with the given name and event type recursively starting at this node.Returns an unmodifiable view of the children in this node.<E extends T>
ListenerHandle<E> Gets the handle of an event type.getName()
int
default boolean
hasListener
(Class<? extends T> type) map
(H value, EventFilter<E, H> filter) Maps a specific object to a node.void
register
(EventBinding<? extends T> binding) removeChild
(EventNode<? extends T> child) Directly removes the given child from this node.default void
removeChildren
(String name) Recursively removes children with the given name starting at this node.void
removeChildren
(String name, Class<? extends T> eventType) Recursively removes children with the given name and type starting at this node.removeListener
(EventListener<? extends T> listener) <E extends T>
voidreplaceChildren
(String name, Class<E> eventType, EventNode<E> eventNode) Replaces all children matching the given name and type recursively starting from this node.default void
replaceChildren
(String name, EventNode<T> eventNode) Replaces all children matching the given name and type recursively starting from this node.setPriority
(int priority) tag
(String name, EventFilter<E, ? extends TagReadable> filter, Tag<?> tag) Creates an event node which accepts any event of the given type which has a handler who has the given tag.tag
(String name, EventFilter<E, ? extends TagReadable> filter, Tag<V> tag, Predicate<@Nullable V> consumer) Creates an event node which accepts any event of the given type which has a handler who has an applicable tag.type
(String name, EventFilter<E, V> filter) Creates an event node which accepts any event of the given type.type
(String name, EventFilter<E, V> filter, BiPredicate<E, V> predicate) Creates an event node which accepts any event of the given type which passes the provided condition.void
Prevents the node frommap(Object, EventFilter)
to be called.void
unregister
(EventBinding<? extends T> binding) value
(String name, EventFilter<E, V> filter, Predicate<V> predicate) Creates an event node which accepts any event of the given type which passes the provided condition.
-
Method Details
-
all
Creates an event node which accepts any event type with no filtering.- Parameters:
name
- The name of the node- Returns:
- An event node with no filtering
-
type
@Contract(value="_, _ -> new", pure=true) static <E extends Event,V> EventNode<E> type(String name, EventFilter<E, V> filter) Creates an event node which accepts any event of the given type. The type is provided by theEventFilter
.For example, you could create an event filter which only accepts player events with the following
var playerEventNode = EventNode.type("demo", EventFilter.PLAYER);
- Type Parameters:
E
- The resulting event type of the node- Parameters:
name
- The name of the event nodefilter
- The event type filter to apply- Returns:
- A node with just an event type filter
-
event
@Contract(value="_, _, _ -> new", pure=true) static <E extends Event,V> EventNode<E> event(String name, EventFilter<E, V> filter, Predicate<E> predicate) Creates an event node which accepts any event of the given type which passes the provided condition. The condition is based on the event object itself.For example, you could create an event filter which only accepts player events where the player is in the pos x/z quadrant of the world.
var playerInPosXZNode = EventNode.event("abc", EventFilter.PLAYER, event -> { var position = event.getPlayer().getPosition(); return position.getX() > 0 && position.getZ() > 0; });
- Type Parameters:
E
- The resulting event type of the node- Parameters:
name
- The name of the event nodefilter
- The event type filter to applypredicate
- The event condition- Returns:
- A node with an event type filter as well as a condition on the event.
-
type
@Contract(value="_, _, _ -> new", pure=true) static <E extends Event,V> EventNode<E> type(String name, EventFilter<E, V> filter, BiPredicate<E, V> predicate) Creates an event node which accepts any event of the given type which passes the provided condition. The condition is based on the event object as well as the event handler type defined in theEventFilter
.For example, you could create an event filter which only accepts player events where the player is in the pos x/z quadrant of the world.
var playerInPosXZNode = EventNode.type("abc", EventFilter.PLAYER, (event, player) -> { var position = player.getPosition(); return position.getX() > 0 && position.getZ() > 0; });
- Type Parameters:
E
- The resulting event type of the nodeV
- The handler type of the event filter- Parameters:
name
- The name of the event nodefilter
- The event type filter to applypredicate
- The event condition- Returns:
- A node with an event type filter as well as a condition on the event.
-
value
@Contract(value="_, _, _ -> new", pure=true) static <E extends Event,V> EventNode<E> value(String name, EventFilter<E, V> filter, Predicate<V> predicate) Creates an event node which accepts any event of the given type which passes the provided condition. The condition is based on the event handler defined by theEventFilter
.For example, you could create an event filter which only accepts player events where the player is in creative mode.
var playerIsCreative = EventNode.value("abc", EventFilter.PLAYER, Player::isCreative);
- Type Parameters:
E
- The resulting event type of the nodeV
- The handler type of the event filter- Parameters:
name
- The name of the event nodefilter
- The event type filter to applypredicate
- The event condition- Returns:
- A node with an event type filter as well as a condition on the event.
-
tag
@Contract(value="_, _, _ -> new", pure=true) static <E extends Event> EventNode<E> tag(String name, EventFilter<E, ? extends TagReadable> filter, Tag<?> tag) Creates an event node which accepts any event of the given type which has a handler who has the given tag.The
EventFilter
's resulting event type must beTagReadable
.- Type Parameters:
E
- The resulting event type of the node- Parameters:
name
- The name of the event nodefilter
- The event type filter to applytag
- The tag which must be contained on the event handler- Returns:
- A node with an event type filter as well as a handler with the provided tag
-
tag
@Contract(value="_, _, _, _ -> new", pure=true) static <E extends Event,V> EventNode<E> tag(String name, EventFilter<E, ? extends TagReadable> filter, Tag<V> tag, Predicate<@Nullable V> consumer) Creates an event node which accepts any event of the given type which has a handler who has an applicable tag. An applicable tag means that it passes the given condition.- Type Parameters:
E
- The resulting event type of the node- Parameters:
name
- The name of the event nodefilter
- The event type filter to applytag
- The tag which must be contained on the event handlerconsumer
- The condition to test against the tag, if it exists.- Returns:
- A node with an event type filter as well as a handler with the provided tag
-
call
Calls an event starting from this node.- Parameters:
event
- the event to call
-
hasListener
-
getHandle
Gets the handle of an event type.- Type Parameters:
E
- the event type- Parameters:
handleType
- the handle type- Returns:
- the handle linked to
handleType
-
callCancellable
Execute a cancellable event with a callback to execute if the event is successful. Event conditions and propagation is the same ascall(Event)
.- Parameters:
event
- The event to executesuccessCallback
- A callback if the event is not cancelled
-
getEventType
-
getName
-
getPriority
@Contract(pure=true) int getPriority() -
setPriority
-
getParent
-
getChildren
Returns an unmodifiable view of the children in this node.- See Also:
-
findChildren
Locates all child nodes with the given name and event type recursively starting at this node.- Parameters:
name
- The event node name to filter foreventType
- The event node type to filter for- Returns:
- All matching event nodes
-
findChildren
Locates all child nodes with the given name and event type recursively starting at this node.- Parameters:
name
- The event name to filter for- Returns:
- All matching event nodes
-
replaceChildren
Replaces all children matching the given name and type recursively starting from this node.Node: The callee may not be replaced by this call.
- Parameters:
name
- The event name to filter foreventType
- The event node type to filter foreventNode
- The replacement node
-
replaceChildren
Replaces all children matching the given name and type recursively starting from this node.Node: The callee may not be replaced by this call.
- Parameters:
name
- The node name to filter foreventNode
- The replacement node
-
removeChildren
Recursively removes children with the given name and type starting at this node.- Parameters:
name
- The node name to filter foreventType
- The node type to filter for
-
removeChildren
Recursively removes children with the given name starting at this node.- Parameters:
name
- The node name to filter for
-
addChild
Directly adds a child node to this node.- Parameters:
child
- The child to add- Returns:
- this, can be used for chaining
-
removeChild
Directly removes the given child from this node.- Parameters:
child
- The child to remove- Returns:
- this, can be used for chaining
-
addListener
-
addListener
-
removeListener
-
map
Maps a specific object to a node.Be aware that such structure have huge performance penalty as they will always require a map lookup. Use only at last resort.
- Parameters:
value
- the mapped valuefilter
- the filter to use- Returns:
- the node (which may have already been registered) directly linked to
value
-
unmap
Prevents the node frommap(Object, EventFilter)
to be called.- Parameters:
value
- the value to unmap
-
register
-
unregister
-