Skip to content

Commit

Permalink
added [money] placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
vytdev committed Jun 18, 2024
1 parent 625916d commit d81db4c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/server/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
events,
config,
removeFormatCodes,
formatNumber,
message,
broadcast,
} from "../catalyst/index.js";
import { getClientById } from "./client.js";
import { isPlayerAdmin } from "./utils.js";
import profanity from "./profanity.js";

Expand All @@ -21,25 +23,28 @@ events.on("beforeChatSend", ev => {
// cancel broadcast
ev.cancel = true;

// the client class of the sender
const plr = getClientById(ev.sender.id);

if (!isChatEnabled && !isPlayerAdmin(ev.sender)) {
broadcast('§echat is currently disabled!§r', ev.sender);
plr.msg('§echat is currently disabled!§r');
return;
}

let msg: string = '§¶';
if (isPlayerAdmin(ev.sender))
if (plr.msg)
msg += '§7[§cadmin§7]§r ';
msg += '§7' + ev.sender.name + "§r: ";
msg += '§7' + plr.name + "§r: ";

// the actual message, masked profanity, removed format codes
msg += removeFormatCodes(clean(ev.message));

// [pos] placeholder
msg = msg.replace(/\[pos\]/g, "§bWorld:§r" +
" " + ev.sender.dimension.id.replace("minecraft:", "") +
" §eX:§r" + Math.floor(ev.sender.location.x) +
" §eY:§r" + Math.floor(ev.sender.location.y) +
" §eZ:§r" + Math.floor(ev.sender.location.z));
" §eX:§r" + Math.floor(plr.loc.x) +
" §eY:§r" + Math.floor(plr.loc.y) +
" §eZ:§r" + Math.floor(plr.loc.z));

// get the player's current held item
const heldItem = ev.sender
Expand All @@ -48,13 +53,16 @@ events.on("beforeChatSend", ev => {
.getItem(ev.sender.selectedSlotIndex);

// item text to use for the item placeholder
let displayName = '§8[§6' + (heldItem?.typeId || 'minecraft:air');
let itemName = '§8[§6' + (heldItem?.typeId || 'minecraft:air');
if (heldItem?.amount > 1)
displayName += ' §r§bx' + heldItem.amount;
displayName += '§8]§r';
itemName += ' §r§bx' + heldItem.amount;
itemName += '§8]§r';

// [item] placeholder
msg = msg.replace(/\[i(?:tem)?\]/g, displayName);
msg = msg.replace(/\[i(?:tem)?\]/g, itemName);

// [money] placeholder
msg = msg.replace(/\[m(?:oney)?\]/g, '§a$' + formatNumber(plr.money) + '§r');

// [\ command ] placeholder
msg = msg.replace(new RegExp(`\\[\\${config.commandPrefix}([^\\]]+)\\]`, "g"),
Expand Down

0 comments on commit d81db4c

Please sign in to comment.