Interface EventNode<T extends Event>
- 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
(@NotNull Class<E> eventType, @NotNull Consumer<@NotNull E> listener) addListener
(@NotNull 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, @NotNull Runnable successCallback) Execute a cancellable event with a callback to execute if the event is successful.event
(@NotNull String name, @NotNull EventFilter<E, V> filter, @NotNull Predicate<E> predicate) Creates an event node which accepts any event of the given type which passes the provided condition.findChildren
(@NotNull String name) Locates all child nodes with the given name and event type recursively starting at this node.findChildren
(@NotNull 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>
@NotNull ListenerHandle<E> Gets the handle of an event type.@NotNull String
getName()
int
default boolean
hasListener
(@NotNull Class<? extends T> type) map
(H value, @NotNull EventFilter<E, H> filter) Maps a specific object to a node.void
register
(@NotNull EventBinding<? extends T> binding) removeChild
(@NotNull EventNode<? extends T> child) Directly removes the given child from this node.default void
removeChildren
(@NotNull String name) Recursively removes children with the given name starting at this node.void
removeChildren
(@NotNull String name, @NotNull Class<? extends T> eventType) Recursively removes children with the given name and type starting at this node.removeListener
(@NotNull EventListener<? extends T> listener) <E extends T>
voidreplaceChildren
(@NotNull String name, @NotNull Class<E> eventType, @NotNull EventNode<E> eventNode) Replaces all children matching the given name and type recursively starting from this node.default void
replaceChildren
(@NotNull String name, @NotNull EventNode<T> eventNode) Replaces all children matching the given name and type recursively starting from this node.setPriority
(int priority) tag
(@NotNull String name, @NotNull EventFilter<E, ? extends TagReadable> filter, @NotNull Tag<?> tag) Creates an event node which accepts any event of the given type which has a handler who has the given tag.tag
(@NotNull String name, @NotNull EventFilter<E, ? extends TagReadable> filter, @NotNull Tag<V> tag, @NotNull 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
(@NotNull String name, @NotNull EventFilter<E, V> filter) Creates an event node which accepts any event of the given type.type
(@NotNull String name, @NotNull EventFilter<E, V> filter, @NotNull 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
(@NotNull EventBinding<? extends T> binding) value
(@NotNull String name, @NotNull EventFilter<E, V> filter, @NotNull Predicate<V> predicate) Creates an event node which accepts any event of the given type which passes the provided condition.
-
Method Details
-
all
@Contract(value="_ -> new", pure=true) @NotNull static @NotNull EventNode<Event> all(@NotNull @NotNull String name) 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) @NotNull static <E extends Event,V> @NotNull EventNode<E> type(@NotNull @NotNull String name, @NotNull @NotNull 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) @NotNull static <E extends Event,V> @NotNull EventNode<E> event(@NotNull @NotNull String name, @NotNull @NotNull EventFilter<E, V> filter, @NotNull @NotNull 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) @NotNull static <E extends Event,V> @NotNull EventNode<E> type(@NotNull @NotNull String name, @NotNull @NotNull EventFilter<E, V> filter, @NotNull @NotNull 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) @NotNull static <E extends Event,V> @NotNull EventNode<E> value(@NotNull @NotNull String name, @NotNull @NotNull EventFilter<E, V> filter, @NotNull @NotNull 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) @NotNull static <E extends Event> @NotNull EventNode<E> tag(@NotNull @NotNull String name, @NotNull @NotNull EventFilter<E, ? extends TagReadable> filter, @NotNull @NotNull 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) @NotNull static <E extends Event,V> @NotNull EventNode<E> tag(@NotNull @NotNull String name, @NotNull @NotNull EventFilter<E, ? extends TagReadable> filter, @NotNull @NotNull Tag<V> tag, @NotNull @NotNull 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
@Experimental @NotNull <E extends T> @NotNull ListenerHandle<E> getHandle(@NotNull @NotNull Class<E> handleType) 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
@Contract(pure=true) @NotNull <E extends T> @NotNull List<EventNode<E>> findChildren(@NotNull @NotNull String name, Class<E> eventType) 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
@Contract(pure=true) @NotNull default @NotNull List<EventNode<T>> findChildren(@NotNull @NotNull String name) 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
<E extends T> void replaceChildren(@NotNull @NotNull String name, @NotNull @NotNull Class<E> eventType, @NotNull @NotNull EventNode<E> eventNode) 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
default void replaceChildren(@NotNull @NotNull String name, @NotNull @NotNull EventNode<T> eventNode) 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
@Contract("_ -> this") @NotNull @NotNull EventNode<T> addChild(@NotNull @NotNull EventNode<? extends T> child) Directly adds a child node to this node.- Parameters:
child
- The child to add- Returns:
- this, can be used for chaining
-
removeChild
@Contract("_ -> this") @NotNull @NotNull EventNode<T> removeChild(@NotNull @NotNull EventNode<? extends T> child) Directly removes the given child from this node.- Parameters:
child
- The child to remove- Returns:
- this, can be used for chaining
-
addListener
@Contract("_ -> this") @NotNull @NotNull EventNode<T> addListener(@NotNull @NotNull EventListener<? extends T> listener) -
addListener
-
removeListener
@Contract("_ -> this") @NotNull @NotNull EventNode<T> removeListener(@NotNull @NotNull EventListener<? extends T> listener) -
map
@Experimental @NotNull <E extends T,H> @NotNull EventNode<E> map(@NotNull H value, @NotNull @NotNull EventFilter<E, H> filter) 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
-