From c8bea0739a38413e0f1e38d6f35d719e51d0d34c Mon Sep 17 00:00:00 2001 From: JustSky Date: Wed, 19 Jul 2023 06:56:21 +0000 Subject: [PATCH] 1.1.0-stable --- scripts/main/plugins/Chat Ranks/system.js | 4 +- .../Custom Commands/global/home/delhome.js | 6 ++- .../Custom Commands/global/home/home.js | 5 +- .../Custom Commands/global/home/listhome.js | 23 ++++---- .../Custom Commands/global/home/sethome.js | 2 +- scripts/main/plugins/plugin.loader.js | 22 +++++--- src/main/@modules/storages/Database.Class.ts | 2 +- src/main/plugins/Chat Ranks/system.ts | 3 +- .../Custom Commands/global/home/delhome.ts | 10 ++-- .../Custom Commands/global/home/home.ts | 10 ++-- .../Custom Commands/global/home/listhome.ts | 20 +++---- .../Custom Commands/global/home/sethome.ts | 2 +- src/main/plugins/plugin.loader.ts | 54 +++++++++---------- 13 files changed, 91 insertions(+), 72 deletions(-) diff --git a/scripts/main/plugins/Chat Ranks/system.js b/scripts/main/plugins/Chat Ranks/system.js index cb7d881..79da8a4 100644 --- a/scripts/main/plugins/Chat Ranks/system.js +++ b/scripts/main/plugins/Chat Ranks/system.js @@ -1,8 +1,10 @@ import { world } from "@minecraft/server"; -import { BeforeEvents, PlayerClass } from "../@modules"; +import { BeforeEvents, Command, PlayerClass } from "../@modules"; import { RankConfig } from "./config"; BeforeEvents.on("chat", (rawdata) => { const { sender, message } = rawdata; + if (message.startsWith(Command.getPrefix())) + return; rawdata.cancel = true; const player = new PlayerClass(sender); const getRank = player.getTagStartsWith("rank:")?.slice(5) ?? RankConfig.defaultRank; diff --git a/scripts/main/plugins/Custom Commands/global/home/delhome.js b/scripts/main/plugins/Custom Commands/global/home/delhome.js index c56820a..9d2d969 100644 --- a/scripts/main/plugins/Custom Commands/global/home/delhome.js +++ b/scripts/main/plugins/Custom Commands/global/home/delhome.js @@ -1,7 +1,7 @@ import { Command, CommandRegistration, Validation } from "../../../@modules"; import { HomeDB } from "./sethome"; const registration = new CommandRegistration() - .setName("delome") + .setName("delhome") .setDescription("Delete home") .setAliases(["deletehome", "dhome"]) .setInputs({ 0: ["string"] }) @@ -14,5 +14,7 @@ Command.BuildCommand(registration, (interaction) => { return sender.sendMessage("§cHome name cannot be empty"); const homeDBFrmt = `${sender.name}_${homeName}`; if (!HomeDB.hasKey(homeDBFrmt)) - return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`); + return sender.sendMessage(`§cHome with name §e${homeName} §cdoesn't exist`); + HomeDB.delete(homeDBFrmt); + return sender.sendMessage(`§aSuccessfully deleted home with name §e${homeName}`); }); diff --git a/scripts/main/plugins/Custom Commands/global/home/home.js b/scripts/main/plugins/Custom Commands/global/home/home.js index 1ee9b02..37619b7 100644 --- a/scripts/main/plugins/Custom Commands/global/home/home.js +++ b/scripts/main/plugins/Custom Commands/global/home/home.js @@ -7,15 +7,16 @@ const registration = new CommandRegistration() .setInputs({ 0: ["string"] }) .setUsage([""]) .setExample(["home myHome"]); -Command.BuildCommand(registration, (interaction) => { +Command.BuildCommand(registration, async (interaction) => { const { sender, inputs } = interaction; const homeName = inputs.getInput(0); if (Validation.isUndefined(homeName)) return sender.sendMessage("§cHome name cannot be empty"); const homeDBFrmt = `${sender.name}_${homeName}`; if (!HomeDB.hasKey(homeDBFrmt)) - return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`); + return sender.sendMessage(`§cHome with name §e${homeName} §cdoesn't exist`); const parsedHome = HomeDB.get(homeDBFrmt); + await null; sender.teleport({ x: parsedHome.coordinate[0], y: parsedHome.coordinate[1], diff --git a/scripts/main/plugins/Custom Commands/global/home/listhome.js b/scripts/main/plugins/Custom Commands/global/home/listhome.js index c938cef..beec596 100644 --- a/scripts/main/plugins/Custom Commands/global/home/listhome.js +++ b/scripts/main/plugins/Custom Commands/global/home/listhome.js @@ -1,20 +1,21 @@ -import { Command, CommandRegistration, Validation } from "../../../@modules"; +import { Command, CommandRegistration } from "../../../@modules"; import { HomeDB } from "./sethome"; const registration = new CommandRegistration() .setName("listhome") .setDescription("Get all home") - .setInputs({ 0: ["string"] }) .setUsage([""]) - .setExample(["home myHome"]); + .setExample(["listhome myHome"]); Command.BuildCommand(registration, (interaction) => { - const { sender, inputs } = interaction; - const homeName = inputs.getInput(0); - if (Validation.isUndefined(homeName)) - return sender.sendMessage("§cHome name cannot be empty"); - const findHome = HomeDB.find((home) => home.creator === sender.name); - return sender.sendMessage(`§b---- Home List ----\n\n${findHome.length === 0 + const { sender } = interaction; + const homes = []; + for (const [, home] of HomeDB) { + if (home.creator === sender.name) + homes.push(home); + } + return sender.sendMessage(`§b---- Home List ----\n\n${homes.length === 0 ? "§f# §7You don't have any home" - : findHome + : homes .sort() - .map((home) => `§f# §7${home.name} - ${home.dimension}`)}`); + .map((home) => `§f# §a${home.name} §7- ${home.dimension}`) + .join("\n\n")}`); }); diff --git a/scripts/main/plugins/Custom Commands/global/home/sethome.js b/scripts/main/plugins/Custom Commands/global/home/sethome.js index 83ccca7..c389196 100644 --- a/scripts/main/plugins/Custom Commands/global/home/sethome.js +++ b/scripts/main/plugins/Custom Commands/global/home/sethome.js @@ -14,7 +14,7 @@ Command.BuildCommand(registration, (interaction) => { return sender.sendMessage("§cHome name cannot be empty"); const homeDBFrmt = `${sender.name}_${homeName}`; if (HomeDB.hasKey(homeDBFrmt)) - return sender.sendMessage(`§eHome with name ${homeName} already exist`); + return sender.sendMessage(`§eHome with name §e${homeName} §calready exist`); HomeDB.set(homeDBFrmt, { name: homeName, creator: sender.name, diff --git a/scripts/main/plugins/plugin.loader.js b/scripts/main/plugins/plugin.loader.js index 48e3fdb..ce3f9eb 100644 --- a/scripts/main/plugins/plugin.loader.js +++ b/scripts/main/plugins/plugin.loader.js @@ -9,16 +9,26 @@ const pluginFolder = [ "Chat Ranks", "Custom Commands", ]; +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. // Don't Touch import "./_ignore/index"; const start = Date.now(); for (const plugin of pluginFolder) { const end = Date.now(); import(`./${plugin}/system`) - .then(() => { - throw `Loaded plugin: ${plugin} successfully, in ${end - start} ms`; - }) - .catch((err) => { - throw `Error on loading plugin: ${plugin}\nError: ${err}\nStack: ${err.stack}`; - }); + .then(() => console.warn(`Loaded plugin: ${plugin} successfully, in ${end - start} ms`)) + .catch((err) => console.warn(`Error on loading plugin: ${plugin}\nError: ${err}\nStack: ${err.stack}`)); } diff --git a/src/main/@modules/storages/Database.Class.ts b/src/main/@modules/storages/Database.Class.ts index 34a9ef5..221e673 100644 --- a/src/main/@modules/storages/Database.Class.ts +++ b/src/main/@modules/storages/Database.Class.ts @@ -134,7 +134,7 @@ class Database { * Find data without key * @param fn - Function */ - find(fn: (value: any, key?: any, map?: Map) => any): [] { + find(fn: (value: any, key?: any, map?: Map) => any): any { return this.RESTORED_DATA.find(fn); } diff --git a/src/main/plugins/Chat Ranks/system.ts b/src/main/plugins/Chat Ranks/system.ts index 1106638..edba883 100644 --- a/src/main/plugins/Chat Ranks/system.ts +++ b/src/main/plugins/Chat Ranks/system.ts @@ -1,9 +1,10 @@ import { world } from "@minecraft/server"; -import { BeforeEvents, PlayerClass } from "../@modules"; +import { BeforeEvents, Command, PlayerClass } from "../@modules"; import { RankConfig } from "./config"; BeforeEvents.on("chat", (rawdata) => { const { sender, message } = rawdata; + if (message.startsWith(Command.getPrefix())) return; rawdata.cancel = true; const player = new PlayerClass(sender); const getRank = diff --git a/src/main/plugins/Custom Commands/global/home/delhome.ts b/src/main/plugins/Custom Commands/global/home/delhome.ts index 911f023..7588467 100644 --- a/src/main/plugins/Custom Commands/global/home/delhome.ts +++ b/src/main/plugins/Custom Commands/global/home/delhome.ts @@ -2,7 +2,7 @@ import { Command, CommandRegistration, Validation } from "../../../@modules"; import { HomeDB } from "./sethome"; const registration: CommandRegistration = new CommandRegistration() - .setName("delome") + .setName("delhome") .setDescription("Delete home") .setAliases(["deletehome", "dhome"]) .setInputs({ 0: ["string"] }) @@ -17,7 +17,11 @@ Command.BuildCommand(registration, (interaction) => { return sender.sendMessage("§cHome name cannot be empty"); const homeDBFrmt = `${sender.name}_${homeName}`; - if (!HomeDB.hasKey(homeDBFrmt)) - return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`); + return sender.sendMessage(`§cHome with name §e${homeName} §cdoesn't exist`); + + HomeDB.delete(homeDBFrmt); + return sender.sendMessage( + `§aSuccessfully deleted home with name §e${homeName}` + ); }); diff --git a/src/main/plugins/Custom Commands/global/home/home.ts b/src/main/plugins/Custom Commands/global/home/home.ts index c54e3dc..54984a2 100644 --- a/src/main/plugins/Custom Commands/global/home/home.ts +++ b/src/main/plugins/Custom Commands/global/home/home.ts @@ -9,7 +9,7 @@ const registration: CommandRegistration = new CommandRegistration() .setUsage([""]) .setExample(["home myHome"]); -Command.BuildCommand(registration, (interaction) => { +Command.BuildCommand(registration, async (interaction) => { const { sender, inputs } = interaction; const homeName = inputs.getInput(0) as any; @@ -18,9 +18,11 @@ Command.BuildCommand(registration, (interaction) => { const homeDBFrmt = `${sender.name}_${homeName}`; if (!HomeDB.hasKey(homeDBFrmt)) - return sender.sendMessage(`§cHome with name ${homeName} doesn't exist`); + return sender.sendMessage(`§cHome with name §e${homeName} §cdoesn't exist`); const parsedHome = HomeDB.get(homeDBFrmt); + + await null; sender.teleport( { x: parsedHome.coordinate[0], @@ -29,5 +31,7 @@ Command.BuildCommand(registration, (interaction) => { }, { dimension: world.getDimension(parsedHome.dimension) } ); - return sender.sendMessage(`§aSuccessfully teleported to home with name §e${homeName}`) + return sender.sendMessage( + `§aSuccessfully teleported to home with name §e${homeName}` + ); }); diff --git a/src/main/plugins/Custom Commands/global/home/listhome.ts b/src/main/plugins/Custom Commands/global/home/listhome.ts index bc29b27..f8143d9 100644 --- a/src/main/plugins/Custom Commands/global/home/listhome.ts +++ b/src/main/plugins/Custom Commands/global/home/listhome.ts @@ -5,28 +5,28 @@ import { HomeDB } from "./sethome"; const registration: CommandRegistration = new CommandRegistration() .setName("listhome") .setDescription("Get all home") - .setInputs({ 0: ["string"] }) .setUsage([""]) - .setExample(["home myHome"]); + .setExample(["listhome myHome"]); Command.BuildCommand(registration, (interaction) => { - const { sender, inputs } = interaction; - const homeName = inputs.getInput(0) as any; + const { sender } = interaction; + const homes = []; - if (Validation.isUndefined(homeName)) - return sender.sendMessage("§cHome name cannot be empty"); + for (const [, home] of HomeDB) { + if (home.creator === sender.name) homes.push(home); + } - const findHome = HomeDB.find((home) => home.creator === sender.name); return sender.sendMessage( `§b---- Home List ----\n\n${ - findHome.length === 0 + homes.length === 0 ? "§f# §7You don't have any home" - : findHome + : homes .sort() .map( (home: { name: string; dimension: string }) => - `§f# §7${home.name} - ${home.dimension}` + `§f# §a${home.name} §7- ${home.dimension}` ) + .join("\n\n") }` ); }); diff --git a/src/main/plugins/Custom Commands/global/home/sethome.ts b/src/main/plugins/Custom Commands/global/home/sethome.ts index ecc4c4e..588aaac 100644 --- a/src/main/plugins/Custom Commands/global/home/sethome.ts +++ b/src/main/plugins/Custom Commands/global/home/sethome.ts @@ -24,7 +24,7 @@ Command.BuildCommand(registration, (interaction) => { const homeDBFrmt = `${sender.name}_${homeName}`; if (HomeDB.hasKey(homeDBFrmt)) - return sender.sendMessage(`§eHome with name ${homeName} already exist`); + return sender.sendMessage(`§eHome with name §e${homeName} §calready exist`); HomeDB.set(homeDBFrmt, { name: homeName, diff --git a/src/main/plugins/plugin.loader.ts b/src/main/plugins/plugin.loader.ts index 859f97d..6a1f604 100644 --- a/src/main/plugins/plugin.loader.ts +++ b/src/main/plugins/plugin.loader.ts @@ -11,40 +11,34 @@ const pluginFolder: string[] = [ "Custom Commands", ]; - - - - - - - - - - - - - - - - - - - - - - - - +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. +//. // Don't Touch import "./_ignore/index"; const start: number = Date.now(); for (const plugin of pluginFolder) { const end: number = Date.now(); import(`./${plugin}/system`) - .then(() => { - throw `Loaded plugin: ${plugin} successfully, in ${end - start} ms`; - }) - .catch((err) => { - throw `Error on loading plugin: ${plugin}\nError: ${err}\nStack: ${err.stack}`; - }); + .then(() => + console.warn( + `Loaded plugin: ${plugin} successfully, in ${end - start} ms` + ) + ) + .catch((err) => + console.warn( + `Error on loading plugin: ${plugin}\nError: ${err}\nStack: ${err.stack}` + ) + ); }