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.-
Field Summary
Fields inherited from interface dev.demeng.pluginbase.event.functional.SubscriptionBuilder
DEFAULT_EXCEPTION_CONSUMER -
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull SingleSubscription<T>biHandler(@NotNull BiConsumer<SingleSubscription<T>, ? super T> handler) Builds and registers the Handler.@NotNull SingleSubscriptionBuilder<T>exceptionConsumer(@NotNull BiConsumer<? super T, Throwable> consumer) Sets the exception consumer for the handler.default @NotNull SingleSubscriptionBuilder<T>expireAfter(long maxCalls) Sets the number of calls until the handler will automatically be unregistereddefault @NotNull SingleSubscriptionBuilder<T>expireAfter(long duration, @NotNull TimeUnit unit) Sets the expiry time on the handler@NotNull SingleSubscriptionBuilder<T>expireIf(@NotNull BiPredicate<SingleSubscription<T>, T> predicate, @NotNull ExpiryTestStage... testPoints) Add a expiry predicate.default @NotNull SingleSubscriptionBuilder<T>Add a expiry predicate.@NotNull SingleSubscriptionBuilder<T>Adds a filter to the handler.default @NotNull SingleSubscription<T>Builds and registers the Handler.@NotNull SingleHandlerList<T>handlers()Return the handler list builder to append handlers for the event.@NotNull SingleSubscriptionBuilder<T>Sets that the handler should accept subclasses of the event type.static <T extends org.bukkit.event.Event>
@NotNull SingleSubscriptionBuilder<T>newBuilder(@NotNull Class<T> eventClass) Makes a HandlerBuilder for a given eventstatic <T extends org.bukkit.event.Event>
@NotNull SingleSubscriptionBuilder<T>newBuilder(@NotNull Class<T> eventClass, @NotNull org.bukkit.event.EventPriority priority) Makes a HandlerBuilder for a given event
-
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
SingleSubscriptionBuilderto 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 eventpriority- the priority to listen at- Returns:
- a
SingleSubscriptionBuilderto 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:SubscriptionBuilderAdd a expiry predicate.- Specified by:
expireIfin interfaceSubscriptionBuilder<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:SubscriptionBuilderSets the expiry time on the handler- Specified by:
expireAfterin interfaceSubscriptionBuilder<T extends org.bukkit.event.Event>- Parameters:
duration- the duration until expiryunit- the unit for the duration- Returns:
- the builder instance
-
expireAfter
Description copied from interface:SubscriptionBuilderSets the number of calls until the handler will automatically be unregisteredThe call counter is only incremented if the event call passes all filters and if the handler completes without throwing an exception.
- Specified by:
expireAfterin interfaceSubscriptionBuilder<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
Description copied from interface:SubscriptionBuilderAdds 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:
filterin interfaceSubscriptionBuilder<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 testtestPoints- 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
Sets that the handler should accept subclasses of the event type.- Returns:
- the builder instance
-
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
SingleSubscriptioninstance. - 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
SingleSubscriptioninstance. - Throws:
NullPointerException- if the handler is null
-