Class World

java.lang.Object
com.hypixel.hytale.server.core.util.thread.TickingThread
com.hypixel.hytale.server.core.universe.world.World
All Implemented Interfaces:
ExecutorMetricsRegistry.ExecutorMetric, IMessageReceiver, Runnable, Executor

Represents a world instance in the universe.
  • Field Details

  • Constructor Details

    • World

      public World(@Nonnull String name, @Nonnull Path savePath, @Nonnull WorldConfig worldConfig)
      Default Constructor for a World instance.
      Parameters:
      name - The name given to the world.
      savePath - The save location for this world.
      worldConfig - The WorldConfig of this world.
  • Method Details

    • init

      @Nonnull public CompletableFuture<World> init()
      Called to start initializing the world.

      Returns a future that completes when the world is joinable.

      Returns:
      the world instance once initialized.
    • stopIndividualWorld

      public void stopIndividualWorld()
      Called to stop and remove this individual world from the universe.
    • stopIndividualWorld

      public void stopIndividualWorld(Map<UUID, PlayerRef> players)
    • validateDeleteOnRemove

      public void validateDeleteOnRemove()
    • setTps

      public void setTps(int tps)
      Overrides:
      setTps in class TickingThread
    • setTimeDilation

      public static void setTimeDilation(float timeDilationModifier, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Set and update time dilation for all connected Players in the world. This doesn't affect other worlds loaded on the server. WARNING: Setting this to a value other than 1 removes most client timeout to allow for very slow interactions to run eg: at 0.025 time dilation.
      Parameters:
      timeDilationModifier - The time dilation modifier to set (0.01 - 4).
      componentAccessor - The ComponentAccessor for component access.
    • getName

      @Nonnull public String getName()
      Returns:
      the name of this world.
    • isAlive

      public boolean isAlive()
      Returns:
      true if this world is alive, false otherwise.
    • getWorldConfig

      @Nonnull public WorldConfig getWorldConfig()
      Get the world config
      Returns:
      the world config
    • getDeathConfig

      @Nonnull public DeathConfig getDeathConfig()
      Returns:
      the DeathConfig for this world, checking for inline overrides first.
    • getGameModeTypeOnDeath

      @Nullable public String getGameModeTypeOnDeath()
      Returns:
      the gamemode type asset id entered on death, falling back to the server-wide default when this world's DeathConfig does not set one, or null for the normal respawn flow.
    • getDaytimeDurationSeconds

      public int getDaytimeDurationSeconds()
      Returns:
      the daytime duration in seconds for this world, checking for inline overrides first.
    • getNighttimeDurationSeconds

      public int getNighttimeDurationSeconds()
      Returns:
      the nighttime duration in seconds for this world, checking for inline overrides first.
    • isTicking

      public boolean isTicking()
      Returns:
      the save path for this world.
    • setTicking

      public void setTicking(boolean ticking)
      Called to set whether this world is ticking or not.
      Parameters:
      ticking - Whether the world should be ticking.
    • isPaused

      public boolean isPaused()
      Returns:
      true if this world is paused, false otherwise.
    • setPaused

      public void setPaused(boolean paused)
      Called to set whether this world is paused or not.
      Parameters:
      paused - Whether the world should be paused.
    • getTick

      public long getTick()
      Returns:
      The tick counter for this world
      See Also:
      • tick
    • getLogger

      @Nonnull public HytaleLogger getLogger()
      Returns:
      the logger instance for this world.
    • isCompassUpdating

      public boolean isCompassUpdating()
    • setCompassUpdating

      public void setCompassUpdating(boolean compassUpdating)
    • getPlayers

      @Deprecated(forRemoval=true) public List<Player> getPlayers()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getEntity

      @Nullable @Deprecated public Entity getEntity(@Nonnull UUID uuid)
      Deprecated.
    • getEntityRef

      @Nullable public Ref<EntityStore> getEntityRef(@Nonnull UUID uuid)
    • getPlayerCount

      public int getPlayerCount()
    • getNonSpectatorPlayerCount

      public int getNonSpectatorPlayerCount()
      The number of players in this world that are not spectating, for lifecycle decisions that should not let a spectator hold a world open. Players whose entity is not resolvable are counted as present.
      Returns:
      the number of non-spectating players in this world.
    • getPlayerRefs

      @Nonnull public Collection<PlayerRef> getPlayerRefs()
      Note: The returned collection may hold PlayerRefs with invalid/null Refs.
      Returns:
      a collection of PlayerRef instances tracked in this world.
    • trackPlayerRef

      public void trackPlayerRef(@Nonnull PlayerRef playerRef)
      Called to track the given player ref as part of this world.
      Parameters:
      playerRef - The PlayerRef of the player to track.
    • untrackPlayerRef

      public void untrackPlayerRef(@Nonnull PlayerRef playerRef)
      Called to untrack the given player ref as part of this world.
      Parameters:
      playerRef - The PlayerRef of the player to untrack.
    • spawnEntity

      @Deprecated @Nullable public <T extends Entity> T spawnEntity(T entity, @Nonnull org.joml.Vector3d position, Rotation3f rotation)
      Deprecated.
    • addEntity

      @Deprecated @Nullable public <T extends Entity> T addEntity(T entity, @Nonnull org.joml.Vector3d position, @Nullable Rotation3f rotation, @Nonnull AddReason reason)
      Deprecated.
    • sendMessage

      public void sendMessage(@Nonnull Message message)
      Description copied from interface: IMessageReceiver
      Called to send a message to this receiver.
      Specified by:
      sendMessage in interface IMessageReceiver
      Parameters:
      message - The message to be sent.
    • execute

      public void execute(@Nonnull Runnable command)
      Specified by:
      execute in interface Executor
    • scheduleAfter

      public ScheduledFuture<?> scheduleAfter(@Nonnull Runnable task, long delay, @Nonnull TimeUnit unit)
      Schedules task to run on this world's thread after the given delay, timed off the shared server scheduler. Dropped if the world stops accepting tasks before the delay elapses. The returned future cancels the pending dispatch. Once the delay elapses and the task is handed to the world thread, cancelling the future has no effect.
    • consumeTaskQueue

      public void consumeTaskQueue()
    • getChunkStore

      @Nonnull public ChunkStore getChunkStore()
      Returns:
      the ChunkStore affiliated with this world.
    • getEntityStore

      @Nonnull public EntityStore getEntityStore()
      Returns:
      the EntityStore affiliated with this world.
    • getChunkLighting

      @Nonnull public ChunkLightingManager getChunkLighting()
      Returns:
      the ChunkLightingManager affiliated with this world.
    • getWorldMapManager

      @Nonnull public WorldMapManager getWorldMapManager()
      Returns:
      the WorldMapTracker affiliated with this world.
    • getWorldPathConfig

      public WorldPathConfig getWorldPathConfig()
      Returns:
      the WorldPathConfig affiliated with this world.
    • getNotificationHandler

      @Nonnull public WorldNotificationHandler getNotificationHandler()
      Get the notification handler used to notify clients of changes to the world
      Returns:
      the notification handler
    • getEventRegistry

      @Nonnull public EventRegistry getEventRegistry()
      Returns:
      the EventRegistry affiliated with this world.
    • addPlayer

      @Nullable public CompletableFuture<PlayerRef> addPlayer(@Nonnull PlayerRef playerRef)
      Called to add the given player to this world.
      Parameters:
      playerRef - The PlayerRef component of the player to add.
      Returns:
      the future that completes with the player ref once added, or null if the player cannot be added.
    • addPlayer

      @Nullable public CompletableFuture<PlayerRef> addPlayer(@Nonnull PlayerRef playerRef, @Nullable Transform transform)
      Called to add the given player to this world.
      Parameters:
      playerRef - The PlayerRef component of the player to add.
      transform - The Transform to spawn the player at, or null to use the default spawn point.
      Returns:
      the future that completes with the player ref once added, or null if the player cannot be added.
    • addPlayer

      @Nullable public CompletableFuture<PlayerRef> addPlayer(@Nonnull PlayerRef playerRef, @Nullable Transform transform, @Nullable Boolean clearWorldOverride, @Nullable Boolean fadeInOutOverride)
      Called to add the given player to this world.
      Parameters:
      playerRef - The PlayerRef component of the player to add.
      transform - The Transform to spawn the player at, or null to use the default spawn point.
      clearWorldOverride - Whether to override clearing the world when the player joins.
      fadeInOutOverride - Whether to override fading in/out when the player joins.
      Returns:
      the future that completes with the player ref once added, or null if the player cannot be added.
    • resendGameplayConfig

      public void resendGameplayConfig()
    • drainPlayersTo

      @Nonnull public CompletableFuture<Void> drainPlayersTo(@Nonnull World fallbackTargetWorld, @Nonnull Collection<PlayerRef> players, @Nullable Message message, boolean isRemovalExceptional)
      Removes all players from this world and either sends them back to the location set in the event or sends them to the provided fallbackTargetWorld.
      Parameters:
      fallbackTargetWorld - The fallback target world.
      players - The players to drain.
      message - The default message sent to each drained player, which event listeners may replace or clear.
      isRemovalExceptional - Whether this world is shutting down because it crashed.
      Returns:
      A CompletableFuture for when all players have finished being added to their target world.
    • getGameplayConfig

      @Nonnull public GameplayConfig getGameplayConfig()
      Returns:
      the GameplayConfig instance of this world.
    • getFeatures

      @Nonnull public Map<ClientFeature, Boolean> getFeatures()
      Returns:
      an unmodifiable view of the client features map for this world.
    • isFeatureEnabled

      public boolean isFeatureEnabled(@Nonnull ClientFeature feature)
      Checks if a client feature is enabled for this world.
      Parameters:
      feature - the feature to check.
      Returns:
      true if the feature is enabled, false otherwise.
    • registerFeature

      public void registerFeature(@Nonnull ClientFeature feature, boolean enabled)
      Registers (enables or disables) a client feature for this world. This will broadcast the updated features to all players in this world.
      Parameters:
      feature - the feature to register.
      enabled - whether the feature is enabled.
    • broadcastFeatures

      public void broadcastFeatures()
      Broadcasts the current feature state to all players in this world.
    • getSavePath

      @Nonnull public Path getSavePath()
      Returns:
      the save path of this world.
    • updateEntitySeed

      public void updateEntitySeed(@Nonnull Store<EntityStore> store)
    • markGCHasRun

      public void markGCHasRun()
      Called to mark that a garbage collection has run in this world.
    • consumeGCHasRun

      public boolean consumeGCHasRun()
      Consume whether a garbage collection has run since the last time this method was called.
      Returns:
      true if a garbage collection has run since the last time this method was called, false otherwise.
    • isSavingLocked

      public boolean isSavingLocked()
      Whether saving of this world is prevented due to another process wanting to access the files manually. e.g. backups
    • lockSaving

      public void lockSaving()
      Increments the saving lock counter, preventing any saving systems from writing to disk.
    • unlockSaving

      public void unlockSaving()
      Decrements the saving lock counter, allowing saving to resume once all locks are released.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object