import { Player, world } from "@minecraft/server";

/**
 * Lifesteal config, change the staffTag and prefix
 */
export const config = {
    prefix: '?',
    staffTag: 'lifesteal-opped'
};


/**
 * Send a message to a player
 * @param player Player to send the message to
 * @param message Message the player will be sent
 * @param removeSpaces Whether to remove repeated spaces
 */
export function sendPlayerMessage(player: Player, message: string, removeSpaces: boolean = false) {
    if (removeSpaces) {
        player.sendMessage(`${message.replaceAll(/(\r\n|\r|\n)/g, `\n`).replaceAll(/  +/g, ``)}`);
    }
    else {
        player.sendMessage(`${message}`);
    }
}

/**
 * Send every player a message
 * @param player Player that will send the message
 * @param message Message that will be sent
 * @param removeSpaces Whether to remove repeated spaces
 */
export function sendAllMessage(message: string, removeSpaces: boolean = false) {
    if (removeSpaces) {
        for (let player of world.getAllPlayers()) {
            player.sendMessage(`${message.replaceAll(/(\r\n|\r|\n)/g, `\n`).replaceAll(/  +/g, ``)}`);
        }
    }
    else {
        for (let player of world.getAllPlayers()) {
            player.sendMessage(`${message}`);
        }
    }
}