#Ban Command

1 messages · Page 1 of 1 (latest)

rigid pond
#

Is it possible to make a ban command as a custom chat command?

dapper ruinBOT
#
Thanks for asking your question!

Once you have finished, please close your thread.

coral mist
supple pasture
#

Yuh I think they meant scripting command

rigid pond
#

yea, thats why i put as tag scripting, not ingame command blocks, i wanna make a Chat Command like !ban playername

coral mist
#

?

#

and just use ```
world.events.tick.subscribe((eventData) => {
const allPlayers = world.getPlayers();
allPlayers.forEach((player) => {
if (player.hasTag('ban')) {
player.runCommandAsync('kick @s You are banned!');
}
});
});

rigid pond
#

ok

#

thanks

past junco
#

thats also wroung

#

world.getAllPlayers().forEach(

past junco
#
import { world, Location } from '@minecraft/server';
import parseCommand from './command_parser.js';
const overworld = world.getDimension(`overworld`);
const prefix = '-';
let unbanWindows = [];
world.events.tick.subscribe(() => {
    [...world.getPlayers({ tags: ['ban'] })].forEach((player) => {
        const {name} = player
        if (unbanWindows.includes(name)) return unbanWindows = unbanWindows.filter(name => name !== playerName), player.removeTag('ban')
        player.runCommandAsync(`kick "${player.name}" You are banned!`).catch(error => console.warn(error, error.stack));
    });
});```
#
world.event.beforeChat.subscribe((eventData) => {
    const { sender, message } = eventData;
    const { rotation: { x: rx, y: ry } } = sender;

    if (!message.startsWith(prefix)) return;
    if (!sender.hasTag('staff')) return sender.tell('You do not have permision to use this command!')
    eventData.sendToTargets = true;
    eventData.targets = [];

    const args = parseCommand(message, prefix);
    const command = args.shift();

    switch (command) {
        case 'hub':
            sender.teleport(new Location(0, 100, 0), overworld, rx, ry);
            break;
         
        case 'ban': 
            const [playerName] = args;
            const player = [...world.getPlayers({name: playerName})][0];
            if (!player) return sender.tell(`player: ${playerName}, does not exist!`);
            sender.tell(`You banned ${player.name}`);
            player.addTag('ban')
            break;
        case 'unban': 
            const [subcommand, playerName] = args;
            switch (subcommand) {
                case 'add': {
                    
                    if (unbannWindows.includes(playerName)) return sender.tell(`You already opened an unban window for $playerName}!`);
                    unbanWindows.push(playerName);
                    return sender.tell(`You opened an unban window for $playerName}!`);
                } case 'remove': {
                    
                    if (!unbannWindows.includes(playerName)) return sender.tell(`You have not opened an unban window for $playerName}!`);
                    unbanWindows = unbanWindows.filter(name => name !== playerName);
                    return sender.tell(`You opened an unban window for $playerName}!`);
                }
            }
            break;
            
    }
});```
https://cdn.discordapp.com/attachments/854033525546942464/1062778717669175326/command_parser.js
#

@rigid pond

rigid pond
#

👍

past junco
#

if it dont work lemme know

rigid pond
#

yea

#

im in a rocket league tourny

#

so gonna have to wait

past junco
#

its fine

rigid pond
#

@past junco

past junco
# rigid pond

Add braces to the switch like case ”help”: {

}