2021-08-19 06:45:23 +02:00
|
|
|
package net.minestom.server.event;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.ApiStatus;
|
2021-08-24 15:35:09 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2021-08-19 06:45:23 +02:00
|
|
|
|
2021-08-22 13:56:12 +02:00
|
|
|
/**
|
2021-08-30 12:33:09 +02:00
|
|
|
* Represents a key to a listenable event, retrievable from {@link EventNode#getHandle(Class)}.
|
2021-08-22 13:56:12 +02:00
|
|
|
* Useful to avoid map lookups.
|
2021-08-30 12:33:09 +02:00
|
|
|
* <p>
|
|
|
|
* It is recommended to store instances of this class in {@code static final} fields.
|
2021-08-22 13:56:12 +02:00
|
|
|
*
|
|
|
|
* @param <E> the event type
|
|
|
|
*/
|
2021-08-24 15:25:11 +02:00
|
|
|
@ApiStatus.Experimental
|
2021-10-22 01:55:55 +02:00
|
|
|
public sealed interface ListenerHandle<E extends Event> permits EventNodeImpl.Handle {
|
2021-08-30 12:33:09 +02:00
|
|
|
/**
|
|
|
|
* Calls the given event.
|
|
|
|
* Will try to fast exit the execution when possible if {@link #hasListener()} return {@code false}.
|
|
|
|
* <p>
|
|
|
|
* Anonymous and subclasses are not supported, events must have the exact type {@code E}.
|
|
|
|
*
|
|
|
|
* @param event the event to call
|
|
|
|
*/
|
2021-08-24 15:35:09 +02:00
|
|
|
void call(@NotNull E event);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets if any listener has been registered for the given handle.
|
|
|
|
* May trigger an update if the cached data is not correct.
|
|
|
|
* <p>
|
|
|
|
* Useful if you are able to avoid expensive computation in the case where
|
|
|
|
* the event is unused. Be aware that {@link #call(Event)}
|
|
|
|
* has similar optimization built-in.
|
|
|
|
*
|
|
|
|
* @return true if the event has 1 or more listeners
|
|
|
|
*/
|
|
|
|
boolean hasListener();
|
2021-08-19 06:45:23 +02:00
|
|
|
}
|