Contents
- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- get()
- registerResource(Class, String, BuilderCodec)
- runBackup()
- isSavingLocked()
- lockSaving()
- unlockSaving()
- getResource(UniverseResourceType)
- flushResource(UniverseResourceType)
- disconnectAllPLayers()
- shutdownAllWorlds()
- toMetricResults()
- getUniverseReady()
- getWorldMarkersResourceType()
- isWorldLoadable(String)
- addWorld(String)
- addWorld(String, String, String)
- validateWorldPath(String)
- makeWorld(String, Path, WorldConfig)
- makeWorld(String, Path, WorldConfig, boolean)
- loadWorld(String)
- getWorld(String)
- getWorld(UUID)
- getDefaultWorld()
- removeWorld(String)
- removeWorldExceptionally(String, Map)
- getPath()
- getWorldsPath()
- getWorldsDeletedPath()
- getWorlds()
- getPlayers()
- getPlayer(UUID)
- getPlayer(String, NameMatching)
- getPlayer(String, Comparator, BiPredicate)
- getPlayerByUsername(String, NameMatching)
- getPlayerByUsername(String, Comparator, BiPredicate)
- getPlayerCount()
- addPlayer(ChannelConnection, String, ProtocolVersion, PlayerAuthentication, int)
- removePlayer(PlayerRef)
- resetPlayer(PlayerRef)
- resetPlayer(PlayerRef, Holder)
- transferPlayerAsync(PlayerRef, World, CompletableFuture, Function)
- resetPlayer(PlayerRef, Holder, World, Transform)
- sendMessage(Message)
- broadcastPacket(ToClientPacket)
- broadcastPacketNoCache(ToClientPacket)
- broadcastPacket(ToClientPacket...)
- getStorageManager()
- getPlayerStorage()
- setPlayerStorage(PlayerStorage)
- getWorldConfigProvider()
- getPlayerRefComponentType()
- getLegacyBlockIdMap()
- getWorldGenPath()
Class Universe
java.lang.Object
com.hypixel.hytale.server.core.plugin.PluginBase
com.hypixel.hytale.server.core.plugin.JavaPlugin
com.hypixel.hytale.server.core.universe.Universe
- All Implemented Interfaces:
MetricProvider, CommandOwner, IMessageReceiver
A plugin that manages the universe of worlds and players on the server.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PluginManifestThe plugin manifest for theUniverseplugin.static final MetricsRegistry<Universe> The metrics registry for theUniverseclass. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddPlayer(ChannelConnection channel, String language, ProtocolVersion protocolVersion, PlayerAuthentication auth, int clientViewRadiusChunks) Called to add a new player to the universe.Creates a new world with the given name using the default world generation and chunk storage.Deprecated.Does not allow any control over the generator settingsvoidbroadcastPacket(ToClientPacket packet) Called to broadcast the given packet to all players in the universe.voidbroadcastPacket(ToClientPacket... packets) Called to broadcast the given packets to all players in the universe.voidbroadcastPacketNoCache(ToClientPacket packet) Called to broadcast the given packet to all players in the universe without caching it.voidCalled when theHytaleServerorUniverseis shutdown.flushResource(UniverseResourceType<?> type) Writes one universe resource to disk.static Universeget()Deprecated.getPath()getPlayer(String value, NameMatching matching) Called to fetch thePlayerRefcomponent of a specific player based on their display name.getPlayer(String value, Comparator<String> comparator, BiPredicate<String, String> equality) Called to fetch thePlayerRefcomponent of a specific player based on their display name.Called to fetch thePlayerRefcomponent of a specific player based on their UUID.getPlayerByUsername(String value, NameMatching matching) Called to fetch thePlayerRefcomponent of a specific player based on their username.getPlayerByUsername(String value, Comparator<String> comparator, BiPredicate<String, String> equality) Called to fetch thePlayerRefcomponent of a specific player based on their username.int<T> TgetResource(UniverseResourceType<T> type) Returns the shared instance of a universe resource.Called to fetch a specific world instance from the given name.Called to fetch a specific world instance from the given UUID.static PathbooleanWhether saving of universe-level data is prevented due to another process wanting to access the files manually. e.g. backupsbooleanisWorldLoadable(String name) Returns whether the world should be loadable.Loads a world that was previously created.voidIncrements the saving lock counter, preventing universe-level saving systems from writing to disk.makeWorld(String name, Path savePath, WorldConfig worldConfig) Creates or loads the world with the given name using the provided world configuration.makeWorld(String name, Path savePath, WorldConfig worldConfig, boolean start) static <T> UniverseResourceType<T> registerResource(Class<T> typeClass, String id, BuilderCodec<T> codec) Registers a universe-scoped persistent resource.voidremovePlayer(PlayerRef playerRef) Called to remove a player from the universe, via their player refbooleanremoveWorld(String name) Fires aRemoveWorldEvent, which, if not cancelled, allows the world to then be removed from this Universe.voidremoveWorldExceptionally(String name, Map<UUID, PlayerRef> players) Remove a world with the knowledge that this removal was caused by an exception causing the thread to crash.resetPlayer(PlayerRef oldPlayer) Called to fetch a completed future that will reset the given player.resetPlayer(PlayerRef oldPlayer, Holder<EntityStore> holder) Called to fetch a completed future that will reset the given player.resetPlayer(PlayerRef playerRef, Holder<EntityStore> holder, World world, Transform transform) Called to fetch a completed future that will reset the given player.Called to run a backup of the universe.voidsendMessage(Message message) Called to send a message to this receiver.voidsetPlayerStorage(PlayerStorage playerStorage) Called to set thePlayerStorageof this universe.voidCalled when theHytaleServerorUniverseis shutdown.static CompletableFuture<PlayerRef> transferPlayerAsync(PlayerRef playerRef, World originalWorld, CompletableFuture<World> targetWorld, Function<World, CompletableFuture<Transform>> spawnResolver) Transfers a player to a world that may still be loading.voidDecrements the saving lock counter, allowing saving to resume once all locks are released.validateWorldPath(String name) Methods inherited from class JavaPlugin
getClassLoader, getFile, getTypeMethods inherited from class PluginBase
getAssetRegistry, getBasePermission, getChunkStoreRegistry, getClientFeatureRegistry, getCodecRegistry, getCodecRegistry, getCodecRegistry, getCommandRegistry, getDataDirectory, getEntityRegistry, getEntityStoreRegistry, getEventRegistry, getIdentifier, getLogger, getManifest, getName, getState, getTaskRegistry, isDisabled, isEnabled, preLoad
-
Field Details
-
Constructor Details
-
Universe
Default Constructor for aUniverseinstance.- Parameters:
init- The plugin initialization step for this plugin.
-
-
Method Details
-
get
-
registerResource
@Nonnull public static <T> UniverseResourceType<T> registerResource(@Nonnull Class<T> typeClass, @Nonnull String id, @Nonnull BuilderCodec<T> codec) Registers a universe-scoped persistent resource. Call during plugin setup, before the universe starts.- Type Parameters:
T- The resource type.- Parameters:
typeClass- The class of the resource.id- The unique id of the resource, also its file name on disk.codec- The codec that persists the resource. Its default value seeds a new universe.- Returns:
- the token to read and flush the resource with.
-
runBackup
Called to run a backup of the universe.- Returns:
- a future that will complete when the backup is done.
-
isSavingLocked
public boolean isSavingLocked()Whether saving of universe-level data 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 universe-level saving systems from writing to disk. -
unlockSaving
public void unlockSaving()Decrements the saving lock counter, allowing saving to resume once all locks are released. -
getResource
Returns the shared instance of a universe resource. Any world thread may call this; the resource owns its own thread-safety.- Type Parameters:
T- The resource type.- Parameters:
type- The resource type token.- Returns:
- the loaded resource, never null.
-
flushResource
Writes one universe resource to disk. A write requested while saving is locked (for example during a backup) is queued and runs when the lock releases.- Parameters:
type- The resource type to write.- Returns:
- a future that completes when the bytes are on disk.
-
disconnectAllPLayers
public void disconnectAllPLayers()Called when theHytaleServerorUniverseis shutdown. Disconnects all connected players. -
shutdownAllWorlds
public void shutdownAllWorlds()Called when theHytaleServerorUniverseis shutdown. Stops and removes all worlds. -
toMetricResults
- Specified by:
toMetricResultsin interfaceMetricProvider
-
getUniverseReady
- Returns:
- a future that will complete when the universe is ready.
-
getWorldMarkersResourceType
- Returns:
- the resource type shared user world markers
-
isWorldLoadable
Returns whether the world should be loadable.This does not mean the world will successfully load as things like missing plugins could prevent it.
- Parameters:
name- The name of the world- Returns:
- whether the world should be loadable
-
addWorld
Creates a new world with the given name using the default world generation and chunk storage.- Parameters:
name- The name of the new world- Returns:
- A future that will resolve to the created world
-
addWorld
@Nonnull @Deprecated @CheckReturnValue public CompletableFuture<World> addWorld(@Nonnull String name, @Nullable String generatorType, @Nullable String chunkStorageType) Deprecated.Does not allow any control over the generator settingsCreates a new world with the given name using the provided world generator and chunk storage type.- Parameters:
name- The name of the new worldgeneratorType- The name of the generator to use or null.chunkStorageType- The name of the chunk storage to use or null.- Returns:
- A future that will resolve to the created world
-
validateWorldPath
-
makeWorld
@Nonnull @CheckReturnValue public CompletableFuture<World> makeWorld(@Nonnull String name, @Nonnull Path savePath, @Nonnull WorldConfig worldConfig) Creates or loads the world with the given name using the provided world configuration.- Parameters:
name- The name of the worldsavePath- The location to store the world folderworldConfig- The configuration to use for the world- Returns:
- A future that will resolve to the loaded/created world
-
makeWorld
@Nonnull @CheckReturnValue public CompletableFuture<World> makeWorld(@Nonnull String name, @Nonnull Path savePath, @Nonnull WorldConfig worldConfig, boolean start) -
loadWorld
Loads a world that was previously created.- Parameters:
name- The name of the world to load- Returns:
- A future that will resolve to the loaded world
-
getWorld
-
getWorld
-
getDefaultWorld
-
removeWorld
Fires aRemoveWorldEvent, which, if not cancelled, allows the world to then be removed from this Universe.- Parameters:
name- The name of the world.- Returns:
trueif the world was removed,falseif theRemoveWorldEventwas cancelled.- See Also:
-
removeWorldExceptionally
Remove a world with the knowledge that this removal was caused by an exception causing the thread to crash. This allows us to make sure we aren't attempting to call anything extra on the world, and that it might not be in a normal state.- Parameters:
name- The name of the world to remove.- See Also:
-
getPath
- Returns:
- the path to the universe directory.
-
getWorldsPath
- Returns:
- the path to the worlds folder within the universe directory.
-
getWorldsDeletedPath
- Returns:
- the path to (temporarily) deleted worlds, moved before they are completely erased from disk.
-
getWorlds
-
getPlayers
- Returns:
- a list of
PlayerRefcomponents for all connected players.
-
getPlayer
-
getPlayer
-
getPlayer
@Nullable public PlayerRef getPlayer(@Nonnull String value, @Nonnull Comparator<String> comparator, @Nonnull BiPredicate<String, String> equality) Called to fetch thePlayerRefcomponent of a specific player based on their display name.- Parameters:
value- The display name of the player to fetch.comparator- The comparator to use.equality- The equality predicate to use.- Returns:
- the
PlayerRefinstance, ornullif no player with the given name is connected.
-
getPlayerByUsername
@Nullable public PlayerRef getPlayerByUsername(@Nonnull String value, @Nonnull NameMatching matching) Called to fetch thePlayerRefcomponent of a specific player based on their username.- Parameters:
value- The username of the player to fetch.matching- The name matching strategy to use.- Returns:
- the
PlayerRefinstance, ornullif no player with the given username is connected.
-
getPlayerByUsername
@Nullable public PlayerRef getPlayerByUsername(@Nonnull String value, @Nonnull Comparator<String> comparator, @Nonnull BiPredicate<String, String> equality) Called to fetch thePlayerRefcomponent of a specific player based on their username.- Parameters:
value- The username of the player to fetch.comparator- The comparator to use.equality- The equality predicate to use.- Returns:
- the
PlayerRefinstance, ornullif no player with the given username is connected.
-
getPlayerCount
public int getPlayerCount()- Returns:
- the count of connected players.
-
addPlayer
@Nonnull public CompletableFuture<PlayerRef> addPlayer(@Nonnull ChannelConnection channel, @Nonnull String language, @Nonnull ProtocolVersion protocolVersion, @Nonnull PlayerAuthentication auth, int clientViewRadiusChunks) Called to add a new player to the universe.- Parameters:
channel- The channel of the client connecting.language- The language of the client.protocolVersion- The protocol version of the client.auth- ThePlayerAuthenticationdata for the player.clientViewRadiusChunks- The view radius of the client in chunks.- Returns:
- a future that will complete with the
PlayerRefof the added player.
-
removePlayer
-
resetPlayer
Called to fetch a completed future that will reset the given player. -
resetPlayer
@Nonnull public CompletableFuture<PlayerRef> resetPlayer(@Nonnull PlayerRef oldPlayer, @Nonnull Holder<EntityStore> holder) Called to fetch a completed future that will reset the given player.- Parameters:
oldPlayer- The oldPlayerRefcomponent of the player to reset.holder- TheEntityStoreholder to use for the new player.- Returns:
- a future that will complete with the new
PlayerRefof the reset player.
-
transferPlayerAsync
@Nonnull public static CompletableFuture<PlayerRef> transferPlayerAsync(@Nonnull PlayerRef playerRef, @Nonnull World originalWorld, @Nonnull CompletableFuture<World> targetWorld, @Nonnull Function<World, CompletableFuture<Transform>> spawnResolver) Transfers a player to a world that may still be loading.Removes the player from
originalWorldasynchronously, waits up to 30 seconds fortargetWorldto complete, then places the player at the transform returned byspawnResolver. AspawnResolverthat completes withnulluses the world's default spawn point.The returned future completes with the player's new
PlayerRefon success, or exceptionally if the target world times out or the player cannot be added. Callers must attach aCompletableFuture.whenComplete(BiConsumer)handler to implement fallback behaviour (e.g. returning the player tooriginalWorld, sending them to the default world, or disconnecting them).- Parameters:
playerRef- The player to transfer.originalWorld- The world the player is currently in; used as the async executor for removal.targetWorld- A future resolving to the destination world.spawnResolver- Resolves the spawn transform given the destination world; may complete withnull.- Returns:
- a future completing with the
PlayerRefon success, or exceptionally on failure.
-
resetPlayer
@Nonnull public CompletableFuture<PlayerRef> resetPlayer(@Nonnull PlayerRef playerRef, @Nonnull Holder<EntityStore> holder, @Nullable World world, @Nullable Transform transform) Called to fetch a completed future that will reset the given player.- Parameters:
playerRef- The oldPlayerRefcomponent of the player to reset.holder- TheEntityStoreholder to use for the new player.world- The world to move the player to, or null to use their current world.transform- The transform to move the player to, or null to use their current position.- Returns:
- a future that will complete with the new
PlayerRefof the reset player.
-
sendMessage
Description copied from interface:IMessageReceiverCalled to send a message to this receiver.- Specified by:
sendMessagein interfaceIMessageReceiver- Parameters:
message- The message to be sent.
-
broadcastPacket
Called to broadcast the given packet to all players in the universe.- Parameters:
packet- The packet to broadcast.
-
broadcastPacketNoCache
Called to broadcast the given packet to all players in the universe without caching it.- Parameters:
packet- The packet to broadcast.
-
broadcastPacket
Called to broadcast the given packets to all players in the universe.- Parameters:
packets- The array of packets to broadcast.
-
getStorageManager
-
getPlayerStorage
- Returns:
- the
PlayerStorageof this universe.
-
setPlayerStorage
Called to set thePlayerStorageof this universe.- Parameters:
playerStorage- The player storage to set.
-
getWorldConfigProvider
- Returns:
- the
WorldConfigProviderof this universe.
-
getPlayerRefComponentType
- Returns:
- the component type for the
PlayerRefcomponent.
-
getLegacyBlockIdMap
Deprecated. -
getWorldGenPath
-