Interface SingleSubscriptionBuilder<T extends org.bukkit.event.Event>

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

public interface SingleSubscriptionBuilder<T extends org.bukkit.event.Event> extends SubscriptionBuilder<T>
Functional builder for SingleSubscriptions.
  • Method Details

    • newBuilder

      @NotNull static <T extends org.bukkit.event.Event> @NotNull SingleSubscriptionBuilder<T> newBuilder(@NotNull @NotNull Class<T> eventClass)
      Makes a HandlerBuilder for a given event
      Type Parameters:
      T - the event type
      Parameters:
      eventClass - the class of the event
      Returns:
      a SingleSubscriptionBuilder to construct the event handler
      Throws:
      NullPointerException - if eventClass is null
    • newBuilder

      @NotNull static <T extends org.bukkit.event.Event> @NotNull SingleSubscriptionBuilder<T> newBuilder(@NotNull @NotNull Class<T> eventClass, @NotNull @NotNull org.bukkit.event.EventPriority priority)
      Makes a HandlerBuilder for a given event
      Type Parameters:
      T - the event type
      Parameters:
      eventClass - the class of the event
      priority - the priority to listen at
      Returns:
      a SingleSubscriptionBuilder to construct the event handler
      Throws:
      NullPointerException - if eventClass or priority is null
    • expireIf

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

      @NotNull default @NotNull SingleSubscriptionBuilder<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 extends org.bukkit.event.Event>
      Parameters:
      duration - the duration until expiry
      unit - the unit for the duration
      Returns:
      the builder instance
    • expireAfter

      @NotNull default @NotNull SingleSubscriptionBuilder<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 extends org.bukkit.event.Event>
      Parameters:
      maxCalls - the number of times the handler will be called until being unregistered.
      Returns:
      the builder instance
    • filter

      @NotNull @NotNull SingleSubscriptionBuilder<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 extends org.bukkit.event.Event>
      Parameters:
      predicate - the filter
      Returns:
      the builder instance
    • expireIf

      @NotNull @NotNull SingleSubscriptionBuilder<T> expireIf(@NotNull @NotNull BiPredicate<SingleSubscription<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
    • exceptionConsumer

      @NotNull @NotNull SingleSubscriptionBuilder<T> exceptionConsumer(@NotNull @NotNull BiConsumer<? super T,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
    • handleSubclasses

      @NotNull @NotNull SingleSubscriptionBuilder<T> handleSubclasses()
      Sets that the handler should accept subclasses of the event type.
      Returns:
      the builder instance
    • handlers

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

      @NotNull default @NotNull SingleSubscription<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 SingleSubscription instance.
      Throws:
      NullPointerException - if the handler is null
    • biHandler

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