Interface BattleEvents

All Known Subinterfaces:
BattleController
All Known Implementing Classes:
MultiLaneBattleController, StandardBattleController

public interface BattleEvents
Provides battle event publication and event-bound task scheduling.

This interface allows battle code to publish BattleEvents and to register tasks that should run when a specific battle event type is next observed. These hooks are useful for sequencing battle logic around events without forcing the caller to manually poll for state changes.

One-shot tasks are removed after they run. Persistent tasks remain registered and run each time the matching event is published.

  • Method Details

    • addFunctionAtEvent

      <E extends BattleEvent, A> CompletableFuture<A> addFunctionAtEvent(Class<E> eventClass, BiFunction<E,BattleController,A> task)
      Adds a one-shot function to run the next time the specified event type is published.

      The returned future is completed with the function result after the task has executed. Once executed, the task is removed and will not run for later events of the same type.

      Type Parameters:
      E - the battle event type
      A - the function result type
      Parameters:
      eventClass - the event type to wait for
      task - the function to execute when the event is published
      Returns:
      a future completed with the function result when the task runs
    • addTaskAtEvent

      <E extends BattleEvent> CompletableFuture<Void> addTaskAtEvent(Class<E> eventClass, BiConsumer<E,BattleController> task)
      Adds a one-shot task to run the next time the specified event type is published.

      The returned future is completed after the task has executed. Once executed, the task is removed and will not run for later events of the same type.

      Type Parameters:
      E - the battle event type
      Parameters:
      eventClass - the event type to wait for
      task - the task to execute when the event is published
      Returns:
      a future completed when the task has run
    • addPersistentTaskAtEvent

      <E extends BattleEvent> void addPersistentTaskAtEvent(Class<E> eventClass, BiConsumer<E,BattleController> task)
      Adds a persistent task to run every time the specified event type is published.

      Persistent tasks are not removed after execution and do not expose a future, because they may run multiple times over the lifetime of the battle.

      Type Parameters:
      E - the battle event type
      Parameters:
      eventClass - the event type to listen for
      task - the task to execute each time the event is published
    • publishEvent

      <T extends BattleEvent> T publishEvent(T event)
      Publishes a battle event.

      Publishing an event should run any one-shot or persistent tasks waiting for that event type, and should also pass the event through the normal Pixelmon event pipeline where applicable. The returned event may have been modified by listeners.

      Type Parameters:
      T - the battle event type
      Parameters:
      event - the event to publish
      Returns:
      the published event, potentially modified by listeners