接口 Test.EventListenerGroup.EventListenerCollector

所有已知实现类:
EventListenerGroupImpl.EventListenerCollectorImpl
封闭接口:
Test.EventListenerGroup

@ParametersAreNonnullByDefault public static interface Test.EventListenerGroup.EventListenerCollector
A collector of event listeners which automatically unregisters listeners when a test is disabled.
  • 方法概要

    修饰符和类型
    方法
    说明
    default <T extends net.neoforged.bus.api.Event>
    void
    addListener(Consumer<T> consumer)
    Add a consumer listener with default EventPriority.NORMAL and not receiving cancelled events.
    <T extends net.neoforged.bus.api.Event>
    void
    addListener(net.neoforged.bus.api.EventPriority priority, boolean receiveCancelled, Class<T> eventType, Consumer<T> consumer)
    Add a consumer listener with the specified EventPriority and potentially cancelled events.
    <T extends net.neoforged.bus.api.Event>
    void
    addListener(net.neoforged.bus.api.EventPriority priority, boolean receiveCancelled, Consumer<T> consumer)
    Add a consumer listener with the specified EventPriority and potentially cancelled events.
    void
    register(Object object)
    Register an instance object or a Class, and add listeners for all SubscribeEvent annotated methods found there.
    void
    registerAll(net.neoforged.bus.api.IEventBus bus)
    Registers all the listeners added through this collector.
    void
    unregisterAll(net.neoforged.bus.api.IEventBus bus)
    Unregisters all the listeners added through this collector.
  • 方法详细资料

    • register

      void register(Object object)
      Register an instance object or a Class, and add listeners for all SubscribeEvent annotated methods found there.

      Depending on what is passed as an argument, different listener creation behaviour is performed.

      Object Instance
      Scanned for non-static methods annotated with SubscribeEvent and creates listeners for each method found.
      Class Instance
      Scanned for static methods annotated with SubscribeEvent and creates listeners for each method found.
      参数:
      object - either a Class instance or an arbitrary object, for scanning and event listener creation
    • unregisterAll

      void unregisterAll(net.neoforged.bus.api.IEventBus bus)
      Unregisters all the listeners added through this collector.
      参数:
      bus - the bus to unregister from
    • registerAll

      void registerAll(net.neoforged.bus.api.IEventBus bus)
      Registers all the listeners added through this collector.
      参数:
      bus - the bus to register
    • addListener

      <T extends net.neoforged.bus.api.Event> void addListener(net.neoforged.bus.api.EventPriority priority, boolean receiveCancelled, Class<T> eventType, Consumer<T> consumer)
      Add a consumer listener with the specified EventPriority and potentially cancelled events.
      Use this method when one of the other methods fails to determine the concrete Event subclass that is intended to be subscribed to.
      类型参数:
      T - the Event subclass to listen for
      参数:
      priority - the priority of the listener
      receiveCancelled - indicate if this listener should receive events that have been ICancellableEvent cancelled
      eventType - the concrete Event subclass to subscribe to
      consumer - callback to invoke when a matching event is received
    • addListener

      <T extends net.neoforged.bus.api.Event> void addListener(net.neoforged.bus.api.EventPriority priority, boolean receiveCancelled, Consumer<T> consumer)
      Add a consumer listener with the specified EventPriority and potentially cancelled events.
      类型参数:
      T - the Event subclass to listen for
      参数:
      priority - the priority of the listener
      receiveCancelled - indicate if this listener should receive events that have been ICancellableEvent cancelled
      consumer - callback to invoke when a matching event is received
    • addListener

      default <T extends net.neoforged.bus.api.Event> void addListener(Consumer<T> consumer)
      Add a consumer listener with default EventPriority.NORMAL and not receiving cancelled events.
      类型参数:
      T - the Event subclass to listen for
      参数:
      consumer - callback to invoke when a matching event is received