Skip to content

Commit

Permalink
色々修正2
Browse files Browse the repository at this point in the history
  • Loading branch information
gamelist1990 committed Sep 11, 2023
1 parent 6bad610 commit 51be6e7
Show file tree
Hide file tree
Showing 39 changed files with 205 additions and 171 deletions.
9 changes: 5 additions & 4 deletions src/commands/debug_commands/listitems.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChatSendAfterEvent, ItemStack, Player } from "@minecraft/server";
import { MinecraftItemTypes } from "../../node_modules/@minecraft/vanilla-data/lib/index";
import config from "../../data/config.js";
import { crypto, getPrefix, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsgToPlayer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager";

function listItems(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -43,10 +44,10 @@ export function listitems(message: ChatSendAfterEvent, args: string[]) {
const key = config.encryption.password ? config.encryption.password : player.id;

// Generate the hash
const encode = crypto?.(salt, key);
const encode = EncryptionManager.hashWithSalt(salt as string, key);
// Make sure the user has permissions to run the command
if (hash === undefined || encode !== hash) {
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f 管理者権限がないと実行できません!!`);
if (!encode || hash === undefined || encode !== hash) {
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f 管理者しか実行できません`);
}

// Check for custom prefix
Expand Down
9 changes: 5 additions & 4 deletions src/commands/moderation/deop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChatSendAfterEvent, Player, world } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { crypto, getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager.js";

function deopHelp(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -42,7 +43,7 @@ export function deop(message: ChatSendAfterEvent, args: string[]) {

// Make sure the user has permissions to run the command
if (uniqueId !== player.name) {
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f 管理者権限がないと実行できません!!`);
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f 管理者しか実行できません`);
}

// Check for custom prefix
Expand Down Expand Up @@ -73,7 +74,7 @@ export function deop(message: ChatSendAfterEvent, args: string[]) {
}

if (!member) {
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f プレイヤーが存在しない又はオフラインです`);
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f ユーザーが見つかりません`);
}

// Check for hash/salt and validate password from member
Expand All @@ -85,7 +86,7 @@ export function deop(message: ChatSendAfterEvent, args: string[]) {
const memberKey = config.encryption.password ? config.encryption.password : member.id;

// Generate the hash
memberEncode = crypto(memberSalt, memberKey);
memberEncode = EncryptionManager.hashWithSalt(memberSalt as string, memberKey);
} catch (error) {}

if (memberHash !== undefined && memberHash === memberEncode) {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/moderation/lockdown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChatSendAfterEvent, Player, world } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { crypto, getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager.js";

function lockdownHelp(player: Player, prefix: string, lockdownBoolean: string | number | boolean) {
let commandStatus: string;
Expand Down Expand Up @@ -99,7 +100,7 @@ async function handleLockdown(message: ChatSendAfterEvent, args: string[]) {
const key = config.encryption.password ? config.encryption.password : pl.id;

// Generate the hash
const encode = crypto?.(salt, key);
const encode = EncryptionManager.hashWithSalt(salt as string, key);
if (hash !== undefined && encode === hash) {
continue;
}
Expand Down
11 changes: 6 additions & 5 deletions src/commands/moderation/modules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChatSendAfterEvent, Player } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { getScore, getPrefix, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsgToPlayer } from "../../util.js";
import { ScoreManager } from "../../classes/ScoreManager.js";

function modulesHelp(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -55,10 +56,10 @@ export function modules(message: ChatSendAfterEvent, args: string[]) {
}

// scores
const commandblocks = getScore("commandblocks", player);
const cmds = getScore("cmds", player);
const encharmor = getScore("encharmor", player);
const antikb = getScore("antikb", player);
const commandblocks = ScoreManager.getScore("commandblocks", player);
const cmds = ScoreManager.getScore("cmds", player);
const encharmor = ScoreManager.getScore("encharmor", player);
const antikb = ScoreManager.getScore("antikb", player);

// Booleans
const worldBorderBoolean = dynamicPropertyRegistry.get("worldborder_b");
Expand Down
28 changes: 15 additions & 13 deletions src/commands/moderation/op.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ChatSendAfterEvent, Player, world } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { crypto, UUID, getPrefix, sendMsg, sendMsgToPlayer, isValidUUID } from "../../util.js";
import { getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager.js";
import { UUIDManager } from "../../classes/UUIDManager.js";

function opHelp(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -48,10 +50,10 @@ export function op(message: ChatSendAfterEvent, args: string[]) {
const operatorHash = operator.getDynamicProperty("hash");
const operatorSalt = operator.getDynamicProperty("salt");

if (!operatorHash || !operatorSalt || (operatorHash !== crypto?.(operatorSalt, config.encryption.password || operator.id) && isValidUUID(operatorSalt as string))) {
if (!operatorHash || !operatorSalt || (operatorHash !== EncryptionManager.hashWithSalt(operatorSalt as string, config.encryption.password || operator.id) && UUIDManager.isValidUUID(operatorSalt as string))) {
if (!config.encryption.password) {
if (!operator.isOp()) {
return sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f 管理者しか実行できません.`);
return sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f You need to be Operator to use this command.`);
}
}
}
Expand All @@ -63,42 +65,42 @@ export function op(message: ChatSendAfterEvent, args: string[]) {

if (args.length === 0 && !config.encryption.password) {
// Operator wants to change their own password
const targetSalt = UUID.generate();
const targetSalt = UUIDManager.generateRandomUUID();

// Use either the operator's ID or the encryption password as the key
const key = config.encryption.password ? config.encryption.password : operator.id;

// Generate the hash
const newHash = crypto?.(targetSalt, key);
const newHash = EncryptionManager.hashWithSalt(targetSalt, key);

operator.setDynamicProperty("hash", newHash);
operator.setDynamicProperty("salt", targetSalt);
operator.addTag("paradoxOpped");

sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f 管理者になりました`);
sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f You are now Paradox-Opped!`);

dynamicPropertyRegistry.set(operator.id, operator.name);

return;
} else if (args.length === 1 && config.encryption.password) {
// Allow the user to gain Paradox-Op using the password
if (config.encryption.password === args[0]) {
const targetSalt = UUID.generate();
const targetSalt = UUIDManager.generateRandomUUID();

// Generate the hash using the provided password
const newHash = crypto?.(targetSalt, args[0]);
const newHash = EncryptionManager.hashWithSalt(targetSalt, args[0]);

operator.setDynamicProperty("hash", newHash);
operator.setDynamicProperty("salt", targetSalt);
operator.addTag("paradoxOpped");

sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f パスワードを使用して管理者になりました`);
sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f You are now Paradox-Opped using the password.`);
dynamicPropertyRegistry.set(operator.id, operator.name);
} else {
// Incorrect password
sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f 不明なパスワードですまた管理者しか実行できません.`);
sendMsgToPlayer(operator, `§f§4[§6Paradox§4]§f Incorrect password. You need to be Operator to use this command.`);
}
} else if (args.length >= 1 && operatorHash === crypto?.(operatorSalt, config.encryption.password || operator.id)) {
} else if (args.length >= 1 && operatorHash === EncryptionManager.hashWithSalt(operatorSalt as string, config.encryption.password || operator.id)) {
// Operator wants to grant "Paradox-Op" to another player
const targetPlayerName = args.join(" "); // Combine all arguments into a single string
// Try to find the player requested
Expand All @@ -117,14 +119,14 @@ export function op(message: ChatSendAfterEvent, args: string[]) {
const targetHash = targetPlayer.getDynamicProperty("hash");

if (targetHash === undefined) {
const targetSalt = UUID.generate();
const targetSalt = UUIDManager.generateRandomUUID();
targetPlayer.setDynamicProperty("salt", targetSalt);

// Use either the operator's ID or the encryption password as the key
const targetKey = config.encryption.password ? config.encryption.password : targetPlayer.id;

// Generate the hash
const newHash = crypto?.(targetSalt, targetKey);
const newHash = EncryptionManager.hashWithSalt(targetSalt, targetKey);

targetPlayer.setDynamicProperty("hash", newHash);

Expand Down
5 changes: 3 additions & 2 deletions src/commands/settings/enchantedarmor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChatSendAfterEvent, Player } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { getPrefix, getScore, sendMsg, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { ScoreManager } from "../../classes/ScoreManager.js";

function enchantedArmorHelp(player: Player, prefix: string, encharmorscore: number) {
let commandStatus: string;
Expand Down Expand Up @@ -64,7 +65,7 @@ async function handleEnchantedArmor(message: ChatSendAfterEvent, args: string[])
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f 管理者権限がないと実行できません!!`);
}

const encharmorscore = getScore("encharmor", player);
const encharmorscore = ScoreManager.getScore("encharmor", player);

// Check for custom prefix
const prefix = getPrefix(player);
Expand Down
5 changes: 3 additions & 2 deletions src/commands/settings/overidecommandblocksenabled.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChatSendAfterEvent, Player } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { getPrefix, getScore, sendMsg, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { ScoreManager } from "../../classes/ScoreManager.js";

function overrideCBEHelp(player: Player, prefix: string, cmdsscore: number) {
let commandStatus: string;
Expand Down Expand Up @@ -64,7 +65,7 @@ async function handleOverideCommandBlocksEnabled(message: ChatSendAfterEvent, ar
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f 管理者権限がないと実行できません!!`);
}

const cmdsscore = getScore("cmds", player);
const cmdsscore = ScoreManager.getScore("cmds", player);

// Check for custom prefix
const prefix = getPrefix(player);
Expand Down
6 changes: 4 additions & 2 deletions src/commands/settings/removecommandblocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ChatSendAfterEvent, Player } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { getPrefix, getScore, sendMsg, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsg, sendMsgToPlayer } from "../../util.js";
import { ScaffoldA } from "../../penrose/BlockPlaceAfterEvent/scaffold/scaffold_a.js";
import { ScoreManager } from "../../classes/ScoreManager.js";

function removeCBEHelp(player: Player, prefix: string, commandblocksscore: number) {
let commandStatus: string;
Expand Down Expand Up @@ -64,7 +66,7 @@ async function handleRemoveCommandBlocks(message: ChatSendAfterEvent, args: stri
return sendMsgToPlayer(player, `§f§4[§6Paradox§4]§f 管理者権限がないと実行できません!!`);
}

const commandblocksscore = getScore("commandblocks", player);
const commandblocksscore = ScoreManager.getScore("commandblocks", player);

// Check for custom prefix
const prefix = getPrefix(player);
Expand Down
5 changes: 3 additions & 2 deletions src/commands/utility/delhome.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChatSendAfterEvent, Player, world } from "@minecraft/server";
import config from "../../data/config.js";
import { decryptString, getPrefix, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsgToPlayer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager.js";

function delhomeHelp(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -70,7 +71,7 @@ export function delhome(message: ChatSendAfterEvent, args: string[]) {
if (tags[i].startsWith("1337")) {
encryptedString = tags[i];
// Decode it so we can verify it
tags[i] = decryptString(tags[i], salt as string);
tags[i] = EncryptionManager.decryptString(tags[i], salt as string);
}
if (tags[i].startsWith(args[0].toString() + " X", 13)) {
verify = true;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/utility/fullreport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async function handleFullReport(message: ChatSendAfterEvent, args: string[]) {
let divider = false;
ScoreManager.allscores.forEach((objective) => {
vlCount++;
const score = ScoreManager.getScore(objective, member);
const score = ScoreManager.ScoreManager.getscore(objective, member);
if (score > 0) {
violationsFound++;
if (violationsFound === 1) {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/utility/give.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ChatSendAfterEvent, Player, world, ItemStack } from "@minecraft/server"
import { MinecraftItemTypes } from "../../node_modules/@minecraft/vanilla-data/lib/index";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { getPrefix, sendMsgToPlayer, toPascalCase } from "../../util.js";
import { getPrefix, sendMsgToPlayer } from "../../util.js";
import { StringTransformation } from "../../classes/StringTransformation";

function giveHelp(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -91,7 +92,7 @@ export function give(message: ChatSendAfterEvent, args: string[]) {
* args[3] = data (optional)
*/
let confirmItem = false;
const itemStringConvert = toPascalCase(args[1]);
const itemStringConvert = StringTransformation.toPascalCase(args[1]);
for (const itemValidate in MinecraftItemTypes) {
if (itemStringConvert === itemValidate) {
confirmItem = true;
Expand Down
5 changes: 3 additions & 2 deletions src/commands/utility/gohome.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { world, Player, ChatSendAfterEvent } from "@minecraft/server";
import config from "../../data/config.js";
import { dynamicPropertyRegistry } from "../../penrose/WorldInitializeAfterEvent/registry.js";
import { decryptString, getPrefix, sendMsgToPlayer, setTimer } from "../../util.js";
import { getPrefix, sendMsgToPlayer, setTimer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager.js";

const cooldownTimer = new WeakMap();

Expand Down Expand Up @@ -111,7 +112,7 @@ async function handleGoHome(message: ChatSendAfterEvent, args: string[]) {
for (let i = 0; i < tagsLength; i++) {
if (tags[i].startsWith("1337")) {
// Decode it so we can verify it
tags[i] = decryptString(tags[i], salt as string);
tags[i] = EncryptionManager.decryptString(tags[i], salt as string);
}
if (tags[i].startsWith(args[0].toString() + " X", 13)) {
// Split string into array
Expand Down
5 changes: 3 additions & 2 deletions src/commands/utility/listhome.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChatSendAfterEvent, Player, world } from "@minecraft/server";
import config from "../../data/config.js";
import { decryptString, getPrefix, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsgToPlayer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager.js";

function listHomeHelp(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -57,7 +58,7 @@ export function listhome(message: ChatSendAfterEvent, args: string[]) {
for (let i = 0; i < tagsLength; i++) {
if (tags[i].startsWith("1337")) {
// Decode it so we can verify it
tags[i] = decryptString(tags[i], salt as string);
tags[i] =EncryptionManager.decryptString(tags[i], salt as string);
// If invalid then skip it
if (tags[i].startsWith("LocationHome:") === false) {
continue;
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utility/sethome.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChatSendAfterEvent, Player, world } from "@minecraft/server";
import config from "../../data/config.js";
import { decryptString, getPrefix, encryptString, sendMsgToPlayer } from "../../util.js";
import { getPrefix, sendMsgToPlayer } from "../../util.js";
import { EncryptionManager } from "../../classes/EncryptionManager.js";

function setHomeHelp(player: Player, prefix: string) {
let commandStatus: string;
Expand Down Expand Up @@ -75,7 +76,7 @@ export function sethome(message: ChatSendAfterEvent, args: string[]) {
for (let i = 0; i < tagsLength; i++) {
if (tags[i].startsWith("1337")) {
// Decode it so we can verify if it already exists
tags[i] = decryptString(tags[i], String(salt));
tags[i] = EncryptionManager.decryptString(tags[i], String(salt));
}
if (tags[i].startsWith(args[0].toString() + " X", 13)) {
verify = true;
Expand Down Expand Up @@ -107,7 +108,7 @@ export function sethome(message: ChatSendAfterEvent, args: string[]) {
}

const decryptedLocationString = `LocationHome:${args[0]} X:${homex} Y:${homey} Z:${homez} Dimension:${currentDimension}`;
const security = encryptString(decryptedLocationString, String(salt));
const security = EncryptionManager.encryptString(decryptedLocationString, String(salt));
// Store their new home coordinates
player.addTag(security);

Expand Down
Loading

0 comments on commit 51be6e7

Please sign in to comment.