Global Functions
Global Functions
Section titled “Global Functions”Ceremony provides a set of globally available functions that you can call from anywhere in your scripts — no imports or namespace prefixes required. These cover the most common operations: sending messages, playing sounds, displaying titles, scheduling delays, and working with players.
msg(player, text)
Section titled “msg(player, text)”Sends a chat message to a player using MiniMessage formatting.
| Parameter | Type | Description |
|---|---|---|
player | any (ServerPlayer) | The target player to send the message to |
text | string | Message text in MiniMessage format |
// Simple colored messagemsg(player, '<green>Hello!');
// Styled text with gradientsmsg(player, '<gradient:gold:yellow>You earned 50 coins!</gradient>');
// Bold and italicmsg(player, '<bold><red>WARNING:</red></bold> <gray>The dungeon is closing in 60 seconds.');
// Hover and click eventsmsg(player, '<click:run_command:/spawn><hover:show_text:"Click to teleport"><underlined><aqua>Click here to return to spawn</aqua></underlined></hover></click>');actionbar(player, text)
Section titled “actionbar(player, text)”Sends an action bar message (the text that appears above the hotbar) using MiniMessage formatting.
| Parameter | Type | Description |
|---|---|---|
player | any (ServerPlayer) | The target player |
text | string | Action bar text in MiniMessage format |
// XP gain notificationactionbar(player, '<gold>+50 XP');
// Combat statusactionbar(player, '<red>HP: <white>14/20 <gray>| <green>Shield: <white>Active');
// Zone entryactionbar(player, '<gradient:green:dark_green>Entering Viridian Forest</gradient>');title(player, main, sub?, fadeIn?, stay?, fadeOut?)
Section titled “title(player, main, sub?, fadeIn?, stay?, fadeOut?)”Sends a title and optional subtitle to a player. Timing values are in ticks (20 ticks = 1 second).
| Parameter | Type | Default | Description |
|---|---|---|---|
player | any (ServerPlayer) | — | The target player |
main | string | — | Title text in MiniMessage format |
sub | string | '' | Subtitle text in MiniMessage format |
fadeIn | number | 10 | Fade-in duration in ticks |
stay | number | 70 | Stay duration in ticks |
fadeOut | number | 20 | Fade-out duration in ticks |
// Simple titletitle(player, '<gold>Victory!');
// Title with subtitletitle(player, '<gold>Victory', '<gray>Well played');
// Title with custom timing (fast appear, long stay, slow fade)title(player, '<gold>Victory', '<gray>Well played', 10, 70, 20);
// Countdown effectasync function showCountdown(player) { title(player, '<red>3', '', 0, 20, 5); await delay(20); title(player, '<yellow>2', '', 0, 20, 5); await delay(20); title(player, '<green>1', '', 0, 20, 5); await delay(20); title(player, '<bold><green>GO!', '<gray>Good luck!', 0, 40, 20);}
// Boss encountertitle(player, '<dark_red><bold>BOSS FIGHT', '<red>Defeat the Ender Dragon', 20, 60, 10);broadcast(text)
Section titled “broadcast(text)”Broadcasts a MiniMessage-formatted chat message to all online players.
| Parameter | Type | Description |
|---|---|---|
text | string | Message text in MiniMessage format |
// Server announcementbroadcast('<yellow>Server restarting in 5 minutes');
// Event announcementbroadcast('<gold><bold>EVENT:</bold> <yellow>A Legendary Pokemon has appeared in the Wild Area!');
// Player achievementbroadcast(`<gray>[<gold>Achievement<gray>] <white>${playerName} <gray>caught their first Shiny Pokemon!`);text(miniMessage)
Section titled “text(miniMessage)”Parses a MiniMessage string into a vanilla Minecraft Component object. This is useful when you need a Component for Java API calls rather than sending a message directly.
| Parameter | Type | Description |
|---|---|---|
miniMessage | string | Text in MiniMessage format |
Returns: Minecraft Component
// Create a Component for use with Java APIsconst comp = text('<red>Error');
// Use with entity custom namesconst nameTag = text('<gold><bold>Quest NPC');
// Use with inventory item display namesconst itemName = text('<light_purple>Legendary Sword');sound(player, soundName, volume?, pitch?)
Section titled “sound(player, soundName, volume?, pitch?)”Plays a sound effect for a specific player. Sound names use Minecraft’s dot-notation identifiers.
| Parameter | Type | Default | Description |
|---|---|---|---|
player | any (ServerPlayer) | — | The target player |
soundName | string | — | Minecraft sound identifier (dot notation) |
volume | number | 1.0 | Volume level (0.0 to 1.0+) |
pitch | number | 1.0 | Pitch multiplier (0.5 = low, 1.0 = normal, 2.0 = high) |
// Level up fanfaresound(player, 'entity.player.levelup', 0.5, 1.2);
// Error buzzersound(player, 'block.note_block.bass', 1.0, 0.5);
// Success chimesound(player, 'block.note_block.chime', 0.8, 1.5);
// Ambient cave soundsound(player, 'ambient.cave', 0.3, 1.0);
// Ender dragon roar for boss encounterssound(player, 'entity.ender_dragon.growl', 1.0, 0.8);
// Chest opening for reward revealssound(player, 'block.chest.open', 1.0, 1.0);delay(ticks)
Section titled “delay(ticks)”Returns a Promise that resolves after a specified number of game ticks. Use with await inside async functions to pause execution without blocking the server.
| Parameter | Type | Description |
|---|---|---|
ticks | number | Number of game ticks to wait (20 ticks = 1 second) |
Returns: Promise<void>
// Wait 1 secondawait delay(20);
// Wait 5 secondsawait delay(100);
// Practical example: reward ceremony with delaysasync function rewardCeremony(player) { msg(player, '<yellow>Opening reward chest...'); sound(player, 'block.chest.open', 1.0, 1.0); await delay(30); // 1.5 seconds
msg(player, '<gold>You received: <white>Diamond x5'); sound(player, 'entity.item.pickup', 1.0, 1.0); await delay(20); // 1 second
msg(player, '<gold>You received: <light_purple>Rare Candy x3'); sound(player, 'entity.item.pickup', 1.0, 1.2); await delay(20);
title(player, '<gold>Rewards Claimed!', '<gray>Check your inventory', 10, 40, 20); sound(player, 'entity.player.levelup', 0.8, 1.0);}setTimeout(callback, delayMs?)
Section titled “setTimeout(callback, delayMs?)”Schedules a callback function to run after a specified number of milliseconds. Unlike delay(), this is wall-clock time, not tick-based.
| Parameter | Type | Default | Description |
|---|---|---|---|
callback | function | — | Function to execute after the delay |
delayMs | number | 0 | Delay in milliseconds before executing the callback |
// Run after 3 seconds (wall-clock time)setTimeout(() => { msg(player, 'Delayed!');}, 3000);
// Run on next tick cycle (no delay)setTimeout(() => { broadcast('<green>Server initialized!');});
// Chain multiple timeouts for a timed sequencesetTimeout(() => msg(player, '<yellow>3...'), 0);setTimeout(() => msg(player, '<yellow>2...'), 1000);setTimeout(() => msg(player, '<yellow>1...'), 2000);setTimeout(() => msg(player, '<green>Go!'), 3000);wrapPlayer(player)
Section titled “wrapPlayer(player)”Wraps a vanilla ServerPlayer object into Ceremony’s rich Player interface, which provides convenient methods for messaging, teleportation, effects, and more.
| Parameter | Type | Description |
|---|---|---|
player | any (ServerPlayer) | A vanilla Minecraft ServerPlayer instance |
Returns: Player interface
// Wrap a player from an eventEvents.on('PlayerJoinEvent', (event) => { const p = wrapPlayer(event.getEntity()); p.sendMessage('<green>Welcome back!');});
// Access player propertiesconst p = wrapPlayer(serverPlayer);const name = p.getName();const uuid = p.getUUID();const pos = p.getPosition(); // { x, y, z }const health = p.getHealth();
// Player actionsp.sendMessage('<red>Watch out!');p.playSound('entity.player.levelup', 1.0, 1.0);p.sendTitle('<gold>Level Up!', '<gray>You are now level 10');p.teleport(100, 65, 200);p.heal(20);getPlayerData(player)
Section titled “getPlayerData(player)”Retrieves the persistent PlayerData key-value storage for a specific player. Data persists across sessions and server restarts.
| Parameter | Type | Description |
|---|---|---|
player | any (ServerPlayer) | The target player |
Returns: PlayerData interface
The PlayerData interface provides:
| Method | Description |
|---|---|
get(key) | Get a stored value by key. Returns string or null |
set(key, value) | Store a key-value pair. Both key and value are strings |
has(key) | Check if a key exists. Returns boolean |
remove(key) | Remove a stored key-value pair |
keys() | Get all stored keys. Returns string[] |
// Store and retrieve player statsconst data = getPlayerData(player);data.set('score', '100');data.set('kills', '25');data.set('last_login', Date.now().toString());
const score = parseInt(data.get('score') || '0');msg(player, `<yellow>Your score: <white>${score}`);
// Track daily login rewardsconst data = getPlayerData(player);const lastClaim = parseInt(data.get('last_daily_claim') || '0');const now = Date.now();const oneDayMs = 24 * 60 * 60 * 1000;
if (now - lastClaim >= oneDayMs) { data.set('last_daily_claim', now.toString()); const streak = parseInt(data.get('daily_streak') || '0') + 1; data.set('daily_streak', streak.toString()); msg(player, `<gold>Daily reward claimed! <gray>Streak: <white>${streak}`);} else { msg(player, '<red>You already claimed today\'s reward.');}Quick Reference
Section titled “Quick Reference”| Function | Purpose | Returns |
|---|---|---|
msg(player, text) | Send chat message | void |
actionbar(player, text) | Send action bar text | void |
title(player, main, sub?, fadeIn?, stay?, fadeOut?) | Show title/subtitle | void |
broadcast(text) | Message all players | void |
text(miniMessage) | Parse to Component | Component |
sound(player, soundName, volume?, pitch?) | Play sound effect | void |
delay(ticks) | Async tick delay | Promise<void> |
setTimeout(callback, delayMs?) | Schedule callback | void |
wrapPlayer(player) | Wrap ServerPlayer | Player |
getPlayerData(player) | Get persistent storage | PlayerData |
Related
Section titled “Related”- Game Namespace — Extended APIs for particles, combat, HUD, and more
- Scripting Introduction — Overview and setup guide
- Your First Script — Hands-on tutorial