Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

← Back to Patterns
util

API Gotchas

Common API mistakes and their corrections. Read this before writing Hytale plugins!

Example Code

java
// ❌ WRONG: Message.append() does not exist
Message.raw("Hello").append(Message.raw(" World"));

// ✅ CORRECT: Use Message.join()
Message.join(Message.raw("Hello"), Message.raw(" World"));


// ❌ WRONG: Color.AQUA does not exist
Message.raw("text").color(Color.AQUA);

// ✅ CORRECT: Use Color.CYAN
Message.raw("text").color(Color.CYAN);


// ❌ WRONG: PlayerChatEvent.getPlayer()
public void onChat(PlayerChatEvent event) {
    Player p = event.getPlayer();  // Does not exist!
}

// ✅ CORRECT: Use getSender() which returns PlayerRef
public void onChat(PlayerChatEvent event) {
    PlayerRef sender = event.getSender();
    sender.sendMessage(...);
}


// ❌ WRONG: Teleport.createForPlayer() may not exist
Teleport.createForPlayer(world, pos, rot);

// ✅ CORRECT: Use constructor directly
new Teleport(world, position, rotation);


// ❌ WRONG: Modifying MovementSettings without syncing
settings.canFly = true;
// Player still cant fly!

// ✅ CORRECT: Must call update() to sync to client
settings.canFly = true;
movementManager.update(playerRef.getPacketHandler());

// ❌ WRONG: setPosition for teleport
transform.setPosition(new Vector3d(x, y, z));
// May not sync properly!

// ✅ CORRECT: teleportPosition for teleport
transform.teleportPosition(new Vector3d(x, y, z));

Thread Safety

N/A

Common Mistakes

All the mistakes listed in the code example are common pitfalls found in documentation that does not match the actual API.