Class SimpleTempListener<E extends org.bukkit.event.Event>
- Type Parameters:
E- Event type
- All Implemented Interfaces:
TempListener,org.bukkit.event.Listener
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ultikits.ultitools.interfaces.TempListener
TempListener.DefaultTempListenerBuilder<E extends org.bukkit.event.Event> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TempEventHandler<E> private org.bukkit.event.EventPriorityprivate static final Set<SimpleTempListener<?>> Tracks which listener instances are currently registered, so a secondregister()call on the same instance is a no-op instead of a silent duplicate Bukkit registration. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version.SimpleTempListener(Class<E> eventClass, TempEventHandler<E> eventHandler) Deprecated, for removal: This API element is subject to removal in a future version.Use the four-argument(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class).SimpleTempListener(Class<E> eventClass, TempEventHandler<E> eventHandler, Function<E, Boolean> filter) Deprecated, for removal: This API element is subject to removal in a future version.Use the four-argument(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class).SimpleTempListener(Class<E> eventClass, TempEventHandler<E> eventHandler, org.bukkit.event.EventPriority priority) Deprecated, for removal: This API element is subject to removal in a future version.Use the four-argument(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class). -
Method Summary
Modifier and TypeMethodDescriptionvoidregister()Register the listener with Bukkit.voidUnregister the listener and clear its registration tracking so a laterregister()call on the same instance actually re-registers.
-
Field Details
-
eventClass
-
priority
private org.bukkit.event.EventPriority priority -
eventHandler
-
filter
-
REGISTERED
Tracks which listener instances are currently registered, so a secondregister()call on the same instance is a no-op instead of a silent duplicate Bukkit registration. Static (not an instance field) so it does not change@AllArgsConstructor's generated signature. Weak keys so a listener that is simply dropped (never unregistered) does not leak.Thread contract: the set is shared by every temporary listener and is touched from any thread that calls
register()and from any event thread whose handler returnstrue, which is an asynchronous thread for events such asAsyncPlayerChatEvent. It is therefore wrapped withCollections.synchronizedSet(Set), so everyaddandremovesynchronizes on this set's own monitor. That lock is held only for the set operation and never across a Bukkit call (registerEventorHandlerList.unregisterAll): synchronous dispatch runs handlers, which may callunregister(), under Bukkit's own synchronization, and spanning both locks would invite a lock-order inversion.
-
-
Constructor Details
-
SimpleTempListener
Deprecated, for removal: This API element is subject to removal in a future version.Use the four-argument(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class). Scheduled for removal in 6.4.0.Hand-written rather than Lombok-generated so it can carry its own javadoc. Lombok's@NoArgsConstructor(onConstructor_ = @Deprecated(...))form was confirmed (via javap on the compiled class) to correctly carrysince/forRemovalinto the class file under this project's-source 1.8/ JDK 21 toolchain, but a Lombok-generated member has no source declaration to attach a@deprecatedtag to.- Scheduled removal version:
- 6.4.0
-
SimpleTempListener
@Deprecated(since="6.3.0", forRemoval=true) public SimpleTempListener(Class<E> eventClass, TempEventHandler<E> eventHandler) Deprecated, for removal: This API element is subject to removal in a future version.Use the four-argument(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class). Scheduled for removal in 6.4.0.No filter, default priority. Indistinguishable at the call site from the other three-and-fewer-argument constructors below - this confusability is exactly why these constructors are being removed (T-05-37).- Scheduled removal version:
- 6.4.0
-
SimpleTempListener
@Deprecated(since="6.3.0", forRemoval=true) public SimpleTempListener(Class<E> eventClass, TempEventHandler<E> eventHandler, Function<E, Boolean> filter) Deprecated, for removal: This API element is subject to removal in a future version.Use the four-argument(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class). Scheduled for removal in 6.4.0.Filter, default priority.- Scheduled removal version:
- 6.4.0
-
SimpleTempListener
@Deprecated(since="6.3.0", forRemoval=true) public SimpleTempListener(Class<E> eventClass, TempEventHandler<E> eventHandler, org.bukkit.event.EventPriority priority) Deprecated, for removal: This API element is subject to removal in a future version.Use the four-argument(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class). Scheduled for removal in 6.4.0.No filter, explicit priority. This is the overloadbuild()used to resolve to before SILENT-12 was fixed - the last-parameter arity clash with the constructor above (aFunctionvs. anEventPriorityin the same position) is the defect mechanism this deprecation window exists to remove.- Scheduled removal version:
- 6.4.0
-
-
Method Details
-
register
public void register()Register the listener with Bukkit. A second call on an instance that is still registered is a no-op.May be called on any thread. Distinct listeners may be registered and unregistered concurrently from different threads; one instance must not be registered on one thread while it is being unregistered on another.
- Specified by:
registerin interfaceTempListener
-
unregister
public void unregister()Unregister the listener and clear its registration tracking so a laterregister()call on the same instance actually re-registers.May be called on any thread, including an asynchronous event thread when the handler returns
true. The registration marker is cleared under the shared set's lock first; Bukkit's handler cleanup then runs outside that lock. The same-instance restriction ofregister()applies.- Specified by:
unregisterin interfaceTempListener
-
(Class, EventPriority, TempEventHandler, Function)constructor (Lombok-generated via@AllArgsConstructor, so it has no source declaration to link to) orTempListener.common(Class).