import { world, system, ItemUseOnAfterEvent } from "@minecraft/server"; import { ModalFormData } from "@minecraft/server-ui";
const BAN_ITEM_ID = "c:menu";
function getOnlinePlayerNames(): string[] { const playerNames: string[] = []; for (const player of world.getPlayers()) { playerNames.push(player.name); } return playerNames; }
function openBanUI(player) { const form = new ModalFormData() .title("Забанить игрока") .dropdown("Выберите игрока", getOnlinePlayerNames(), 0);
form.button("Бан");
form.show(player).then(response => { if (response.isCanceled) return;
const selectedPlayerIndex = response.formValues[0]; const selectedPlayerName = getOnlinePlayerNames()[selectedPlayerIndex]; if (selectedPlayerName) { try { system.runCommand(tag add "${selectedPlayerName}" ban); player.sendMessage(§aИгрок ${selectedPlayerName} был забанен.); } catch (error) { player.sendMessage(§cОшибка при бане: ${error}); } } else { player.sendMessage(§cОшибка: Не удалось получить имя игрока); } }); }
import { ModalFormData } from "@minecraft/server-ui";
const BAN_ITEM_ID = "c:menu";
function getOnlinePlayerNames(): string[] {
const playerNames: string[] = [];
for (const player of world.getPlayers()) {
playerNames.push(player.name);
}
return playerNames;
}
function openBanUI(player) {
const form = new ModalFormData()
.title("Забанить игрока")
.dropdown("Выберите игрока", getOnlinePlayerNames(), 0);
form.button("Бан");
form.show(player).then(response => {
if (response.isCanceled) return;
const selectedPlayerIndex = response.formValues[0];
const selectedPlayerName = getOnlinePlayerNames()[selectedPlayerIndex];
if (selectedPlayerName) {
try {
system.runCommand(tag add "${selectedPlayerName}" ban);
player.sendMessage(§aИгрок ${selectedPlayerName} был забанен.);
} catch (error) {
player.sendMessage(§cОшибка при бане: ${error});
}
} else {
player.sendMessage(§cОшибка: Не удалось получить имя игрока);
}
});
}
world.afterEvents.itemUseOn.subscribe((event: ItemUseOnAfterEvent) => {
const { itemStack, source } = event;
if (itemStack.typeId === BAN_ITEM_ID && source.isPlayer()) {
openBanUI(source);
}
});