Package net.dv8tion.jda.api.utils
Class Once.Builder<E extends GenericEvent>
java.lang.Object
net.dv8tion.jda.api.utils.Once.Builder<E>
- Type Parameters:
- E- Type of the event listened to
- Enclosing class:
- Once<E extends GenericEvent>
Builds a one-time event listener, can be reused.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionAdds an event filter, all filters need to returntruefor the event to be consumed.setTimeoutPool(ScheduledExecutorService timeoutPool) Sets the thread pool used to schedule timeouts and run its callback.Starts listening for the event, once.Sets the timeout duration, after which the event is no longer listener for.Sets the timeout duration, after which the event is no longer listener for, and the callback is run.
- 
Constructor Details- 
BuilderCreates a builder for a one-time event listener- Parameters:
- jda- The JDA instance
- eventType- The event type to listen for
- Throws:
- IllegalArgumentException- If any of the parameters is null
 
 
- 
- 
Method Details- 
filterAdds an event filter, all filters need to returntruefor the event to be consumed.If the filter throws an exception, this listener will unregister itself. - Parameters:
- filter- The filter to add, returns- trueif the event can be consumed
- Returns:
- This instance for chaining convenience
- Throws:
- IllegalArgumentException- If the filter is null
 
- 
timeoutSets the timeout duration, after which the event is no longer listener for.- Parameters:
- timeout- The duration after which the event is no longer listener for
- Returns:
- This instance for chaining convenience
- Throws:
- IllegalArgumentException- If the timeout is null
 
- 
timeout@Nonnull public Once.Builder<E> timeout(@Nonnull Duration timeout, @Nullable Runnable timeoutCallback) Sets the timeout duration, after which the event is no longer listener for, and the callback is run.- Parameters:
- timeout- The duration after which the event is no longer listener for
- timeoutCallback- The callback run after the duration
- Returns:
- This instance for chaining convenience
- Throws:
- IllegalArgumentException- If the timeout is null
 
- 
setTimeoutPoolSets the thread pool used to schedule timeouts and run its callback.By default JDA.getGatewayPool()is used.- Parameters:
- timeoutPool- The thread pool to use for timeouts
- Returns:
- This instance for chaining convenience
- Throws:
- IllegalArgumentException- If the timeout pool is null
 
- 
subscribeStarts listening for the event, once.The task will be completed after all filtersreturntrue.Exceptions thrown in blockingandasynccontexts includes:- CancellationException- When- Task.cancel()is called
- TimeoutException- When the listener has expired
- Any exception thrown by the timeout callback
 - Returns:
- Taskreturning an event satisfying all preconditions
- Throws:
- IllegalArgumentException- If the callback is null
- See Also:
 
 
-