Interface MergedSubscriptionBuilder<T>
- Type Parameters:
T- the handled type
- All Superinterfaces:
SubscriptionBuilder<T>
Functional builder for
MergedSubscriptions.-
Field Summary
Fields inherited from interface dev.demeng.pluginbase.event.functional.SubscriptionBuilder
DEFAULT_EXCEPTION_CONSUMER -
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull MergedSubscription<T>biHandler(@NotNull BiConsumer<MergedSubscription<T>, ? super T> handler) Builds and registers the Handler.<E extends org.bukkit.event.Event>
@NotNull MergedSubscriptionBuilder<T>Binds this handler to an event<E extends org.bukkit.event.Event>
@NotNull MergedSubscriptionBuilder<T>bindEvent(@NotNull Class<E> eventClass, @NotNull org.bukkit.event.EventPriority priority, @NotNull Function<E, T> function) Binds this handler to an event@NotNull MergedSubscriptionBuilder<T>exceptionConsumer(@NotNull BiConsumer<org.bukkit.event.Event, Throwable> consumer) Sets the exception consumer for the handler.default @NotNull MergedSubscriptionBuilder<T>expireAfter(long maxCalls) Sets the number of calls until the handler will automatically be unregistereddefault @NotNull MergedSubscriptionBuilder<T>expireAfter(long duration, @NotNull TimeUnit unit) Sets the expiry time on the handler@NotNull MergedSubscriptionBuilder<T>expireIf(@NotNull BiPredicate<MergedSubscription<T>, T> predicate, @NotNull ExpiryTestStage... testPoints) Add a expiry predicate.default @NotNull MergedSubscriptionBuilder<T>Add a expiry predicate.@NotNull MergedSubscriptionBuilder<T>Adds a filter to the handler.default @NotNull MergedSubscription<T>Builds and registers the Handler.@NotNull MergedHandlerList<T>handlers()Return the handler list builder to append handlers for the event.static <T> @NotNull MergedSubscriptionBuilder<T>newBuilder(@NotNull com.google.common.reflect.TypeToken<T> type) Makes a MergedHandlerBuilder for a given super typestatic <S extends org.bukkit.event.Event>
@NotNull MergedSubscriptionBuilder<S>newBuilder(@NotNull Class<S> superClass, @NotNull Class<? extends S>... eventClasses) Makes a MergedHandlerBuilder for a super event classstatic <S extends org.bukkit.event.Event>
@NotNull MergedSubscriptionBuilder<S>newBuilder(@NotNull Class<S> superClass, @NotNull org.bukkit.event.EventPriority priority, @NotNull Class<? extends S>... eventClasses) Makes a MergedHandlerBuilder for a super event classstatic <T> @NotNull MergedSubscriptionBuilder<T>newBuilder(@NotNull Class<T> handledClass) Makes a MergedHandlerBuilder for a given super type
-
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
MergedSubscriptionBuilderto 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
MergedSubscriptionBuilderto 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 classeventClasses- the event classes to be bound to- Returns:
- a
MergedSubscriptionBuilderto 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 classpriority- the priority to listen ateventClasses- the event classes to be bound to- Returns:
- a
MergedSubscriptionBuilderto construct the event handler
-
expireIf
@NotNull default @NotNull MergedSubscriptionBuilder<T> expireIf(@NotNull @NotNull Predicate<T> predicate) Description copied from interface:SubscriptionBuilderAdd a expiry predicate.- Specified by:
expireIfin interfaceSubscriptionBuilder<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:SubscriptionBuilderSets the expiry time on the handler- Specified by:
expireAfterin interfaceSubscriptionBuilder<T>- 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>- 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>- 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 testtestPoints- 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 tofunction- 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 topriority- the priority to listen atfunction- 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
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
MergedSubscriptioninstance. - Throws:
NullPointerException- if the handler is nullIllegalStateException- 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
MergedSubscriptioninstance. - Throws:
NullPointerException- if the handler is nullIllegalStateException- if no events have been bound to
-