java.lang.Object
net.botwithus.rs3.events.EventBus
EventBus
relies on preview features of the Java platform:
EventBus
refers to one or more preview APIs:MemorySegment
.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
The EventBus handles incoming events from RuneScape or Scripts
Usage Example:
//Subscribing to events
Script owner = ...;
Subscription<InteractionEvent> sub = EventBus.EVENT_BUS.subscribe(owner, InteractionEvent.class, event -> {
int opcode = event.getOpcode();
int param1 = event.getParam1();
int param2 = event.getParam2();
int param3 = event.getParam3();
System.out.println("Opcode: " + opcode);
System.out.println("Param1: " + param1);
System.out.println("Param2: " + param2);
System.out.println("Param3: " + param3);
});
//Publishing your own events
Script owner = ...;
MyEvent event = ...;
EventBus bus = EventBus.EVENT_BUS;
bus.publish(event);
Subscription<MyEvent> sub = bus.subscribe(owner, MyEvent.class, myEvent -> {
myEvent.myFunction();
System.out.println(myEvent.toString());
});
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescription<T,
S extends ImmutableScript>
voidpublish
(S owner, T event) Publish an event to a specific owner<T> void
publish
(T event) Publish an event to all known owners of subscriptionsstatic void
receiveNativeEvent
(int eventCode, MemorySegmentPREVIEW nativeEvent) <T> Subscription<T>
Subscribe to an Event<T> void
unsubscribe
(@NotNull Subscription<T> sub) <T> void
unsubscribe
(@NotNull Script owner, @NotNull Class<T> eventType, @NotNull Consumer<T> listener) Remove a subscription to an Event<T> void
unsubscribeAll
(@NotNull Subscription<T> sub)
-
Field Details
-
EVENT_BUS
-
-
Method Details
-
receiveNativeEvent
-
subscribe
public <T> Subscription<T> subscribe(@NotNull @NotNull Script owner, @NotNull @NotNull Class<T> eventType, @NotNull @NotNull Consumer<T> listener) Subscribe to an Event- Type Parameters:
T
- The generic event type- Parameters:
owner
- The owner of the subscriptioneventType
- The event typelistener
- The behaviour when the event is published- Returns:
- The
Subscription
to the event
-
unsubscribe
public <T> void unsubscribe(@NotNull @NotNull Script owner, @NotNull @NotNull Class<T> eventType, @NotNull @NotNull Consumer<T> listener) Remove a subscription to an Event- Type Parameters:
T
- The generic event type- Parameters:
owner
- The owner of theSubscription
eventType
- The event typelistener
- The behaviour when the event is published
-
unsubscribe
-
unsubscribeAll
-
publish
Publish an event to a specific owner- Type Parameters:
T
- The generic event type- Parameters:
owner
- A script who owns subscriptions to this eventevent
- The event- See Also:
-
publish
public <T> void publish(@NotNull T event) Publish an event to all known owners of subscriptions- Type Parameters:
T
- The generic event type- Parameters:
event
- The event to be published- See Also:
-
EventBus
when preview features are enabled.