Interface EventNode<T extends Event>

Type Parameters:
T - The event type accepted by this node
All Known Implementing Classes:
GlobalEventHandler

public sealed interface EventNode<T extends Event>
Represents a single node in an event graph.

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 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 the EventFilter.

      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 node
      filter - 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 node
      filter - The event type filter to apply
      predicate - 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 the EventFilter.

      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 node
      V - The handler type of the event filter
      Parameters:
      name - The name of the event node
      filter - The event type filter to apply
      predicate - 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 the EventFilter.

      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 node
      V - The handler type of the event filter
      Parameters:
      name - The name of the event node
      filter - The event type filter to apply
      predicate - 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 be TagReadable.

      Type Parameters:
      E - The resulting event type of the node
      Parameters:
      name - The name of the event node
      filter - The event type filter to apply
      tag - 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 node
      filter - The event type filter to apply
      tag - The tag which must be contained on the event handler
      consumer - 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

      default void call(@NotNull T event)
      Calls an event starting from this node.
      Parameters:
      event - the event to call
    • hasListener

      default boolean hasListener(@NotNull @NotNull Class<? extends T> type)
    • 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

      default void callCancellable(@NotNull T event, @NotNull @NotNull Runnable successCallback)
      Execute a cancellable event with a callback to execute if the event is successful. Event conditions and propagation is the same as call(Event).
      Parameters:
      event - The event to execute
      successCallback - A callback if the event is not cancelled
    • getEventType

      @Contract(pure=true) @NotNull @NotNull Class<T> getEventType()
    • getName

      @Contract(pure=true) @NotNull @NotNull String getName()
    • getPriority

      @Contract(pure=true) int getPriority()
    • setPriority

      @Contract("_ -> this") @NotNull @NotNull EventNode<T> setPriority(int priority)
    • getParent

      @Contract(pure=true) @Nullable @Nullable EventNode<? super T> getParent()
    • getChildren

      @Contract(pure=true) @NotNull @NotNull Set<@NotNull EventNode<T>> 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 for
      eventType - 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 for
      eventType - The event node type to filter for
      eventNode - 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 for
      eventNode - The replacement node
    • removeChildren

      void removeChildren(@NotNull @NotNull String name, @NotNull @NotNull Class<? extends T> eventType)
      Recursively removes children with the given name and type starting at this node.
      Parameters:
      name - The node name to filter for
      eventType - The node type to filter for
    • removeChildren

      default void removeChildren(@NotNull @NotNull String name)
      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

      @Contract("_, _ -> this") @NotNull default <E extends T> @NotNull EventNode<T> addListener(@NotNull @NotNull Class<E> eventType, @NotNull @NotNull Consumer<@NotNull E> listener)
    • 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 value
      filter - the filter to use
      Returns:
      the node (which may have already been registered) directly linked to value
    • unmap

      @Experimental void unmap(@NotNull @NotNull Object value)
      Prevents the node from map(Object, EventFilter) to be called.
      Parameters:
      value - the value to unmap
    • register

      @Experimental void register(@NotNull @NotNull EventBinding<? extends T> binding)
    • unregister

      @Experimental void unregister(@NotNull @NotNull EventBinding<? extends T> binding)