Class PrefabEditSessionManager

java.lang.Object
com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditSessionManager

public class PrefabEditSessionManager extends Object
Manages all active Prefab Edit Sessions on the server
  • Field Details

    • NOON_TIME

      public static final float NOON_TIME
      The default time in a new edit session world.
      See Also:
    • DEFAULT_NEW_WORLD_ZERO_COORDINATE_BLOCK_NAME

      public static final String DEFAULT_NEW_WORLD_ZERO_COORDINATE_BLOCK_NAME
      A default block to place when creating a new prefab, helpful for void worlds.
      See Also:
    • DEFAULT_ENVIRONMENT

      public static final String DEFAULT_ENVIRONMENT
      The default weather for all prefab editor worlds.
      See Also:
    • DEFAULT_CHUNK_ENVIRONMENT

      public static final String DEFAULT_CHUNK_ENVIRONMENT
      The default chunk environment for all prefab editor worlds. This should be a grasslands-like environment to match the default weather.
      See Also:
    • PREFAB_EDITING_WORLD_NAME_PREFIX

      public static final String PREFAB_EDITING_WORLD_NAME_PREFIX
      The prefix for world folders for edit session worlds.
      See Also:
    • DEFAULT_TINT

      @Nonnull public static final Color DEFAULT_TINT
      The default tint of a world-- grass-greenish.
    • DEFAULT_GRASS_TINT_HEX

      public static final String DEFAULT_GRASS_TINT_HEX
      The default grass tint as a hex string.
      See Also:
  • Constructor Details

    • PrefabEditSessionManager

      public PrefabEditSessionManager(@Nonnull JavaPlugin plugin)
      Default Constructor for a PrefabEditSessionManager instance.
      Parameters:
      plugin - The JavaPlugin that this manager is associated with.
  • Method Details

    • onPlayerAddedToWorld

      public void onPlayerAddedToWorld(@Nonnull AddPlayerToWorldEvent event)
      When a player being teleported to the prefab editing world begins being added to world, we cannot get the world that they are being teleported to from the PlayerReadyEvent, so we need to store it in this event
      Parameters:
      event - The AddPlayerToWorldEvent that was called
    • updatePathOfLoadedPrefab

      public void updatePathOfLoadedPrefab(@Nonnull Path oldPath, @Nonnull Path newPath)
      Updates the stored prefab paths in the prefabsBeingEdited
      Parameters:
      oldPath - The old path of the loaded prefab.
      newPath - The new path of the loaded prefab.
    • isEditingAPrefab

      public boolean isEditingAPrefab(@Nonnull UUID playerUUID)
      Parameters:
      playerUUID - The UUID of a player
      Returns:
      true if the player is currently editing a prefab
    • getPrefabEditSession

      public PrefabEditSession getPrefabEditSession(@Nonnull UUID playerUUID)
      Retrieve the PrefabEditSession that the player is currently a part of
      Parameters:
      playerUUID - The UUID of the Player to fetch their edit session
      Returns:
      The PrefabEditSession that the player is in
    • getActiveEditSessions

      @Nonnull public Map<UUID, PrefabEditSession> getActiveEditSessions()
      Returns:
      all active prefab edit sessions, keyed by player UUID.
    • hasInProgressLoading

      public boolean hasInProgressLoading(@Nonnull UUID playerUuid)
      Checks if a player has an in-progress loading operation.
      Parameters:
      playerUuid - The UUID of the player.
      Returns:
      true if the player has an in-progress loading operation.
    • cancelLoading

      public void cancelLoading(@Nonnull UUID playerUuid)
      Marks a player's loading operation as cancelled. The loading chain will check this and abort early.
      Parameters:
      playerUuid - The UUID of the player.
    • isLoadingCancelled

      public boolean isLoadingCancelled(@Nonnull UUID playerUuid)
      Checks if a player's loading operation has been cancelled.
      Parameters:
      playerUuid - The UUID of the player.
      Returns:
      true if the loading was cancelled.
    • clearLoadingState

      public void clearLoadingState(@Nonnull UUID playerUuid)
      Clears the in-progress and cancelled loading state for a player. Should be called when loading completes (successfully or not) or after cleanup.
      Parameters:
      playerUuid - The UUID of the player.
    • createEditSessionForNewPrefab

      @Nonnull public CompletableFuture<Void> createEditSessionForNewPrefab(@Nonnull Ref<EntityStore> ref, @Nonnull Player editor, @Nonnull PrefabEditorCreationSettings settings, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Create an empty PrefabEditSession instance world where the player can build a new prefab
      Parameters:
      ref - The entity reference of the player entity.
      editor - The player who is editing the prefab.
      settings - The settings to use for creating the prefab edit session.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      A CompletableFuture that handles all the above tasks, or null if something went wrong
    • loadPrefabAndCreateEditSession

      @Nullable public CompletableFuture<Void> loadPrefabAndCreateEditSession(@Nonnull Ref<EntityStore> ref, @Nonnull Player editor, @Nonnull PrefabEditorCreationSettings settings, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Create a PrefabEditSession instance world, load the specified prefab(s), and teleport the provided player into it.
      Parameters:
      ref - The entity reference of the player entity.
      editor - The player who is editing the prefab.
      settings - The settings to use for creating the prefab edit session.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      A CompletableFuture that handles all the above tasks, or null if something went wrong
    • loadPrefabAndCreateEditSession

      @Nullable public CompletableFuture<Void> loadPrefabAndCreateEditSession(@Nonnull Ref<EntityStore> ref, @Nonnull Player editor, @Nonnull PrefabEditorCreationSettings settings, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nullable Consumer<PrefabLoadingState> progressCallback)
      Create a PrefabEditSession instance world, load the specified prefab(s), and teleport the provided player into it.
      Parameters:
      ref - The entity reference of the player entity.
      editor - The player who is editing the prefab.
      settings - The settings to use for creating the prefab edit session.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      progressCallback - Optional callback to receive progress updates.
      Returns:
      A CompletableFuture that handles all the above tasks, or null if something went wrong
    • isInEditWorld

      public boolean isInEditWorld(@Nonnull PlayerRef playerRef, @Nonnull Store<EntityStore> store)
    • sendToEditWorld

      @Nullable public CompletableFuture<Void> sendToEditWorld(@Nonnull Ref<EntityStore> ref, @Nonnull World world, @Nonnull PlayerRef playerRef)
    • exitEditSession

      @Nullable public CompletableFuture<Void> exitEditSession(@Nonnull Ref<EntityStore> ref, @Nonnull World world, @Nonnull PlayerRef playerRef, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Exits and ends a PrefabEditSession, unloading the world and teleporting you out.
      Parameters:
      ref - The entity reference of the instigating player entity.
      world - The world that the instigating player entity is in.
      playerRef - The PlayerRef component of the instigating player entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      a CompletableFuture handling the removal of the world, or null if something went wrong.
    • cleanupCancelledSession

      @Nonnull public CompletableFuture<Void> cleanupCancelledSession(@Nonnull UUID playerUuid, @Nonnull String worldName, @Nullable Consumer<PrefabLoadingState> progressCallback)
      Cleans up a cancelled loading session, removing the world and active session tracking. Called when the user cancels loading via the UI.

      This method runs asynchronously and provides progress updates via the callback.

      Parameters:
      playerUuid - The UUID of the player who cancelled.
      worldName - The name of the world that was being created.
      progressCallback - Optional callback to receive progress updates during shutdown.
      Returns:
      A CompletableFuture that completes when cleanup is finished.
    • cleanupCancelledSession

      @Nonnull public CompletableFuture<Void> cleanupCancelledSession(@Nonnull UUID playerUuid, @Nonnull String worldName)
      Cleans up a cancelled loading session without progress callbacks.
      Parameters:
      playerUuid - The UUID of the player who cancelled.
      worldName - The name of the world that was being created.
      Returns:
      A CompletableFuture that completes when cleanup is finished.