Interface MergedSubscriptionBuilder<T>

Type Parameters:
T - the handled type
All Superinterfaces:
SubscriptionBuilder<T>

public interface MergedSubscriptionBuilder<T> extends SubscriptionBuilder<T>
Functional builder for MergedSubscriptions.
  • Method Details

    • newBuilder

      @NotNull static <T> @NotNull MergedSubscriptionBuilder<T> newBuilder(@NotNull @NotNull Class<T> handledClass)
      Makes a MergedHandlerBuilder for a given super type
      Type Parameters:
      T - the super type class
      Parameters:
      handledClass - the super type of the event handler
      Returns:
      a MergedSubscriptionBuilder to construct the event handler
    • newBuilder

      @NotNull static <T> @NotNull MergedSubscriptionBuilder<T> newBuilder(@NotNull @NotNull com.google.common.reflect.TypeToken<T> type)
      Makes a MergedHandlerBuilder for a given super type
      Type Parameters:
      T - the super type class
      Parameters:
      type - the super type of the event handler
      Returns:
      a MergedSubscriptionBuilder to construct the event handler
    • newBuilder

      @NotNull @SafeVarargs static <S extends org.bukkit.event.Event> @NotNull MergedSubscriptionBuilder<S> newBuilder(@NotNull @NotNull Class<S> superClass, @NotNull @NotNull Class<? extends S>... eventClasses)
      Makes a MergedHandlerBuilder for a super event class
      Type Parameters:
      S - the super class type
      Parameters:
      superClass - the abstract super event class
      eventClasses - the event classes to be bound to
      Returns:
      a MergedSubscriptionBuilder to construct the event handler
    • newBuilder

      @NotNull @SafeVarargs static <S extends org.bukkit.event.Event> @NotNull MergedSubscriptionBuilder<S> newBuilder(@NotNull @NotNull Class<S> superClass, @NotNull @NotNull org.bukkit.event.EventPriority priority, @NotNull @NotNull Class<? extends S>... eventClasses)
      Makes a MergedHandlerBuilder for a super event class
      Type Parameters:
      S - the super class type
      Parameters:
      superClass - the abstract super event class
      priority - the priority to listen at
      eventClasses - the event classes to be bound to
      Returns:
      a MergedSubscriptionBuilder to construct the event handler
    • expireIf

      @NotNull default @NotNull MergedSubscriptionBuilder<T> expireIf(@NotNull @NotNull Predicate<T> predicate)
      Description copied from interface: SubscriptionBuilder
      Add a expiry predicate.
      Specified by:
      expireIf in interface SubscriptionBuilder<T>
      Parameters:
      predicate - the expiry test
      Returns:
      ths builder instance
    • expireAfter

      @NotNull default @NotNull MergedSubscriptionBuilder<T> expireAfter(long duration, @NotNull @NotNull TimeUnit unit)
      Description copied from interface: SubscriptionBuilder
      Sets the expiry time on the handler
      Specified by:
      expireAfter in interface SubscriptionBuilder<T>
      Parameters:
      duration - the duration until expiry
      unit - the unit for the duration
      Returns:
      the builder instance
    • expireAfter

      @NotNull default @NotNull MergedSubscriptionBuilder<T> expireAfter(long maxCalls)
      Description copied from interface: SubscriptionBuilder
      Sets the number of calls until the handler will automatically be unregistered

      The call counter is only incremented if the event call passes all filters and if the handler completes without throwing an exception.

      Specified by:
      expireAfter in interface SubscriptionBuilder<T>
      Parameters:
      maxCalls - the number of times the handler will be called until being unregistered.
      Returns:
      the builder instance
    • filter

      @NotNull @NotNull MergedSubscriptionBuilder<T> filter(@NotNull @NotNull Predicate<T> predicate)
      Description copied from interface: SubscriptionBuilder
      Adds a filter to the handler.

      An event will only be handled if it passes all filters. Filters are evaluated in the order they are registered.

      Specified by:
      filter in interface SubscriptionBuilder<T>
      Parameters:
      predicate - the filter
      Returns:
      the builder instance
    • expireIf

      @NotNull @NotNull MergedSubscriptionBuilder<T> expireIf(@NotNull @NotNull BiPredicate<MergedSubscription<T>,T> predicate, @NotNull @NotNull ExpiryTestStage... testPoints)
      Add a expiry predicate.
      Parameters:
      predicate - the expiry test
      testPoints - when to test the expiry predicate
      Returns:
      ths builder instance
    • bindEvent

      @NotNull <E extends org.bukkit.event.Event> @NotNull MergedSubscriptionBuilder<T> bindEvent(@NotNull @NotNull Class<E> eventClass, @NotNull @NotNull Function<E,T> function)
      Binds this handler to an event
      Type Parameters:
      E - the event class
      Parameters:
      eventClass - the event class to bind to
      function - the function to remap the event
      Returns:
      the builder instance
    • bindEvent

      @NotNull <E extends org.bukkit.event.Event> @NotNull MergedSubscriptionBuilder<T> bindEvent(@NotNull @NotNull Class<E> eventClass, @NotNull @NotNull org.bukkit.event.EventPriority priority, @NotNull @NotNull Function<E,T> function)
      Binds this handler to an event
      Type Parameters:
      E - the event class
      Parameters:
      eventClass - the event class to bind to
      priority - the priority to listen at
      function - the function to remap the event
      Returns:
      the builder instance
    • exceptionConsumer

      @NotNull @NotNull MergedSubscriptionBuilder<T> exceptionConsumer(@NotNull @NotNull BiConsumer<org.bukkit.event.Event,Throwable> consumer)
      Sets the exception consumer for the handler.

      If an exception is thrown in the handler, it is passed to this consumer to be swallowed.

      Parameters:
      consumer - the consumer
      Returns:
      the builder instance
      Throws:
      NullPointerException - if the consumer is null
    • handlers

      @NotNull @NotNull MergedHandlerList<T> handlers()
      Return the handler list builder to append handlers for the event.
      Returns:
      the handler list
    • handler

      @NotNull default @NotNull MergedSubscription<T> handler(@NotNull @NotNull Consumer<? super T> handler)
      Builds and registers the Handler.
      Parameters:
      handler - the consumer responsible for handling the event.
      Returns:
      a registered MergedSubscription instance.
      Throws:
      NullPointerException - if the handler is null
      IllegalStateException - if no events have been bound to
    • biHandler

      @NotNull default @NotNull MergedSubscription<T> biHandler(@NotNull @NotNull BiConsumer<MergedSubscription<T>,? super T> handler)
      Builds and registers the Handler.
      Parameters:
      handler - the bi-consumer responsible for handling the event.
      Returns:
      a registered MergedSubscription instance.
      Throws:
      NullPointerException - if the handler is null
      IllegalStateException - if no events have been bound to