Class OwnedEventBusImpl<O,E,S extends OwnedSubscriber<O,? extends E>>

java.lang.Object
org.geysermc.event.bus.impl.OwnedEventBusImpl<O,E,S>
All Implemented Interfaces:
BaseBus<E,S>, OwnedEventBus<O,E,S>

public abstract class OwnedEventBusImpl<O,E,S extends OwnedSubscriber<O,? extends E>> extends Object implements OwnedEventBus<O,E,S>
  • Constructor Details

    • OwnedEventBusImpl

      public OwnedEventBusImpl()
  • Method Details

    • makeSubscription

      protected abstract <L, T extends E, B extends OwnedSubscriber<O, T>> B makeSubscription(@NonNull O owner, @NonNull Class<T> eventClass, @NonNull Subscribe subscribe, @NonNull L listener, @NonNull BiConsumer<L,T> handler)
    • makeSubscription

      protected abstract <T extends E, B extends OwnedSubscriber<O, T>> B makeSubscription(@NonNull O owner, @NonNull Class<T> eventClass, @NonNull Consumer<T> handler, @NonNull PostOrder postOrder)
    • subscribe

      public <T extends E, U extends OwnedSubscriber<O, T>> @NonNull U subscribe(@NonNull O owner, @NonNull Class<T> eventClass, @NonNull Consumer<T> handler)
      Description copied from interface: OwnedEventBus
      Subscribes to the given event see Subscriber.

      The difference between this method and is that this method takes in an extension parameter which allows for the event to be unsubscribed upon extension disable and reloads.

      Specified by:
      subscribe in interface OwnedEventBus<O,E,S extends OwnedSubscriber<O,? extends E>>
      Type Parameters:
      T - the event class
      Parameters:
      owner - the extension to subscribe the event to
      eventClass - the class of the event
      handler - the consumer for handling the event
      Returns:
      the event subscription
    • subscribe

      public <T extends E, U extends OwnedSubscriber<O, T>> @NonNull U subscribe(@NonNull O owner, @NonNull Class<T> eventClass, @NonNull Consumer<T> handler, @NonNull PostOrder postOrder)
      Description copied from interface: OwnedEventBus
      Subscribes to the given event see Subscriber.

      The difference between this method and is that this method takes in an extension parameter which allows for the event to be unsubscribed upon extension disable and reloads.

      Specified by:
      subscribe in interface OwnedEventBus<O,E,S extends OwnedSubscriber<O,? extends E>>
      Type Parameters:
      T - the event class
      Parameters:
      owner - the extension to subscribe the event to
      eventClass - the class of the event
      handler - the consumer for handling the event
      postOrder - the order of the subscriber
      Returns:
      the event subscription
    • register

      public void register(@NonNull O owner, @NonNull Object listener)
      Description copied from interface: OwnedEventBus
      Registers events for the given listener.
      Specified by:
      register in interface OwnedEventBus<O,E,S extends OwnedSubscriber<O,? extends E>>
      Parameters:
      owner - the extension registering the event
      listener - the listener
    • unregisterAll

      public void unregisterAll(@NonNull O owner)
      Description copied from interface: OwnedEventBus
      Unregisters all events from a given owner.
      Specified by:
      unregisterAll in interface OwnedEventBus<O,E,S extends OwnedSubscriber<O,? extends E>>
      Parameters:
      owner - the extension
    • subscribers

      public <T extends E> @NonNull Set<? extends OwnedSubscriber<O,T>> subscribers(@NonNull Class<T> eventClass)
      Description copied from interface: BaseBus
      Gets the subscriptions for the given event class.
      Specified by:
      subscribers in interface BaseBus<O,E>
      Specified by:
      subscribers in interface OwnedEventBus<O,E,S extends OwnedSubscriber<O,? extends E>>
      Type Parameters:
      T - the value
      Parameters:
      eventClass - the event class
      Returns:
      the subscriptions for the event class
    • register

      protected <T extends E> void register(Class<T> eventClass, S subscriber)
    • findSubscriptions

      protected <T extends E> void findSubscriptions(@NonNull Object listener, TriConsumer<Class<T>,Subscribe,BiConsumer<Object,T>> consumer)
    • unsubscribe

      public void unsubscribe(S subscription)
      Description copied from interface: BaseBus
      Unsubscribes the given Subscriber.
      Specified by:
      unsubscribe in interface BaseBus<E,S extends Subscriber<? extends E>>
      Parameters:
      subscription - the event subscription
    • unsubscribeMany

      protected void unsubscribeMany(Iterable<S> subscriptions)
    • unsubscribeAll

      protected void unsubscribeAll()
    • fire

      public FireResult fire(E event)
      Description copied from interface: BaseBus
      Fires the given event and log all exceptions that occur while executing this event.
      Specified by:
      fire in interface BaseBus<E,S extends Subscriber<? extends E>>
      Parameters:
      event - the event to fire
    • fireSilently

      public FireResult fireSilently(E event)
      Description copied from interface: BaseBus
      Fires the given event silently.
      Specified by:
      fireSilently in interface BaseBus<E,S extends Subscriber<? extends E>>
      Parameters:
      event - the event to fire
      Returns:
      the result of firing the given event
    • sortedSubscribers

      protected List<S> sortedSubscribers(Class<?> eventClass)
    • eventSubscribers

      protected <T extends Subscriber<U>, U> Set<T> eventSubscribers(Class<U> eventType)
    • castGenericNullableSet

      protected static <T extends U, U> Set<T> castGenericNullableSet(@Nullable Set<U> o)