接口 Test.EventListenerGroup.EventListenerCollector
- 封闭接口:
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>
voidaddListener
(Consumer<T> consumer) Add a consumer listener with defaultEventPriority.NORMAL
and not receiving cancelled events.<T extends net.neoforged.bus.api.Event>
voidaddListener
(net.neoforged.bus.api.EventPriority priority, boolean receiveCancelled, Class<T> eventType, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriority
and potentially cancelled events.<T extends net.neoforged.bus.api.Event>
voidaddListener
(net.neoforged.bus.api.EventPriority priority, boolean receiveCancelled, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriority
and potentially cancelled events.void
Register an instance object or a Class, and add listeners for allSubscribeEvent
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
Register an instance object or a Class, and add listeners for allSubscribeEvent
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 aClass
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 specifiedEventPriority
and potentially cancelled events.
Use this method when one of the other methods fails to determine the concreteEvent
subclass that is intended to be subscribed to.- 类型参数:
T
- theEvent
subclass to listen for- 参数:
priority
- the priority of the listenerreceiveCancelled
- indicate if this listener should receive events that have beenICancellableEvent
cancelledeventType
- the concreteEvent
subclass to subscribe toconsumer
- 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 specifiedEventPriority
and potentially cancelled events.- 类型参数:
T
- theEvent
subclass to listen for- 参数:
priority
- the priority of the listenerreceiveCancelled
- indicate if this listener should receive events that have beenICancellableEvent
cancelledconsumer
- callback to invoke when a matching event is received
-
addListener
Add a consumer listener with defaultEventPriority.NORMAL
and not receiving cancelled events.- 类型参数:
T
- theEvent
subclass to listen for- 参数:
consumer
- callback to invoke when a matching event is received
-