#Ban Command
1 messages · Page 1 of 1 (latest)
Thanks for asking your question!
Once you have finished, please close your thread.
Use the /close command or button below.
Yes, just add a tag to the player and check every player to make sure they don't have that tag and if they do kick them.
Yuh I think they meant scripting command
yea, thats why i put as tag scripting, not ingame command blocks, i wanna make a Chat Command like !ban playername
?
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!');
}
});
});
you can't kick @s only names
thats also wroung
world.getAllPlayers().forEach(
import { world } from '@minecraft/server';
world.events.tick.subscribe(() => {
[...world.getPlayers({ tags: ['ban'] })].forEach((player) => {
player.runCommandAsync(`kick "${player.name}" You are banned!`).catch(error => console.warn(error, error.stack));
});
});```
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
👍
if it dont work lemme know
its fine
Add braces to the switch like case ”help”: {
}