Class EventBus

java.lang.Object
net.botwithus.rs3.events.EventBus

public class EventBus extends Object
EventBus relies on preview features of the Java platform:
Programs can only use EventBus when preview features are enabled.
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 Details

    • EVENT_BUS

      public static final EventBus EVENT_BUS
  • Method Details

    • receiveNativeEvent

      public static void receiveNativeEvent(int eventCode, MemorySegmentPREVIEW nativeEvent)
    • 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 subscription
      eventType - The event type
      listener - 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 the Subscription
      eventType - The event type
      listener - The behaviour when the event is published
    • unsubscribe

      public <T> void unsubscribe(@NotNull @NotNull Subscription<T> sub)
    • unsubscribeAll

      public <T> void unsubscribeAll(@NotNull @NotNull Subscription<T> sub)
    • publish

      public <T, S extends ImmutableScript> void publish(@NotNull S owner, @NotNull T event)
      Publish an event to a specific owner
      Type Parameters:
      T - The generic event type
      Parameters:
      owner - A script who owns subscriptions to this event
      event - 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: