Universe
Universe is a singleton that manages all worlds and players:
1import com.hypixel.hytale.server.core.universe.Universe;23Universe universe = Universe.get();45// Get all worlds6Map<String, World> worlds = universe.getWorlds();78// Get specific world by name9World world = universe.getWorld("default");1011// Get default world12World defaultWorld = universe.getDefaultWorld();1314// Get all players across all worlds15List allPlayers = universe.getPlayers(); 1617// Get player by UUID18PlayerRef player = universe.getPlayer(uuid);1920// Get player count21int count = universe.getPlayerCount();World
Basic Info
1World world = player.getWorld();23// World properties4String name = world.getName();5long tick = world.getTick();6boolean alive = world.isAlive();7boolean paused = world.isPaused();89// Players in this world10List<Player> players = world.getPlayers();11int playerCount = world.getPlayerCount();Thread-Safe Execution
1// Execute code on the world thread (REQUIRED for entity modifications)2world.execute(() -> {3 player.setModel("Mouse");4 // ... other entity modifications5});critical
All entity modifications MUST be wrapped in
world.execute(). See Threading Model.Spawning Entities
1World world = player.getWorld();23// Spawn position and rotation4Vector3d position = new Vector3d(100.0, 64.0, 100.0);5Vector3f rotation = new Vector3f(0f, 0f, 0f);67// Spawn entity (must be on world thread)8world.execute(() -> {9 Entity entity = world.spawnEntity(myEntity, position, rotation);10});Managing Worlds
1Universe universe = Universe.get();23// Add/load world (returns CompletableFuture)4CompletableFuture<World> future = universe.addWorld("myworld");5future.thenAccept(world -> {6 // World is ready7});89// Check if world can be loaded10boolean loadable = universe.isWorldLoadable("myworld");1112// Remove world13universe.removeWorld("myworld");Broadcasting
1Universe universe = Universe.get();23// Broadcast packet to ALL players on server4universe.broadcastPacket(myPacket);56// Broadcast to specific world only7World world = universe.getWorld("default");8for (Player p : world.getPlayers()) {9 p.getPlayerConnection().write(myPacket);10}World Events
Each world has its own EventRegistry:
1World world = universe.getWorld("default");2EventRegistry registry = world.getEventRegistry();34// Register world-specific events5registry.register(SomeEvent.class, event -> {6 // Only fires for this world7});Moving Players Between Worlds
1Universe universe = Universe.get();2World targetWorld = universe.getWorld("minigame");34// Add player to world (returns CompletableFuture)5PlayerRef playerRef = player.getPlayerRef();6CompletableFuture future = targetWorld.addPlayer(playerRef); 78// With specific spawn position9Transform spawn = new Transform(new Vector3d(0, 64, 0), ...);10targetWorld.addPlayer(playerRef, spawn);