Skip to content

Commit

Permalink
v1.8.5
Browse files Browse the repository at this point in the history
updated how commands work hehe
  • Loading branch information
BlaizerBrumo authored Mar 13, 2024
1 parent 044f7cf commit 9b46022
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 180 deletions.
28 changes: 28 additions & 0 deletions Safeguard anti-cheat B/scripts/command/handle.js
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 15 additions & 0 deletions Safeguard anti-cheat B/scripts/command/importer.js
Original file line number Diff line number Diff line change
@@ -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";
21 changes: 21 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/ban.js
Original file line number Diff line number Diff line change
@@ -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"}]}`);
}
})
8 changes: 8 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/clearchat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { newCommand } from '../handle';

newCommand({
name:"clearchat",
run: (data) => {
data.player.runCommandAsync("function admin_cmds/clearchat");
}
})
8 changes: 8 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/fakeleave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { newCommand } from '../handle';

newCommand({
name:"fakeleave",
run: (data) => {
data.player.runCommandAsync("function admin_cmds/fake_leave");
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { newCommand } from '../handle';

newCommand({
name:"fakeleave_server",
run: (data) => {
data.player.runCommandAsync("function admin_cmds/fake_leave_server");
}
})
10 changes: 10 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/help.js
Original file line number Diff line number Diff line change
@@ -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 <player name> §r|| to ban a person\n§einvsee <player name> §r|| see inventory of a player\n§ecopyinv <player name> §r|| copy inventory of a player to yours\n§emute <player name> §r|| mute a player\n§eunmute <player name>§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 <player name> §r|| unban a player`)
}
})
15 changes: 15 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/invsee.js
Original file line number Diff line number Diff line change
@@ -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);
}
})
8 changes: 8 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/lagclear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { newCommand } from '../handle';

newCommand({
name:"lagclear",
run: (data) => {
data.player.runCommandAsync("function anti/anti_lag");
}
})
22 changes: 22 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/mute.js
Original file line number Diff line number Diff line change
@@ -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"}]}`);

}
})
8 changes: 8 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { newCommand } from '../handle';

newCommand({
name:"notify",
run: (data) => {
data.player.runCommandAsync("function admin_cmds/notify");
}
})
8 changes: 8 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/summon_npc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { newCommand } from '../handle';

newCommand({
name:"summon_npc",
run: (data) => {
data.player.runCommandAsync("function admin_cmds/summon_npc");
}
})
10 changes: 10 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/unban.js
Original file line number Diff line number Diff line change
@@ -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);
}
})
22 changes: 22 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/unmute.js
Original file line number Diff line number Diff line change
@@ -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"}]}`);

}
})
8 changes: 8 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/vanish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { newCommand } from '../handle';

newCommand({
name:"vanish",
run: (data) => {
data.player.runCommandAsync("function admin_cmds/vanish");
}
})
41 changes: 41 additions & 0 deletions Safeguard anti-cheat B/scripts/command/src/worldborder.js
Original file line number Diff line number Diff line change
@@ -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"}]}`);

}
})
5 changes: 5 additions & 0 deletions Safeguard anti-cheat B/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":{
Expand Down
Loading

0 comments on commit 9b46022

Please sign in to comment.