Class SimpleTempListener<E extends org.bukkit.event.Event>

java.lang.Object
com.ultikits.ultitools.interfaces.impl.SimpleTempListener<E>
Type Parameters:
E - Event type
All Implemented Interfaces:
TempListener, org.bukkit.event.Listener

public class SimpleTempListener<E extends org.bukkit.event.Event> extends Object implements TempListener
Simple temp listener.
See Also:
  • Field Details

    • eventClass

      private Class<E extends org.bukkit.event.Event> eventClass
    • priority

      private org.bukkit.event.EventPriority priority
    • eventHandler

      private TempEventHandler<E extends org.bukkit.event.Event> eventHandler
    • filter

      private Function<E extends org.bukkit.event.Event,Boolean> filter
    • REGISTERED

      private static final Set<SimpleTempListener<?>> REGISTERED
      Tracks which listener instances are currently registered, so a second register() 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 returns true, which is an asynchronous thread for events such as AsyncPlayerChatEvent. It is therefore wrapped with Collections.synchronizedSet(Set), so every add and remove synchronizes on this set's own monitor. That lock is held only for the set operation and never across a Bukkit call (registerEvent or HandlerList.unregisterAll): synchronous dispatch runs handlers, which may call unregister(), under Bukkit's own synchronization, and spanning both locks would invite a lock-order inversion.

  • Constructor Details

    • SimpleTempListener

      @Deprecated(since="6.3.0", forRemoval=true) public 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) or TempListener.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 carry since/forRemoval into 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 @deprecated tag 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) or TempListener.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) or TempListener.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) or TempListener.common(Class). Scheduled for removal in 6.4.0.
      No filter, explicit priority. This is the overload build() used to resolve to before SILENT-12 was fixed - the last-parameter arity clash with the constructor above (a Function vs. an EventPriority in 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:
      register in interface TempListener
    • unregister

      public void unregister()
      Unregister the listener and clear its registration tracking so a later register() 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 of register() applies.

      Specified by:
      unregister in interface TempListener