Class GlobalWorldEventManager

java.lang.Object
com.hypixel.hytale.builtin.adventure.worldevents.GlobalWorldEventManager

@ThreadSafe public final class GlobalWorldEventManager extends Object
Tracks the active global world-events and runs their start and stop tasks.

The manager is the persisted universe resource. The universe resource system loads it once at universe start, flushes it on a fixed cadence and at shutdown, and serializes the writes for the file. The codec and the universe can create extra instances, so the constructor has no side effects. The plugin starts the task runner on the loaded instance.

  • Field Details

  • Constructor Details

    • GlobalWorldEventManager

      public GlobalWorldEventManager()
  • Method Details

    • clear

      public void clear()
      Removes every active global world-event id and drops the queued start and stop tasks.

      The caller must stop the running events itself. This method only clears the manager.

      runTasks() drains and runs the task queue under the same lock. This call and a task run cannot interleave. Either the queue is wiped before a task is drained, or the drained tasks run to completion first. A reset cannot race a mid-drain task and leave a global event running in worlds it just reset.

    • add

      public boolean add(@Nonnull UUID eventId)
    • contains

      public boolean contains(@Nonnull UUID eventId)
    • activeCount

      public int activeCount()
      Returns:
      the number of active ids, without the copy that activeIds() makes
    • activeIds

      @Nonnull public UUID[] activeIds()
      Returns:
      a sorted snapshot of the active global world-event ids
    • remove

      public boolean remove(@Nonnull UUID eventId)
    • start

      public void start(@Nonnull Store<EntityStore> store, @Nonnull WorldEventRecord[] events)
    • flush

      public void flush()
      Writes the active ids now.

      The universe resource system also flushes on a fixed cadence and at shutdown. It serializes the writes for the file, so overlapping flushes cannot race on the temporary file.

    • startup

      public void startup()
    • shutdown

      public void shutdown()
    • get

      @Nonnull public static GlobalWorldEventManager get()
    • startEvent

      public static boolean startEvent(@Nonnull UUID eventId)
    • stopEvent

      public static boolean stopEvent(@Nonnull UUID eventId)
    • scheduleStartEventInAllWorlds

      public static void scheduleStartEventInAllWorlds(@Nonnull UUID eventId)
    • scheduleRestartEventInAllWorlds

      public static void scheduleRestartEventInAllWorlds(@Nonnull UUID eventId)
      Stops the event in every world, then starts it again.

      scheduleStartEventInAllWorlds(UUID) alone cannot restart a running event, because EventStartAction.startEvent(ComponentAccessor, WorldEventRecord) refuses an id that the world already runs. Both halves run in one task, so each world receives the stop before the start. The removal that the stop queues is applied before the start task runs, so the start then sees a free id.