94 lines
2.5 KiB
Markdown
94 lines
2.5 KiB
Markdown
---
|
|
title: Univers & Mondes
|
|
type: docs
|
|
weight: 1
|
|
---
|
|
|
|
## Universe
|
|
|
|
L'Universe est un singleton gérant tous les mondes :
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.universe.Universe;
|
|
import com.hypixel.hytale.server.core.universe.world.World;
|
|
import java.util.Map;
|
|
|
|
Universe universe = Universe.get();
|
|
|
|
// Obtenir un monde spécifique
|
|
World world = universe.getWorld("default");
|
|
|
|
// Obtenir tous les mondes
|
|
Map<String, World> worlds = universe.getWorlds();
|
|
|
|
// Vérifier si un monde existe (hasWorld n'existe pas - utiliser null check)
|
|
if (universe.getWorld("creative") != null) {
|
|
// Le monde existe
|
|
}
|
|
```
|
|
|
|
## World
|
|
|
|
Chaque monde contient des chunks, entités et joueurs :
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.entity.entities.Player;
|
|
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
|
|
World world = Universe.get().getWorld("default");
|
|
|
|
// Obtenir le nom du monde
|
|
String name = world.getName();
|
|
|
|
// Obtenir tous les joueurs (retourne List<Player>)
|
|
List<Player> players = world.getPlayers();
|
|
|
|
// Obtenir les références de joueurs
|
|
Collection<PlayerRef> playerRefs = world.getPlayerRefs();
|
|
```
|
|
|
|
{{< callout type="warning" >}}
|
|
**Note :** `world.getEntities()` n'existe pas sur World. Les entités sont gérées via le système de composants EntityStore.
|
|
{{< /callout >}}
|
|
|
|
## Opérations sur le Monde
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
|
import com.hypixel.hytale.math.vector.Vector3i;
|
|
|
|
// Obtenir un bloc à une position
|
|
BlockType blockType = world.getBlockType(x, y, z);
|
|
BlockType blockType = world.getBlockType(new Vector3i(x, y, z));
|
|
|
|
// Définir un bloc (prend une clé String, pas un BlockType)
|
|
world.setBlock(x, y, z, "stone");
|
|
|
|
// Si vous avez un BlockType, utilisez getId()
|
|
if (blockType != null) {
|
|
world.setBlock(x, y, z, blockType.getId());
|
|
}
|
|
```
|
|
|
|
{{< callout type="info" >}}
|
|
**Note :** `world.getSpawnPoint()` n'existe pas directement sur World. La configuration du spawn est accessible via `world.getWorldConfig().getSpawnProvider()`.
|
|
{{< /callout >}}
|
|
|
|
## World depuis les Événements Player
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.event.events.player.PlayerConnectEvent;
|
|
import java.util.logging.Level;
|
|
|
|
getEventRegistry().register(PlayerConnectEvent.class, event -> {
|
|
PlayerRef playerRef = event.getPlayerRef();
|
|
World world = event.getWorld(); // Peut être null !
|
|
|
|
if (world != null) {
|
|
getLogger().at(Level.INFO).log("Joueur a rejoint le monde : " + world.getName());
|
|
}
|
|
});
|
|
```
|