lib/format.ts
1.4 KB · sha256:14015a4fb8afe3032635d607dc3d9dafe0d46849127feb3cc1347033a039039d
type Sendable = { sendMessage(component: any): void };
const TAG =
"<dark_gray>[<gradient:#9b87f5:#5b3df5>Ward</gradient>]</dark_gray>";
function render(template: string): any {
return rune.mm(template);
}
export function say(to: Sendable, body: string): void {
to.sendMessage(render(`${TAG} ${body}`));
}
export const ok = (to: Sendable, body: string) => say(to, `<green>${body}`);
export const info = (to: Sendable, body: string) => say(to, `<white>${body}`);
export const warn = (to: Sendable, body: string) => say(to, `<yellow>${body}`);
export const err = (to: Sendable, body: string) => say(to, `<red>${body}`);
/** Send a raw MiniMessage line WITHOUT the Ward tag (for info cards). */
export function raw(to: Sendable, body: string): void {
to.sendMessage(render(body));
}
/** Escape `<` so user-supplied text doesn't get parsed as MiniMessage. */
export function escapeMM(s: string): string {
return s.replace(/</g, "\\<");
}
/**
* Permission gate. Console always passes; players need `perm` (or op).
* Sends a red "you lack..." message + returns false when denied.
*/
export function requirePerm(ctx: CommandCtx, perm: string): boolean {
if (!ctx.sender.isPlayer) return true;
const player = ctx.sender as unknown as Player;
if (player.isOp() || player.hasPermission(perm)) return true;
err(ctx.sender, `you lack <white>${escapeMM(perm)}`);
return false;
}