From 9b460227e4edd0792a98ee988f414210dab5c021 Mon Sep 17 00:00:00 2001 From: Blazer <51216880+BlaizerBrumo@users.noreply.github.com> Date: Wed, 13 Mar 2024 19:19:17 -0400 Subject: [PATCH] v1.8.5 updated how commands work hehe --- .../scripts/command/handle.js | 28 +++ .../scripts/command/importer.js | 15 ++ .../scripts/command/src/ban.js | 21 ++ .../scripts/command/src/clearchat.js | 8 + .../scripts/command/src/fakeleave.js | 8 + .../scripts/command/src/fakeleave_server.js | 8 + .../scripts/command/src/help.js | 10 + .../scripts/command/src/invsee.js | 15 ++ .../scripts/command/src/lagclear.js | 8 + .../scripts/command/src/mute.js | 22 ++ .../scripts/command/src/notify.js | 8 + .../scripts/command/src/summon_npc.js | 8 + .../scripts/command/src/unban.js | 10 + .../scripts/command/src/unmute.js | 22 ++ .../scripts/command/src/vanish.js | 8 + .../scripts/command/src/worldborder.js | 41 ++++ Safeguard anti-cheat B/scripts/config.js | 5 + Safeguard anti-cheat B/scripts/index.js | 199 ++---------------- 18 files changed, 264 insertions(+), 180 deletions(-) create mode 100644 Safeguard anti-cheat B/scripts/command/handle.js create mode 100644 Safeguard anti-cheat B/scripts/command/importer.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/ban.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/clearchat.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/fakeleave.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/fakeleave_server.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/help.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/invsee.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/lagclear.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/mute.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/notify.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/summon_npc.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/unban.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/unmute.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/vanish.js create mode 100644 Safeguard anti-cheat B/scripts/command/src/worldborder.js diff --git a/Safeguard anti-cheat B/scripts/command/handle.js b/Safeguard anti-cheat B/scripts/command/handle.js new file mode 100644 index 0000000..698a815 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/handle.js @@ -0,0 +1,28 @@ +import * as config from "../config"; + +let commands = {}; + +export function newCommand(obj){ + if(commands[obj.name]) return console.warn(`§4[ERROR] A command named "${obj.name}" already exists!`) + commands[obj.name] = obj; +} + +export function commandHandler(data){ + const prefix = config.default.chat.prefix; + const player = data.sender; + const message = data.message; + const args = message.substring(prefix.length).split(" "); + const cmdName = args[0]; + data.cancel = true; + + + if(!commands[cmdName]) return player.sendMessage(`§cUnknown command: §f${args[0]}`); + + let runData = { + args: args, + player: player, + message: message + } + + commands[cmdName].run(runData); +} \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/importer.js b/Safeguard anti-cheat B/scripts/command/importer.js new file mode 100644 index 0000000..ebdd604 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/importer.js @@ -0,0 +1,15 @@ +//import all commands +import "../command/src/help"; +import "../command/src/ban"; +import "../command/src/invsee"; +import "../command/src/mute"; +import "../command/src/unmute"; +import "../command/src/unban"; +import "../command/src/summon_npc"; +import "../command/src/vanish"; +import "../command/src/clearchat"; +import "../command/src/fakeleave"; +import "../command/src/fakeleave_server"; +import "../command/src/lagclear"; +import "../command/src/notify"; +import "../command/src/worldborder"; \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/ban.js b/Safeguard anti-cheat B/scripts/command/src/ban.js new file mode 100644 index 0000000..7746a15 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/ban.js @@ -0,0 +1,21 @@ +import { canFindPlayer, getPlayerByName } from '../../assets/util'; +import { newCommand } from '../handle'; + +newCommand({ + name:"ban", + run: (data) => { + let player = data.player; + const setNameBan = data.args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); + if (!canFindPlayer(setNameBan)) { + player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameBan}§f was not found`); + return; + } + if (getPlayerByName(setNameBan).hasTag("admin")) { + player.sendMessage(`§6[§eSafeGuard§6]§f Can't ban §e${setNameBan}§f, they're an admin.`); + return; + } + player.runCommandAsync('tag "' + setNameBan +'" add Ban'); + player.sendMessage(`§6[§eSafeGuard§6]§f Banned §e${setNameBan}`); + player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${player.name} §bbanned§l§5 ${setNameBan}! §r"}]}`); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/clearchat.js b/Safeguard anti-cheat B/scripts/command/src/clearchat.js new file mode 100644 index 0000000..103f628 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/clearchat.js @@ -0,0 +1,8 @@ +import { newCommand } from '../handle'; + +newCommand({ + name:"clearchat", + run: (data) => { + data.player.runCommandAsync("function admin_cmds/clearchat"); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/fakeleave.js b/Safeguard anti-cheat B/scripts/command/src/fakeleave.js new file mode 100644 index 0000000..36bfc89 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/fakeleave.js @@ -0,0 +1,8 @@ +import { newCommand } from '../handle'; + +newCommand({ + name:"fakeleave", + run: (data) => { + data.player.runCommandAsync("function admin_cmds/fake_leave"); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/fakeleave_server.js b/Safeguard anti-cheat B/scripts/command/src/fakeleave_server.js new file mode 100644 index 0000000..7c2c734 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/fakeleave_server.js @@ -0,0 +1,8 @@ +import { newCommand } from '../handle'; + +newCommand({ + name:"fakeleave_server", + run: (data) => { + data.player.runCommandAsync("function admin_cmds/fake_leave_server"); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/help.js b/Safeguard anti-cheat B/scripts/command/src/help.js new file mode 100644 index 0000000..c13af42 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/help.js @@ -0,0 +1,10 @@ +import { newCommand } from '../handle'; +import config from '../../config'; + +newCommand({ + name:"help", + run: (data) => { + //TODO: change this to work somehow else because this is not a-okay + data.player.sendMessage(`§l§aPREFIX:§2 §r${config.chat.prefix}\n§l§aCOMMANDS:\n§r§eban §r|| to ban a person\n§einvsee §r|| see inventory of a player\n§ecopyinv §r|| copy inventory of a player to yours\n§emute §r|| mute a player\n§eunmute §r || unmute a player\n§eworldborder [border] §r|| get or set the world border\n§evanish §r|| toggle vanish mode\n§eclearchat §r|| clear the chat\n§efakeleave §r|| simulate leaving the realm\n§efakeleave_server §r|| simulate leaving the server\n§esummon_npc §r|| summon an NPC\n§enotify §r|| toggle anticheat notifications\n§elagclear §r|| clear lag\n§eunban §r|| unban a player`) + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/invsee.js b/Safeguard anti-cheat B/scripts/command/src/invsee.js new file mode 100644 index 0000000..212dc3e --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/invsee.js @@ -0,0 +1,15 @@ +import { newCommand } from '../handle'; +import { getPlayerByName, invsee } from '../../assets/util'; + +newCommand({ + name:"invsee", + run: (data) => { + const setNameInvsee = data.args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); + if (getPlayerByName(setNameInvsee).hasTag("admin")) { + data.player.sendMessage(`§6[§eSafeGuard§6]§f Can't view the inventory of §e${setNameInvsee}§f, they're an admin.`); + return; + } + data.player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${player.name} §bviewed the inventory of§l§5 ${setNameInvsee.replace("@", "")}! §r"}]}`); + invsee(data.player.name, setNameInvsee); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/lagclear.js b/Safeguard anti-cheat B/scripts/command/src/lagclear.js new file mode 100644 index 0000000..2ff1702 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/lagclear.js @@ -0,0 +1,8 @@ +import { newCommand } from '../handle'; + +newCommand({ + name:"lagclear", + run: (data) => { + data.player.runCommandAsync("function anti/anti_lag"); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/mute.js b/Safeguard anti-cheat B/scripts/command/src/mute.js new file mode 100644 index 0000000..dce8f66 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/mute.js @@ -0,0 +1,22 @@ +import { canFindPlayer, getPlayerByName } from '../../assets/util'; +import { newCommand } from '../handle'; + +newCommand({ + name:"mute", + run: (data) => { + let player = data.player; + const setNameMute = data.args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); + if (!canFindPlayer(setNameMute)) { + player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameMute}§f was not found`); + return; + } + if (getPlayerByName(setNameMute).hasTag("admin")) { + player.sendMessage(`§6[§eSafeGuard§6]§f Can't mute §e${setNameMute}§f, they're an admin.`); + return; + } + player.runCommandAsync('tag "' + setNameMute +'" add muted'); + player.sendMessage(`§6[§eSafeGuard§6]§f Muted §e${setNameMute}`); + player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${player.name} §bmuted§l§5 ${setNameMute}! §r"}]}`); + + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/notify.js b/Safeguard anti-cheat B/scripts/command/src/notify.js new file mode 100644 index 0000000..2d91f20 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/notify.js @@ -0,0 +1,8 @@ +import { newCommand } from '../handle'; + +newCommand({ + name:"notify", + run: (data) => { + data.player.runCommandAsync("function admin_cmds/notify"); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/summon_npc.js b/Safeguard anti-cheat B/scripts/command/src/summon_npc.js new file mode 100644 index 0000000..1d52669 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/summon_npc.js @@ -0,0 +1,8 @@ +import { newCommand } from '../handle'; + +newCommand({ + name:"summon_npc", + run: (data) => { + data.player.runCommandAsync("function admin_cmds/summon_npc"); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/unban.js b/Safeguard anti-cheat B/scripts/command/src/unban.js new file mode 100644 index 0000000..8ec5f84 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/unban.js @@ -0,0 +1,10 @@ +import { unban } from '../../assets/util'; +import { newCommand } from '../handle'; + +newCommand({ + name:"unban", + run: (data) => { + const setNameUnban = data.args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); + unban(data.player,setNameUnban); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/unmute.js b/Safeguard anti-cheat B/scripts/command/src/unmute.js new file mode 100644 index 0000000..0032cad --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/unmute.js @@ -0,0 +1,22 @@ +import { canFindPlayer, getPlayerByName } from '../../assets/util'; +import { newCommand } from '../handle'; + +newCommand({ + name:"unmute", + run: (data) => { + let player = data.player; + const setNameUnmute = data.args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); + if (!canFindPlayer(setNameUnmute)) { + player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameUnmute}§f was not found`); + return; + } + if (!getPlayerByName(setNameUnmute).hasTag("muted")) { + player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameUnmute}§f is not muted.`); + return; + } + player.runCommandAsync('tag "' + setNameUnmute +'" remove muted'); + player.sendMessage(`§6[§eSafeGuard§6]§f Unmuted §e${setNameUnmute}`); + player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${player.name} §bunmuted§l§5 ${setNameUnmute}! §r"}]}`); + + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/vanish.js b/Safeguard anti-cheat B/scripts/command/src/vanish.js new file mode 100644 index 0000000..ebc7891 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/vanish.js @@ -0,0 +1,8 @@ +import { newCommand } from '../handle'; + +newCommand({ + name:"vanish", + run: (data) => { + data.player.runCommandAsync("function admin_cmds/vanish"); + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/command/src/worldborder.js b/Safeguard anti-cheat B/scripts/command/src/worldborder.js new file mode 100644 index 0000000..591ad95 --- /dev/null +++ b/Safeguard anti-cheat B/scripts/command/src/worldborder.js @@ -0,0 +1,41 @@ +import { scoreboardAction } from '../../assets/util'; +import config from '../../config'; +import { newCommand } from '../handle'; +import * as Minecraft from "@minecraft/server"; + +const world = Minecraft.world; + +newCommand({ + name:"worldborder", + run: (data) => { + let player = data.player; + let oldBorder = null; + world.scoreboard.getObjectives().forEach((objective) => { + const objectiveId = objective.id; + if (objectiveId.startsWith("safeguard:worldBorder:")) oldBorder = objectiveId.split("safeguard:worldBorder:")[1]; + }); + const border = data.args[1]; + if (!border) { + player.sendMessage(`§6[§eSafeGuard§6]§f The current border is §e${oldBorder ?? "not set"}§f.`); + return; + } + if(border === "remove"){ + if(!oldBorder) return player.sendMessage(`§6[§eSafeGuard§6]§f The world border is §enot set§f.`); + scoreboardAction(`safeguard:worldBorder:${oldBorder}`,"remove"); + player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${player.name} §bremoved the world border! §r"}]}`); + player.sendMessage(`§6[§eSafeGuard§6]§r Removed the world border.`); + return; + } + if (isNaN(border) || border === "" || border < config.world.worldborder.minBorderDistance) { + player.sendMessage(`§6[§eSafeGuard§6]§f You need to enter a valid number for the border (must be more than ${config.world.worldborder.minBorderDistance}).`); + return; + } + world.scoreboard.getObjectives().forEach((objective) => { + if (objective.id.startsWith("safeguard:worldBorder:")) scoreboardAction(objective.id, "remove"); + }); + scoreboardAction(`safeguard:worldBorder:${border}`, "add"); + player.sendMessage(`§6[§eSafeGuard§6]§f Set world border to §e${border}§f blocks.`); + player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${player.name} §bset the world border to§5 ${border}§b blocks! §r"}]}`); + + } +}) \ No newline at end of file diff --git a/Safeguard anti-cheat B/scripts/config.js b/Safeguard anti-cheat B/scripts/config.js index 63bd05a..e7fbce3 100644 --- a/Safeguard anti-cheat B/scripts/config.js +++ b/Safeguard anti-cheat B/scripts/config.js @@ -41,6 +41,11 @@ export default { "maxBlocks": 3, //checks if admin players are using nuker (good for anti op abuse) "checkAdmins": true + }, + "worldborder":{ + //the minimum border size required, this is used so if a possible admin abuse or force op occurs hackers don't create a border of a size 1 block or less which + //will teleport all the players up in the air constantly + "minBorderDistance": 500 } }, "chat":{ diff --git a/Safeguard anti-cheat B/scripts/index.js b/Safeguard anti-cheat B/scripts/index.js index 165d569..a6156a6 100644 --- a/Safeguard anti-cheat B/scripts/index.js +++ b/Safeguard anti-cheat B/scripts/index.js @@ -4,8 +4,10 @@ import { ActionFormData } from '@minecraft/server-ui'; import * as config from "./config.js"; import * as ui from "./assets/ui.js"; -import {invsee, getPlayerByName, canFindPlayer, scoreboardAction, unban, copyInv, formatMilliseconds } from "./assets/util.js"; +import { scoreboardAction, formatMilliseconds } from "./assets/util.js"; import { globalBanList } from './assets/globalBanList.js'; +import { commandHandler } from './command/handle.js'; +import "./command/importer.js"; console.warn("Script Loaded"); @@ -13,7 +15,6 @@ const world = Minecraft.world; - world.beforeEvents.itemUseOn.subscribe((data) => { const player = data.source; let antiItemsOn = (world.scoreboard.getObjective('item_on') === undefined) ? false : true; @@ -72,7 +73,7 @@ world.beforeEvents.chatSend.subscribe((data) => { if (!message.startsWith(prefix)) return; - const args = message.substring(prefix.length).split(" "); + if (!player.hasTag("admin")) { player.sendMessage('§6[§eSafeGuard§6]§r§c You need admin tag to run this!'); @@ -80,161 +81,7 @@ world.beforeEvents.chatSend.subscribe((data) => { return; } - switch (args[0]) { - case "help": - player.sendMessage(`§l§aPREFIX:§2 §r${prefix}\n§l§aCOMMANDS:\n§r§eban §r|| to ban a person\n§einvsee §r|| see inventory of a player\n§ecopyinv §r|| copy inventory of a player to yours\n§emute §r|| mute a player\n§eunmute §r || unmute a player\n§eworldborder [border] §r|| get or set the world border\n§evanish §r|| toggle vanish mode\n§eclearchat §r|| clear the chat\n§efakeleave §r|| simulate leaving the realm\n§efakeleave_server §r|| simulate leaving the server\n§esummon_npc §r|| summon an NPC\n§enotify §r|| toggle anticheat notifications\n§elagclear §r|| clear lag\n§eunban §r|| unban a player`); - data.cancel = true; - break; - - - - case "invsee": - data.cancel = true; - const setNameInvsee = args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); - if (getPlayerByName(setNameInvsee).hasTag("admin")) { - player.sendMessage(`§6[§eSafeGuard§6]§f Can't view the inventory of §e${setNameInvsee}§f, they're an admin.`); - return; - } - player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${sender} §bviewed the inventory of§l§5 ${setNameInvsee.replace("@", "")}! §r"}]}`); - invsee(sender, setNameInvsee); - break; - - case "ban": - data.cancel = true; - const setNameBan = args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); - if (!canFindPlayer(setNameBan)) { - player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameBan}§f was not found`); - return; - } - if (getPlayerByName(setNameBan).hasTag("admin")) { - player.sendMessage(`§6[§eSafeGuard§6]§f Can't ban §e${setNameBan}§f, they're an admin.`); - return; - } - player.runCommandAsync('tag "' + setNameBan +'" add Ban'); - player.sendMessage(`§6[§eSafeGuard§6]§f Banned §e${setNameBan}`); - player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${sender} §bbanned§l§5 ${setNameBan}! §r"}]}`); - break; - - case "mute": - data.cancel = true; - const setNameMute = args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); - if (!canFindPlayer(setNameMute)) { - player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameMute}§f was not found`); - return; - } - if (getPlayerByName(setNameMute).hasTag("admin")) { - player.sendMessage(`§6[§eSafeGuard§6]§f Can't mute §e${setNameMute}§f, they're an admin.`); - return; - } - player.runCommandAsync('tag "' + setNameMute +'" add muted'); - player.sendMessage(`§6[§eSafeGuard§6]§f Muted §e${setNameMute}`); - player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${sender} §bmuted§l§5 ${setNameMute}! §r"}]}`); - break; - - case "unmute": - data.cancel = true; - const setNameUnmute = args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); - if (!canFindPlayer(setNameUnmute)) { - player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameUnmute}§f was not found`); - return; - } - if (!getPlayerByName(setNameUnmute).hasTag("muted")) { - player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameUnmute}§f is not muted.`); - return; - } - player.runCommandAsync('tag "' + setNameUnmute +'" remove muted'); - player.sendMessage(`§6[§eSafeGuard§6]§f Unmuted §e${setNameUnmute}`); - player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${sender} §bunmuted§l§5 ${setNameUnmute}! §r"}]}`); - break; - - case "worldborder": - data.cancel = true; - let oldBorder = null; - world.scoreboard.getObjectives().forEach((objective) => { - const objectiveId = objective.id; - if (objectiveId.startsWith("safeguard:worldBorder:")) oldBorder = objectiveId.split("safeguard:worldBorder:")[1]; - }); - const border = args[1]; - if (!border) { - player.sendMessage(`§6[§eSafeGuard§6]§f The current border is §e${oldBorder ?? "not set"}§f.`); - return; - } - if(border === "remove"){ - if(!oldBorder) return player.sendMessage(`§6[§eSafeGuard§6]§f The world border is §enot set§f.`); - scoreboardAction(`safeguard:worldBorder:${oldBorder}`,"remove"); - player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${sender} §bremoved the world border! §r"}]}`); - player.sendMessage(`§6[§eSafeGuard§6]§r Removed the world border.`); - return; - } - if (isNaN(border) || border === "" || border < 500) { - player.sendMessage(`§6[§eSafeGuard§6]§f You need to enter a valid number for the border (must be more than 500).`); - return; - } - world.scoreboard.getObjectives().forEach((objective) => { - if (objective.id.startsWith("safeguard:worldBorder:")) scoreboardAction(objective.id, "remove"); - }); - scoreboardAction(`safeguard:worldBorder:${border}`, "add"); - player.sendMessage(`§6[§eSafeGuard§6]§f Set world border to §e${border}§f blocks.`); - player.runCommandAsync(`tellraw @a[tag=admin,scores={notify=1}] {"rawtext":[{"text":"§6[§eSafeGuard Notify§6]§5§l "},{"text":"${sender} §bset the world border to§5 ${border}§b blocks! §r"}]}`); - break; - - case "vanish": - player.runCommandAsync("function admin_cmds/vanish"); - data.cancel = true; - break; - - case "clearchat": - player.runCommandAsync("function admin_cmds/clearchat"); - data.cancel = true; - break; - - case "fakeleave": - player.runCommandAsync("function admin_cmds/fake_leave"); - data.cancel = true; - break; - - case "fakeleave_server": - player.runCommandAsync("function admin_cmds/fake_leave_server"); - data.cancel = true; - break; - - case "summon_npc": - player.runCommandAsync("function admin_cmds/summon_npc"); - data.cancel = true; - break; - - case "lagclear": - player.runCommandAsync("function anti/anti_lag"); - data.cancel = true; - break; - - case "notify": - player.runCommandAsync("function admin_cmds/notify"); - data.cancel = true; - break; - - case "copyinv": - data.cancel = true; - const setNameInvcopy = args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); - if (!canFindPlayer(setNameInvcopy)) { - player.sendMessage(`§6[§eSafeGuard§6]§f Player §e${setNameInvcopy}§f was not found`); - return; - } - copyInv(player,setNameInvcopy) - break; - - case "unban": - data.cancel = true; - const setNameUnban = args.slice(1).join(" ").replaceAll('"', "").replaceAll('@', ""); - unban(player,setNameUnban); - break; - - - default: - player.sendMessage(`§cUnknown command: §f${args}`); - data.cancel = true; - break; - } + commandHandler(data); }) @@ -273,8 +120,12 @@ world.afterEvents.playerBreakBlock.subscribe((data) => { block.setPermutation(data.brokenBlockPermutation); if(autoModOn) { player.runCommand("gamemode adventure @s"); + //I decided to put the player in adventure mode so they can't break more blocks player.teleport({x: player.location.x, y: 325, z: player.location.z},{dimension: player.dimension, rotation: {x: 0, y: 0}, keepVelocity: false}); - player.runCommand(`kick "${player.name}" §r§6[§eSafeGuard§6]§r§4 You were detected using nuker by breaking §c${player.blocksBroken}§4 in one tick. `) + player.runCommand(`kick "${player.name}" §r§6[§eSafeGuard§6]§r§4 You were detected using nuker by breaking §c${player.blocksBroken}§4 in one tick. `); + //we only send an alert if auto mod is enabled because otherwise player would be breaking blocks indefinitely + //and constantly making the alert pop up, causing spam + //here, we kick the player so the message should be sent once or twice without causing spam world.sendMessage(`§6[§eSafeGuard§6]§r§c§l ${player.name} §r§4Was detected using nuker by breaking §l§c${player.blocksBroken}§r§4 blocks in one tick!§r`); } return; @@ -312,14 +163,14 @@ Minecraft.system.runInterval(() => { } if(velocity.x == 0 && velocity.z == 0 && !player.isFalling) player.removeTag("safeguard:moving") - const item = player.getComponent("minecraft:inventory").container.getItem(player.selectedSlot); + const item = inv.getItem(player.selectedSlot); if(!item) player.removeTag("safeguard:hasRiptide"); if(item){ const itemName = item.nameTag ?? ''; //check if player has a trident if(item.typeId == "minecraft:trident") { - const hasRiptide = item.getComponent("enchantments").enchantments.hasEnchantment("riptide"); + const hasRiptide = item.getComponent("enchantable").hasEnchantment("riptide"); if(hasRiptide !== 0) player.addTag("safeguard:hasRiptide"); } else if(item.typeId !== "minecraft:trident") player.removeTag("safeguard:hasRiptide"); @@ -330,20 +181,20 @@ Minecraft.system.runInterval(() => { if (itemName.length > config.default.item.anti_items.maxItemNameLength && antiItemsOn) { world.sendMessage('§6[§eSafeGuard§6]§r§c§l ' + plrName + ' §r§4Has illegal item: §l§c' +item.typeId.replace('minecraft:','') +'§l§4(chr limit exceeded§c ' + itemName.length + '§4/30)§4!§r') player.runCommandAsync('function punishment/warning/ill_warning'); - inv.setItem(player.selectedSlot, new Minecraft.ItemStack('air', 1)); + inv.setItem(player.selectedSlot, undefined); return; } else if (item.getLore().length > 0 && antiItemsOn && config.default.item.anti_items.antiLore) { //items in surivial usually don't have lore in them so it is banned(note to make this a setting) world.sendMessage('§6[§eSafeGuard§6]§r§c§l ' + plrName + '§r §4Has illegal item: §c§l' +item.typeId.replace('minecraft:','') +'§4§l(lore chr limit exceeded§c ' + String(item.getLore()).length + '§4/0)§4!§r') player.runCommandAsync('function punishment/warning/ill_warning'); - inv.setItem(player.selectedSlot, new Minecraft.ItemStack('air', 1)); + inv.setItem(player.selectedSlot, undefined); return; } //keyword ban check for(var u = 0; u < config.default.item.anti_items.bannedKeyWords.length; u++){ if (String(itemName.toLowerCase()).includes(config.default.item.anti_items.bannedKeyWords[u]) && antiItemsOn) { world.sendMessage('§6[§eSafeGuard§6]§r§c§l ' + plrName + '§r §4Has illegal item: §c§l' +item.typeId.replace('minecraft:','') +' §r§4with banned keyword, item name:§r ' + String(itemName) + '§4!§r'); - inv.setItem(player.selectedSlot, new Minecraft.ItemStack('air', 1)); + inv.setItem(player.selectedSlot, undefined); return; }} @@ -388,10 +239,9 @@ Minecraft.system.runInterval(() => { } world.scoreboard.getObjectives().forEach((objective) => { - const objectiveId = objective.id; - if(objectiveId.startsWith("safeguard:worldBorder:")){ + if(objective.id.startsWith("safeguard:worldBorder:")){ let {x,y,z} = player.location; - const border = objectiveId.split("safeguard:worldBorder:")[1]; + const border = objective.id.split("safeguard:worldBorder:")[1]; if(x > border || y > border || z > border || x < -border || y < -border || z < -border ) { player.sendMessage(`§6[§eSafeGuard§6]§r You reached the border of §e${border}§f blocks!`); player.teleport({x: 0, y: 325, z: 0},{dimension: player.dimension, rotation: {x: 0, y: 0}, keepVelocity: false}); @@ -402,21 +252,10 @@ Minecraft.system.runInterval(() => { //anti fly idk let debugMenu = { - isFalling: player.isFalling, - isFlying: player.isFlying, - isOnGround: player.isOnGround, - isGliding: player.isGliding, - isClimbing: player.isClimbing, - fallDistance: player.fallDistance, - isSwimming: player.isSwimming, - isJumping: player.isJumping, - isSprinting: player.isSprinting, - isInWater: player.isInWater, - isSneaking: player.isSneaking, - velocity: velocity + rotation: player.getViewDirection() } //world.sendMessage(`-------------\n§e${JSON.stringify(velocity, null, 2)}§r\n-------------`); - if(config.debug) world.sendMessage(`§e${JSON.stringify(debugMenu, null, 2)}§r\n-------------`); + if(config.default.debug) world.sendMessage(`§e${JSON.stringify(debugMenu, null, 2)}§r\n-------------`); //check if fall distance is in negatives (fly detection) if(player.fallDistance < config.default.movement.fly.minFallDistance && antiFly && !player.hasTag("gamemode:creative") && !player.hasTag("admin") && !player.hasTag("safeguard:hasRiptide") && !player.isGliding && !player.isClimbing){