Skip to content

Commit

Permalink
Update to Paradox AntiCheat v5.1.0 with enhanced moderation tools
Browse files Browse the repository at this point in the history
- Updated version to v5.1.0 in `manifest.json`, `package.json`, and `versioning.ts`.
- Increased minimum Minecraft engine version to 1.21.50 and updated module dependencies to their latest beta versions.
- Added a new `whitelist` command for managing player access, including add, remove, and list functionalities.
- Enhanced `ban` command to integrate whitelist checks, preventing bans for whitelisted players.
- Improved `player-spawn` listener:
  - Added whitelist validation to bypass local ban checks.
  - Adjusted ban logic for memory-tier-based disconnections.
- Streamlined command parsing and error handling in moderation utilities.
- Registered the `whitelist` command in `paradox.ts` to enable its functionality.

This update strengthens player moderation while ensuring smoother integration with Minecraft's latest features.
  • Loading branch information
Visual1mpact committed Dec 4, 2024
1 parent edaebda commit 3a8e7aa
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 72 deletions.
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"format_version": 2,
"header": {
"name": "Paradox AntiCheat",
"description": "A utility to fight against malicious hackers on Bedrock Edition ~ v5.0.3",
"description": "A utility to fight against malicious hackers on Bedrock Edition ~ v5.1.0",
"uuid": "54edfea5-ab51-47ca-b992-724e255b5560",
"version": [5, 0, 3],
"min_engine_version": [1, 21, 40]
"version": [5, 1, 0],
"min_engine_version": [1, 21, 50]
},
"metadata": {
"authors": ["Visual1mpact"],
Expand All @@ -30,7 +30,7 @@
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.16.0-beta"
"version": "1.17.0-beta"
},
{
"module_name": "@minecraft/server-ui",
Expand Down
64 changes: 37 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "paradox-anticheat",
"version": "5.0.3",
"version": "5.1.0",
"productName": "Paradox-AntiCheat",
"description": "A utility to fight against malicious hackers on Bedrock Edition",
"private": true,
"devDependencies": {
"@types/node": "22.9.2",
"@types/node": "22.10.1",
"@types/glob": "8.1.0",
"@types/fs-extra": "11.0.4",
"finalhandler": "1.3.1",
"prettier": "3.3.3",
"prettier": "3.4.1",
"serve-static": "1.16.2",
"typescript": "5.7.2",
"fs-extra": "11.2.0",
Expand All @@ -19,17 +19,17 @@
"tsc-alias": "1.8.10"
},
"dependencies": {
"@minecraft/server-ui": "1.4.0-beta.1.21.44-stable",
"@minecraft/server": "1.16.0-beta.1.21.44-stable",
"@minecraft/math": "1.4.0",
"@minecraft/server-ui": "1.4.0-beta.1.21.50-stable",
"@minecraft/server": "1.17.0-beta.1.21.50-stable",
"@minecraft/math": "1.5.1",
"crypto-es": "2.1.0"
},
"overrides": {
"@minecraft/math": {
"@minecraft/server": "1.16.0-beta.1.21.44-stable"
"@minecraft/server": "1.17.0-beta.1.21.50-stable"
},
"@minecraft/server-ui": {
"@minecraft/server": "1.16.0-beta.1.21.44-stable"
"@minecraft/server": "1.17.0-beta.1.21.50-stable"
}
},
"prettier": {
Expand Down
37 changes: 22 additions & 15 deletions penrose/commands/moderation/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ export const banCommand: Command = {
const world = minecraftEnvironment.getWorld();
const system = minecraftEnvironment.getSystem();

// Initialize or retrieve the banned players list
// Initialize or retrieve the banned and whitelisted players lists
let bannedPlayers: string[] = [];
let whitelistedPlayers: string[] = [];
const bannedPlayersString = world.getDynamicProperty("bannedPlayers") as string;
const whitelistedPlayersString = world.getDynamicProperty("whitelistedPlayers") as string;

try {
bannedPlayers = bannedPlayersString ? JSON.parse(bannedPlayersString) : [];
whitelistedPlayers = whitelistedPlayersString ? JSON.parse(whitelistedPlayersString) : [];
} catch (error) {
bannedPlayers = [];
whitelistedPlayers = [];
}

// Check if the command is for listing banned players
Expand All @@ -50,14 +55,7 @@ export const banCommand: Command = {
// Define valid flags
const validFlags = new Set(["-t", "--target", "-r", "--reason"]);

/**
* Captures and returns a multi-word argument from the provided array of arguments.
* This function continues to concatenate words from the `args` array until it encounters
* a valid flag or runs out of arguments.
*
* @param {string[]} args - The array of arguments to parse.
* @returns {string} - The captured multi-word argument as a string.
*/
// Capture multi-word argument helper
function captureMultiWordArgument(args: string[]): string {
let result = "";
while (args.length > 0 && !validFlags.has(args[0])) {
Expand All @@ -66,7 +64,7 @@ export const banCommand: Command = {
return result.replace(/["@]/g, "");
}

// Parse the arguments using parameter flags
// Parse the arguments
while (args.length > 0) {
const flag = args.shift();
switch (flag) {
Expand All @@ -81,6 +79,18 @@ export const banCommand: Command = {
}
}

// Abort if no player name is provided
if (!playerName) {
message.sender.sendMessage("§cPlease provide a player name using the -t or --target flag.");
return;
}

// Abort if the player is whitelisted
if (whitelistedPlayers.includes(playerName)) {
message.sender.sendMessage(`§cPlayer "${playerName}" is whitelisted and cannot be banned.`);
return;
}

// Function to get the player object by name
const getPlayerObject = (name: string) => {
return world.getAllPlayers().find((playerObject) => playerObject.name === name);
Expand Down Expand Up @@ -124,10 +134,7 @@ export const banCommand: Command = {
}
};

if (playerName) {
banPlayer(playerName);
} else {
message.sender.sendMessage("§cPlease provide a player name using the -t or --target flag.");
}
// Proceed to ban the player
banPlayer(playerName);
},
};
88 changes: 88 additions & 0 deletions penrose/commands/moderation/whitelist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Command } from "../../classes/command-handler";
import { ChatSendBeforeEvent } from "@minecraft/server";
import { MinecraftEnvironment } from "../../classes/container/dependencies";

// Define the whitelist command
export const whitelistCommand: Command = {
name: "whitelist",
description: "Manage the whitelist by adding or removing a player, or list all whitelisted players.",
usage: "{prefix}whitelist <add|remove|list> <player>",
examples: [`{prefix}whitelist add Steve`, `{prefix}whitelist remove Steve`, `{prefix}whitelist list`],
category: "Moderation",
securityClearance: 3,

/**
* Executes the whitelist command.
* @param {ChatSendBeforeEvent} message - The message object containing information about the command execution context.
* @param {string[]} args - The command arguments, where the first element specifies the action and the second (optional) is the player name.
* @param {MinecraftEnvironment} minecraftEnvironment - The Minecraft environment instance providing access to world and other utilities.
* @returns {void}
*/
execute: (message: ChatSendBeforeEvent, args: string[], minecraftEnvironment: MinecraftEnvironment): void => {
const world = minecraftEnvironment.getWorld();
const dynamicProperty = "whitelistedPlayers";

// Retrieve the whitelist from dynamic properties and parse it
const whitelistString = world.getDynamicProperty(dynamicProperty) as string;
let whitelistedPlayers: string[];

try {
whitelistedPlayers = whitelistString ? JSON.parse(whitelistString) : [];
} catch (error) {
message.sender.sendMessage("§cFailed to retrieve the whitelist. Please contact an admin.");
console.error("Error parsing whitelist:", error);
return;
}

// Validate the command arguments
const action = args.shift()?.toLowerCase();
if (!["add", "remove", "list"].includes(action)) {
message.sender.sendMessage("§cInvalid action. Use `add`, `remove`, or `list`.");
return;
}

// Handle listing all whitelisted players
if (action === "list") {
if (whitelistedPlayers.length === 0) {
message.sender.sendMessage("§2[§7Paradox§2]§o§7 No players are currently whitelisted.");
} else {
message.sender.sendMessage("\n§2[§7Paradox§2]§o§7 Whitelisted Players:");
whitelistedPlayers.forEach((player) => {
message.sender.sendMessage(` §o§7| [§f${player}§7]`);
});
}
return;
}

// Extract player name for add/remove actions
const playerName = args.join(" ").trim().replace(/["@]/g, "");
if (!playerName) {
message.sender.sendMessage("§cPlease provide a valid player name.");
return;
}

// Handle adding a player to the whitelist
if (action === "add") {
if (whitelistedPlayers.includes(playerName)) {
message.sender.sendMessage(`§cPlayer "${playerName}" is already in the whitelist.`);
return;
}

whitelistedPlayers.push(playerName);
world.setDynamicProperty(dynamicProperty, JSON.stringify(whitelistedPlayers));
message.sender.sendMessage(`§2[§7Paradox§2]§o§7 Player "${playerName}" has been added to the whitelist.`);
}

// Handle removing a player from the whitelist
if (action === "remove") {
if (!whitelistedPlayers.includes(playerName)) {
message.sender.sendMessage(`§cPlayer "${playerName}" is not in the whitelist.`);
return;
}

whitelistedPlayers = whitelistedPlayers.filter((player) => player !== playerName);
world.setDynamicProperty(dynamicProperty, JSON.stringify(whitelistedPlayers));
message.sender.sendMessage(`§2[§7Paradox§2]§o§7 Player "${playerName}" has been removed from the whitelist.`);
}
},
};
2 changes: 1 addition & 1 deletion penrose/data/versioning.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const paradoxVersion = "v5.0.3";
export const paradoxVersion = "v5.1.0";
Loading

0 comments on commit 3a8e7aa

Please sign in to comment.