From 72679fddf9bb1eceb0a37b7da0525521e2a94046 Mon Sep 17 00:00:00 2001 From: Mo9ses <65575019+moisesgamingtv9@users.noreply.github.com> Date: Wed, 7 Dec 2022 20:23:30 -0500 Subject: [PATCH] ROT V3 part 2 --- manifest.json | 4 +- scripts/Papers/CommandPaper/CommandPaper.js | 305 +++++++++--------- scripts/Papers/CommandPaper/CommandTypes.js | 38 ++- scripts/Papers/DatabasePaper.js | 106 +++--- scripts/Papers/FormPaper.js | 10 +- scripts/Papers/LangPaper.js | 49 ++- scripts/Papers/PlayerPaper.js | 55 ++-- scripts/Papers/ServerPaper.js | 114 +++---- scripts/Papers/paragraphs/ExtrasParagraphs.js | 62 +--- scripts/Stories/Building/region.js | 0 scripts/Stories/Escape/feed.js | 2 +- scripts/Stories/Escape/heal.js | 2 +- scripts/Stories/Escape/home.js | 2 +- scripts/Stories/Escape/kill.js | 2 +- scripts/Stories/Escape/repair.js | 7 +- scripts/Stories/Escape/top.js | 2 +- scripts/Stories/Escape/tpa.js | 2 +- scripts/Stories/Escape/vanish.js | 4 +- scripts/Stories/Fantasy/rickroll.js | 12 +- scripts/Stories/Fantasy/rottle.js | 20 +- scripts/Stories/Management/ban.js | 27 +- scripts/Stories/Management/rank.js | 55 ++++ scripts/Stories/Management/ranks.js | 28 -- scripts/Stories/Management/tac.js | 23 +- scripts/Stories/ROT/form.js | 2 +- scripts/Stories/ROT/help.js | 61 ++++ scripts/Stories/ROT/{toggle.js => quick.js} | 3 +- scripts/Stories/ROT/setup.js | 13 +- scripts/Stories/Server/broadcast.js | 20 +- scripts/Stories/Server/clearchat.js | 8 +- scripts/Stories/Server/close.js | 3 +- scripts/Stories/Server/members.js | 47 +-- scripts/config.js | 43 ++- scripts/main.js | 99 +++--- 34 files changed, 631 insertions(+), 599 deletions(-) create mode 100644 scripts/Stories/Building/region.js create mode 100644 scripts/Stories/Management/rank.js delete mode 100644 scripts/Stories/Management/ranks.js create mode 100644 scripts/Stories/ROT/help.js rename scripts/Stories/ROT/{toggle.js => quick.js} (95%) diff --git a/manifest.json b/manifest.json index 711d25d..186ca93 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,9 @@ { "format_version": 2, "header": { - "name": "§4§lROT V3 §aPart 1", + "name": "§4§lROT V3 §aPart 2", "description": "§cWelcome to §4§lROT§r§c! §4§lROT§r§c is a Minecraft Bedrock addon designed to make §6§lYOUR§r§c Minecraft server §4§lBETTER§r§c! Remember to use \"§7!help§c\"!", - "uuid": "e61fb559-fe1e-43ff-8da2-74c10de97e81", + "uuid": "62dd78b5-8197-4f8f-97cd-8f1f9ddc4c9f", "version": [ 2, 3, diff --git a/scripts/Papers/CommandPaper/CommandPaper.js b/scripts/Papers/CommandPaper/CommandPaper.js index 395d1d3..d4b229e 100644 --- a/scripts/Papers/CommandPaper/CommandPaper.js +++ b/scripts/Papers/CommandPaper/CommandPaper.js @@ -17,31 +17,42 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ import { Location, world } from '@minecraft/server'; +import { MS, timeRegex } from '../paragraphs/ConvertersParagraphs.js'; import { staticBook, staticValues } from './CommandTypes.js'; -import { lang } from '../LangPaper.js'; import Server from '../../ServerBook.js'; -import quick from '../DatabasePaper.js'; -import { MS, timeRegex } from '../paragraphs/ConvertersParagraphs.js'; +import lang from '../LangPaper.js'; +import quick from '../../main.js'; +import { DatabasePaper } from '../DatabasePaper'; +import { getNameColor, getRanks } from '../paragraphs/ExtrasParagraphs.js'; /** * This is what initiates the commands */ +const ROT = new DatabasePaper('server'); world.events.beforeChat.subscribe(data => { data.cancel = true; if (!data.message.startsWith(quick.prefix)) { - const player = Server.player.paperPlayer(data.sender, { from: 'CHAT' }); + const player = Server.player.paperPlayer(data.sender, { from: 'CHAT' }), time = new Date(); if (data.message.startsWith(quick.prefix)) return player.error(lang.cmd.wrongPrefix); if (data.sender.hasTag('mute')) return player.error(lang.chat.mutted); if (data.message.trim() === '') return; - return data.cancel = false; + if (!ROT.has('setup')) + return data.cancel = false; + const message = data.message.charAt(0).toUpperCase() + data.message.slice(1), rank = `§7[${getRanks(data.sender.name)}§r§7] ${getNameColor(data.sender.name)}`; + let currentHour = time.getUTCHours(), AMPM = ''; + if (currentHour < 0) + currentHour = currentHour + 24; + if (currentHour <= 12) + AMPM = currentHour === 12 ? 'PM' : 'AM', currentHour === 0 ? currentHour = 12 : null; + else + currentHour = currentHour - 12, AMPM = 'PM'; + return Array.from(world.getPlayers()).forEach(plr => plr.tell(`${rank}${data.sender.nameTag}§r§7 ${currentHour}:${time.getUTCMinutes() < 10 ? '0' + time.getUTCMinutes() : time.getUTCMinutes()} ${AMPM}: §f${message}`)); } const args = data.message.slice(quick.prefix.length).trim().split(/\s+/), command = args.shift().toLowerCase(); Server.command.run(command, Server.player.paperPlayer(data.sender, { from: command }), args); }); -export const commands = []; -const endCommand = {}; /* * Welcome to the CommandPaper! * Main Developer: Mo9ses @@ -49,6 +60,12 @@ const endCommand = {}; * Link to name: Command Paper */ export class CommandPaper { + constructor() { + //Defining class varibles + this.list = []; + this.endQueue = {}; + this.forceQueue = {}; + } /** * Creates a command and saves it to memeory * @param info The command meta data @@ -56,18 +73,19 @@ export class CommandPaper { * @returns {command} */ create(info) { - var _a, _b, _c, _d; if (info.name.replace(/[a-zA-Z0-9-_ ]/g, '').length) throw Error(`Cannot create command "${info.name}". Command names cannot have special symbols or characters.`); - if (commands.some(cmd => cmd.name === info.name)) + if (this.list.some(cmd => cmd.name === info.name)) throw Error(`Cannot create command "${info.name}" because there is already a command with that name.`); - return new command({ - name: info.name, - description: (_a = info.description) !== null && _a !== void 0 ? _a : 'Basic command description', - aliases: (_b = info.aliases) !== null && _b !== void 0 ? _b : [], - category: (_c = info.category) !== null && _c !== void 0 ? _c : 'uncategorized', - developers: (_d = info.developers) !== null && _d !== void 0 ? _d : ['Mo9ses'] - }); + if (info.aliases && this.list.some(cmd => cmd.aliases && cmd.aliases.some(a => info.aliases.some(c => a === c)))) + throw Error(`Cannot create command "${info.name}" because there is already a command with that alias.`); + return new command(Object.assign(info, { + name: info.name.toLowerCase(), + description: info.description ?? 'Basic command description', + aliases: info.aliases?.map(a => a.toLowerCase()) ?? [], + category: info.category ? info.category[0].toUpperCase() + info.category.slice(1).toLowerCase() : 'uncategorized', + developers: info.developers ?? ['Mo9ses'] + })); } /** * Formats arguments allow the command builder to read command easier @@ -75,7 +93,6 @@ export class CommandPaper { * @returns {string[]} Args after correction */ parseArgs(args) { - //Check for \" const output = [], quotes = []; args.forEach(a => { if (quotes.length) @@ -107,7 +124,6 @@ export class CommandPaper { * Argument name, value, next args (from player) */ findType(cmd, player, nextArgs, args) { - var _a, _b, _c, _d; for (const a of nextArgs) { if (!['sta', 'dyn'].includes(cmd.aR[a].tY)) continue; @@ -124,7 +140,7 @@ export class CommandPaper { } ; const argTypes = {}; - (_a = nextArgs === null || nextArgs === void 0 ? void 0 : nextArgs.filter(a => !['sta', 'dyn'].includes(cmd.aR[a].tY))) === null || _a === void 0 ? void 0 : _a.forEach(a => Object.assign(argTypes, { [cmd.aR[a].tY]: a })); + nextArgs?.filter(a => !['sta', 'dyn'].includes(cmd.aR[a].tY))?.forEach(a => Object.assign(argTypes, { [cmd.aR[a].tY]: a })); const allTypes = Object.keys(argTypes); if (allTypes.includes('plr')) { if (args[0] === '@s' && cmd.aR[argTypes['plr']].tV[2]) @@ -162,46 +178,22 @@ export class CommandPaper { } if (allTypes.includes('num') && !isNaN(parseInt(args[0]))) return { aRN: argTypes['num'], tV: Number(args[0]), nA: args.slice(1) }; - if (allTypes.includes('tim')) - if (cmd.aR[argTypes['tim']].nA.some(a => cmd.aR[a].tY === 'tim')) { - let time = 0, left = args[0], testing = true; - while (testing) { - const test = (_c = (_b = left[0]) === null || _b === void 0 ? void 0 : _b.match(timeRegex)) === null || _c === void 0 ? void 0 : _c[0]; - if (!test) { - left = left.replace(test, '').trim(); - time = time + MS(test); - continue; - } - else - testing = false; + if (allTypes.includes('tim')) { + let time = 0, left = args[0], testing = true; + while (testing) { + const test = left?.match(timeRegex)?.[0]; + if (test) { + left = left.replace(test, '').trim(); + time = time + MS(test); } - if (left === args[0]) - return { aRN: argTypes['tim'], tV: time, nA: args.slice(1) }; - } - else { - let i = -1, test = true, output = 0; - while (test) { - i = i + 1; - let left = args[i], testing = true; - while (testing) { - const test = (_d = left === null || left === void 0 ? void 0 : left.match(timeRegex)) === null || _d === void 0 ? void 0 : _d[0]; - if (!test) { - left = left.replace(test, '').trim(); - output = output + MS(test); - continue; - } - else - testing = false; - } - if (left === args[i]) - test = false; - } - if (i > -1) - return { aRN: argTypes['tim'], tV: output, nA: args.slice(i + 1) }; + else + testing = false; } + if (left !== args[0]) + return { aRN: argTypes['tim'], tV: time, nA: args.slice(1) }; + } } findExample(type, player) { - var _a, _b, _c, _d; if (!type) return; if (type.tY === 'sta') @@ -211,7 +203,7 @@ export class CommandPaper { if (type.tY === 'plr') return Array.from(world.getPlayers(), plr => plr.nameTag).find(n => n !== player.nameTag) || '@s'; if (type.tY === 'num') - return `${type.tV ? ~~(Math.random() * (((_a = type.tV) === null || _a === void 0 ? void 0 : _a.max) || (((_b = type.tV) === null || _b === void 0 ? void 0 : _b.min) + 5) || 15)) + ((_c = type.tV) === null || _c === void 0 ? void 0 : _c.min) || (((_d = type.tV) === null || _d === void 0 ? void 0 : _d.max) - 5) || -15 : 0}`; + return `${type.tV ? ~~(Math.random() * (type.tV?.max || (type.tV?.min + 5) || 15)) + type.tV?.min || (type.tV?.max - 5) || -15 : 0}`; if (type.tY === 'loc') return '~ ~ ~'; if (type.tY === 'boo') @@ -229,14 +221,16 @@ export class CommandPaper { * @returns {void} */ run(command, player, args) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - const cmd = commands.find(cmd => cmd.name === command || cmd.aliases && cmd.aliases.includes(command)), time = new Date().getTime(); - if (!cmd || !cmd.rM.cM) - return player.error(lang.cmd.unknown, 'ROT'); - if ((cmd.admin && !player.hasTag(quick.adminTag)) || (((_a = cmd.tags) === null || _a === void 0 ? void 0 : _a.length) && !cmd.tags.some(t => player.hasTag(t)))) + const cmd = this.list.find(cmd => cmd.name === command || cmd.aliases && cmd.aliases.includes(command)), time = new Date().getTime(); + if (!cmd) + return player.error(ROT.read('setup') ? lang.cmd.unknown : lang.setup.notSetup, 'ROT'); + if (!cmd.rM.cM) + return player.error(lang.cmd.useForm, 'ROT'); + if (player.isAdmin ? true : cmd.admin || (cmd.tags?.length ? !player.hasTags(cmd.tags) : false)) return player.error(lang.cmd.noPerms, 'ROT'); if (!cmd.sT[0].length && args.length) return player.error(lang.cmd.noArgs, 'ROT'); + // Make this assume @s and ~~~ \/ if (cmd.sT[1] && !args.length) return player.error(lang.cmd.missingArgs(command, args, this.findExample(cmd.aR[cmd.sT[0][0]], player)), 'ROT'); const cls = {}, output = this.parseArgs(args); @@ -248,42 +242,52 @@ export class CommandPaper { fetchCLs = false; if (!fetchCLs) continue; - const nAR = !tries ? cmd.sT[0] : (_b = cmd.aR[Object.keys(cls).reverse()[0]]) === null || _b === void 0 ? void 0 : _b.nA; - if (!(nAR === null || nAR === void 0 ? void 0 : nAR.length) && nextArgs.length) + const nAR = !tries ? cmd.sT[0] : cmd.aR[Object.keys(cls).reverse()[0]]?.nA; + if (!nAR?.length && nextArgs.length) return player.error(lang.cmd.maxArgs(nextArgs[0]), 'ROT'); - const type = this.findType(cmd, player, nAR, nextArgs), arg = (type === null || type === void 0 ? void 0 : type.aRN) ? cmd.aR[type.aRN] : null; + const type = this.findType(cmd, player, nAR, nextArgs), arg = type?.aRN ? cmd.aR[type.aRN] : null; if (!arg) return player.error(lang.cmd.notAArg(command, args.slice(0, args.length - nextArgs.length), nextArgs[0], nextArgs.slice(1).join(' '), this.findExample(cmd.aR[nAR[0]], player)), 'ROT'); if (arg.nN && !type.nA.length) if (cmd.aR[type.aRN].nA.some(a => cmd.aR[a].tY === 'plr' && cmd.aR[a].tV[2])) Object.assign(type, { nA: ['@s'] }); + else if (cmd.aR[type.aRN].nA.some(a => cmd.aR[a].tY === 'loc')) + Object.assign(type, { nA: ['~~~'] }); else return player.error(lang.cmd.missingArgs(command, args, this.findExample(cmd.aR[arg.nA[0]], player))); - if (['dyn', 'sta'].includes(arg.tY) && !((_c = type.tV) === null || _c === void 0 ? void 0 : _c.length) && arg.tV[1]) - return player.error(lang.cmd.needVal(arg.tV[0]), 'ROT'); //Might need fixing - if (arg.tY === 'sta' && ((_e = !((_d = staticBook[arg.tV[0]]) === null || _d === void 0 ? void 0 : _d.con(type.tV))) !== null && _e !== void 0 ? _e : false)) - return player.error((_g = (_f = staticBook[arg.tV[0]]) === null || _f === void 0 ? void 0 : _f.err) !== null && _g !== void 0 ? _g : lang.cmd.valErr(arg.tV[0]), command); - if (((_h = arg.tG) === null || _h === void 0 ? void 0 : _h.length) && !arg.tG.some(t => player.hasTag(t))) + if (['dyn', 'sta'].includes(arg.tY) && !type.tV?.length && arg.tV[1]) + return player.error(lang.cmd.needVal(arg.tV[0]), 'ROT'); + if (arg.tY === 'sta' && (!staticBook[arg.tV[0]]?.con(type.tV) ?? false)) + return player.error(staticBook[arg.tV[0]]?.err ?? lang.cmd.valErr(arg.tV[0]), command); + if (arg.tG?.length && !arg.tG.some(t => player.hasTag(t))) return player.error(lang.cmd.noArgPerm, 'ROT'); - Object.assign(cls, { [type.aRN]: [type.tV, type.nA] }); - //Make timeTye work like "1 day 2 years 5 hours" + Object.assign(cls, { [type.aRN]: type.tV }); nextArgs = type.nA; tries++; } + console.warn(`Operation compeleted in ${new Date().getTime() - time} MS!`); try { + const keys = Object.keys(cls), values = keys.map(k => cls[k]); if (cmd.cB) - cmd.cB(player, args); - (_j = Object.keys(cls)) === null || _j === void 0 ? void 0 : _j.forEach(arg => { - if (!Object.keys(endCommand).includes(cmd.name)) - return cmd.aR[arg].cB ? cmd.aR[arg].cB(player, cls[arg][0], cls[arg][1]) : null; - endCommand[cmd.name](player); - }); + cmd.cB(player, values); + values.splice(0, 1); + if (Object.keys(this.forceQueue).includes(cmd.name)) + cmd.aR[this.forceQueue[cmd.name][0]].cB(player, this.forceQueue[cmd.name][1], []); + for (let i = 0; i < keys.length; i++) { + if (Object.keys(this.endQueue).includes(cmd.name)) + return this.endQueue[cmd.name](player); + if (cmd.aR[keys[i]].cB) + cmd.aR[keys[i]].cB(player, cls[keys[i]], values); + if (Object.keys(this.forceQueue).includes(cmd.name)) + cmd.aR[this.forceQueue[cmd.name][0]].cB(player, this.forceQueue[cmd.name][1], values); + values.splice(0, 1); + } } catch (e) { console.warn(`${e}:${e.stack}`); } - console.warn(`Operation compeleted in ${new Date().getTime() - time} MS!`); - delete endCommand[cmd.name]; + delete this.forceQueue[cmd.name]; + delete this.endQueue[cmd.name]; } /** * Makes a command show up as a FormUI for a player @@ -293,9 +297,8 @@ export class CommandPaper { * @returns {void} */ form(cmd, player) { - var _a; const time = new Date().getTime(); - if ((cmd.admin && !player.hasTag(quick.adminTag)) || (((_a = cmd.tags) === null || _a === void 0 ? void 0 : _a.length) && !cmd.tags.some(t => player.hasTag(t)))) + if ((cmd.admin && !player.hasTag(quick.adminTag)) || (cmd.tags?.length && !cmd.tags.some(t => player.hasTag(t)))) return player.error(lang.cmd.noPerms, 'ROT'); if (!cmd.sT[0].length) return; @@ -316,14 +319,14 @@ export class CommandPaper { //Add bridgeType to the command builder class command { constructor(information) { - commands.push(Object.assign(information, { + Server.command.list.push(Object.assign(information, { sT: [[], false], aR: {}, cB: null, rM: { cM: true, fM: true, tG: true }, })); this.name = information.name; - this.index = commands.findIndex(c => c.name === this.name); + this.index = Server.command.list.findIndex(c => c.name === this.name); } /** * Runs a function if the command is execute successfully (Before the arg callbacks) @@ -332,7 +335,7 @@ class command { * @returns {command} */ callback(callback) { - commands[this.index].cB = callback; + Server.command.list[this.index].cB = callback; return this; } /** @@ -341,7 +344,15 @@ class command { * @returns {void} */ end(callback) { - Object.assign(endCommand, { [this.name]: callback }); + Object.assign(Server.command.endQueue, { [this.name]: callback }); + } + /** + * Force the command builder to run a argument. Remember, this argument will run after the origin has been called + * @param argument The name of the argument + * @param {string} value The value that will the command builder will send to the argument (recommended) + */ + force(argument, value) { + Object.assign(Server.command.forceQueue, { [this.name]: [argument, value] }); } /** * The starting argument(s) for the command. This is required if you have arguments @@ -355,7 +366,7 @@ class command { arg.forEach(a => !test.includes(a) && test.push(a)); if (arg.length !== test.length) throw Error(`Please check your starting args for "${this.name}"!`); - commands[this.index].sT = [arg, needArg !== null && needArg !== void 0 ? needArg : true]; + Server.command.list[this.index].sT = [arg, needArg ?? true]; return this; } /** @@ -367,13 +378,13 @@ class command { * @returns {command} */ relayMethod({ cmd, form, tag }) { - const rM = commands[this.index].rM; + const rM = Server.command.list[this.index].rM; if (cmd !== undefined && rM.cM !== cmd) - commands[this.index].rM.cM = cmd; + Server.command.list[this.index].rM.cM = cmd; if (form !== undefined && rM.fM !== form) - commands[this.index].rM.fM = form; + Server.command.list[this.index].rM.fM = form; if (tag !== undefined && rM.tG !== tag) - commands[this.index].rM.tG = tag; + Server.command.list[this.index].rM.tG = tag; return this; } /** @@ -390,15 +401,15 @@ class command { * @returns {command} */ staticType(name, type, callback, nextArgs, needValue, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add argument "${name}" to "${this.name}". This argument/type already exists!`); const nA = nextArgs ? [nextArgs].flat() : []; - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'sta', - tV: [type, needValue !== null && needValue !== void 0 ? needValue : true], - cB: callback !== null && callback !== void 0 ? callback : null, + tV: [type, needValue ?? true], + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false } }); return this; } @@ -414,14 +425,14 @@ class command { * @returns {command} */ booleanType(name, callback, nextArgs, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add argument "${name}" to "${this.name}". This argument/type already exists!`); const nA = nextArgs ? [nextArgs].flat() : []; - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'boo', - cB: callback !== null && callback !== void 0 ? callback : null, + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false } }); return this; } @@ -438,15 +449,15 @@ class command { * @returns {command} */ locationType(name, callback, nextArgs, loaded, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add argument "${name}" to "${this.name}". This argument/type already exists!`); const nA = nextArgs ? [nextArgs].flat() : []; - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'loc', - tV: loaded !== null && loaded !== void 0 ? loaded : true, - cB: callback !== null && callback !== void 0 ? callback : null, + tV: loaded ?? true, + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false } }); return this; } @@ -463,17 +474,17 @@ class command { * @returns {command} */ numberType(name, callback, nextArgs, data, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add argument "${name}" to "${this.name}". This argument/type already exists!`); if (data && data.min > data.max) throw Error(`Argument "${name}" from command "${this.name}" cannot have a min value greater than the max.`); const nA = nextArgs ? [nextArgs].flat() : []; - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'num', - tV: data !== null && data !== void 0 ? data : null, - cB: callback !== null && callback !== void 0 ? callback : null, + tV: data ?? null, + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false } }); return this; } @@ -491,15 +502,15 @@ class command { * @returns {command} */ playerType(name, callback, online, nextArgs, data, self, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add argument "${name}" to "${this.name}". This argument/type already exists!`); const nA = nextArgs ? [nextArgs].flat() : []; - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'plr', - tV: [data !== null && data !== void 0 ? data : {}, online !== null && online !== void 0 ? online : true, self !== null && self !== void 0 ? self : true], - cB: callback !== null && callback !== void 0 ? callback : null, + tV: [data ?? {}, online ?? true, self ?? true], + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false } }); return this; } @@ -517,7 +528,7 @@ class command { * @returns {command} */ dynamicType(name, data, callback, nextArgs, needValue, length, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add argument "${name}" to "${this.name}". This argument/type already exists!`); const val = [data].flat(); if (val.some(v => staticValues.includes(v))) @@ -525,12 +536,12 @@ class command { const nA = nextArgs ? [nextArgs].flat() : []; if (nA.includes('*') && nA.length > 1) throw Error(`Dynamic argument "${name}" from command "${this.name}" can't take any argument if it has multiple argument aliases`); - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'dyn', - tV: [val, needValue !== null && needValue !== void 0 ? needValue : false, length !== null && length !== void 0 ? length : 0], - cB: callback !== null && callback !== void 0 ? callback : null, + tV: [val, needValue ?? false, length ? 0 : val[0] === '*' ? 30 : 0], + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false, + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false, tG: [] } }); return this; @@ -548,28 +559,28 @@ class command { * @returns {command} */ timeType(name, callback, nextArgs, data, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add argument "${name}" to "${this.name}". This argument/type already exists!`); const nA = nextArgs ? [nextArgs].flat() : []; - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'tim', - tV: data !== null && data !== void 0 ? data : null, - cB: callback !== null && callback !== void 0 ? callback : null, + tV: data ?? null, + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false } }); return this; } teamType(name, argNames, callback, nextArgs, needNextArg) { - if (Object.keys(commands[this.index].aR).includes(name)) + if (Object.keys(Server.command.list[this.index].aR).includes(name)) throw Error(`Failed to add teamType "${name}" to "${this.name}". This argument/type already exists!`); const val = [argNames].flat(), nA = nextArgs ? [nextArgs].flat() : []; - Object.assign(commands[this.index].aR, { [name]: { + Object.assign(Server.command.list[this.index].aR, { [name]: { tY: 'tem', tV: val, - cB: callback !== null && callback !== void 0 ? callback : null, + cB: callback ?? null, nA: nA, - nN: nA.length ? needNextArg !== null && needNextArg !== void 0 ? needNextArg : Boolean(nA === null || nA === void 0 ? void 0 : nA.length) : false, + nN: nA.length ? needNextArg ?? Boolean(nA?.length) : false, tG: [] } }); return this; @@ -583,16 +594,15 @@ class command { argConfig(argNames, info) { const args = [argNames].flat(); args.forEach(a => { - var _a, _b, _c; - const arg = commands[this.index].aR[a], tags = info.tags ? info.tags : (_a = arg === null || arg === void 0 ? void 0 : arg.tG) !== null && _a !== void 0 ? _a : []; + const arg = Server.command.list[this.index].aR[a], tags = info.tags ? info.tags : arg?.tG ?? []; if (info.admin) tags.push(quick.adminTag); if (!arg) throw Error(`Failed editing argument "${a}" from command "${this.name}" because it does not exist!`); - Object.assign(commands[this.index].aR[a], { - nA: (_b = info.nextArgs) !== null && _b !== void 0 ? _b : arg.nA, + Object.assign(Server.command.list[this.index].aR[a], { + nA: info.nextArgs ?? arg.nA, tG: tags, - nN: (_c = info.needNextArgs) !== null && _c !== void 0 ? _c : arg.nN + nN: info.needNextArgs ?? arg.nN }); }); return this; @@ -600,31 +610,4 @@ class command { } /** * Checks ROT command arguments for imperfections - */ -world.events.worldInitialize.subscribe(() => commands.forEach((cmd, i) => { - try { - const length = Object.keys(cmd.aR).length, fakeArgs = cmd.aR; - if (length && !cmd.sT[0].length) - throw Error(`Command "${cmd.name}" has no starting args, but has args.`); - if (!length && cmd.sT[0].length) - throw Error(`Command "${cmd.name}" has starting args, but no args.`); - if (cmd.sT[0].some(a => !cmd.aR.hasOwnProperty(a))) - console.warn(`Some of the starting arguments for the command "${cmd.name}" don't exist!`); - Object.assign(fakeArgs, { '... I mean Starting Arguements': { nA: cmd.sT[0] } }); - for (const arg in fakeArgs) { - if (fakeArgs[arg].nN && !fakeArgs[arg].nA.length) - throw Error(`Argument "${arg}" from command "${cmd.name}" needs next args but, there are no args afther it.`); - const realArgs = fakeArgs[arg].nA.filter(a => cmd.aR.hasOwnProperty(a)); - if (fakeArgs[arg].nA.length !== realArgs.length) - throw Error(`Argument "${arg}" from command "${cmd.name}" is asking for next argument(s) that don't exist!`); - const argTypes = realArgs.map(a => ['sta', 'dyn'].includes(cmd.aR[a].tY) ? '' : cmd.aR[a].tY), test = []; - argTypes.forEach(t => (!test.includes(t) || t === '') && test.unshift(t)); - if (test.length !== argTypes.length) - throw Error(`Argument "${arg}" from command "${cmd.name}" has two of the same types for the next arg!`); - } - } - catch (e) { - console.warn(e); - commands.splice(i, 1); - } -})); + */ diff --git a/scripts/Papers/CommandPaper/CommandTypes.js b/scripts/Papers/CommandPaper/CommandTypes.js index 8bea348..ade275f 100644 --- a/scripts/Papers/CommandPaper/CommandTypes.js +++ b/scripts/Papers/CommandPaper/CommandTypes.js @@ -5,14 +5,26 @@ export const staticBook = { con: (val) => val.replace(/[a-zA-Z0-9-_ ]/g, '') === '', err: 'You cannot use special characters!' }, + delyeet: { + des: 'Deletes stuff', + val: ['delete', 'delyeet', 'd-', 'yeet'], + con: (val) => val.replace(/[a-zA-Z0-9-_ ]/g, '') === '', + err: 'You cannot use special characters!' + }, + add: { + des: 'Adds stuff', + val: ['add', 'a-', 'push'], + con: (val) => val.replace(/[a-zA-Z0-9-_ ]/g, '') === '', + err: 'You cannot use special characters!' + }, remove: { - des: '', - val: ['remove', 'delete', 'd-', 'r-', 'del', 'rem', 're', 'yeet'], + des: 'Removes stuff', + val: ['remove', 'r-', 'rem', 're'], con: (val) => val.replace(/[a-zA-Z0-9-_ ]/g, '') === '', err: 'You cannot use special characters!' }, save: { - des: '', + des: 'Saves stuff?', val: ['save', 's-', 'memory', 'sav'], con: (val) => val.replace(/[a-zA-Z0-9-_ ]/g, '') === '', err: 'You cannot use special characters!' @@ -61,7 +73,7 @@ export const staticBook = { }, try: { des: '', - val: ['try', 'tryo', 't', 'tr'], + val: ['try', 'tryo', 'tr'], con: (val) => val ? val.replace(/[a-zA-Z0-9-_ ]/g, '') === '' : true, err: 'You cannot use special characters!' }, @@ -70,6 +82,24 @@ export const staticBook = { val: ['quit', 'q', 'qu'], con: (val) => val ? val.replace(/[a-zA-Z0-9-_ ]/g, '') === '' : true, err: 'You cannot use special characters!' + }, + set: { + des: '', + val: ['set', 'push', 'put'], + con: (val) => val ? val.replace(/[a-zA-Z0-9-_ ]/g, '') === '' : true, + err: 'You cannot use special characters!' + }, + toggle: { + des: '', + val: ['toggle', 'enable', 'disable', 'on', 'off'], + con: (val) => val ? val.replace(/[a-zA-Z0-9-_ ]/g, '') === '' : true, + err: 'You cannot use special characters!' + }, + rename: { + des: '', + val: ['rename', 'name', 'rn', 'rname'], + con: (val) => val ? val.replace(/[a-zA-Z0-9-_ ]/g, '') === '' : true, + err: 'You cannot use special characters!' } } /* as { [key: string]: { des: string, val: string[], con?: (val: string) => boolean, err?: string }}*/; export const typeBook = {}; diff --git a/scripts/Papers/DatabasePaper.js b/scripts/Papers/DatabasePaper.js index 8b6b0db..243ea36 100644 --- a/scripts/Papers/DatabasePaper.js +++ b/scripts/Papers/DatabasePaper.js @@ -19,13 +19,13 @@ Thank you! import { textToHex, hexToText } from './paragraphs/ConvertersParagraphs.js'; import { world } from '@minecraft/server'; import Server from '../ServerBook.js'; -import config from '../config.js'; /* * Welcome to the DatabasePaper! * Main Developer: Mo9ses * Sub developer: Nobady! * Link to name: Database Paper -*/ +*/ //Don't forget to make the memory release system +const memory = {}; export class DatabasePaper { constructor(table, identifier) { const id = identifier || 'ROT'; @@ -34,21 +34,11 @@ export class DatabasePaper { try { world.scoreboard.addObjective(id + table, ''); } - catch (_a) { } + catch { } ; this.fullName = id + table; this.table = table; - } - /** - * Get key score for a fake player on the database - * @param {string} key The name of the fake player - * @returns {number} A number int - * @example .getScore('ROTidk'); - */ - getScore(key) { - let value = 0; - Server.runCommand(`scoreboard players test "${key}" "${this.fullName}" -1 -1`).catch(e => value = e ? parseInt(e.match(/\d+/)) : 0); - return value; + Object.assign(memory, { [this.fullName]: {} }); } /** * Save a value or update a value in the Database under a key @@ -58,18 +48,14 @@ export class DatabasePaper { * @returns {database} * @example .write('Test Key', 'Test Value'); */ - write(key, value, memoryKey) { - var _a; - let keyLength = this.getScore(key + 'L') + 1, j = 1, data = textToHex(JSON.stringify(value)); - for (let l = 1; l < keyLength; l++) - Server.runCommand(`scoreboard players reset "${key + l}" "${this.fullName}"`); - Server.runCommand(`scoreboard players set "${key}L" "${this.fullName}" ${data.length}`); + write(key, value) { + Object.assign(memory[this.fullName], { [key]: [value, new Date().getTime()] }); + let keyL = world.scoreboard.getObjective(this.fullName).getScores().filter(p => p.participant.displayName.startsWith(key) && p.score != 0).length + 1, j = 1, data = textToHex(JSON.stringify(value)); + for (let l = 1; l < keyL; l++) + Server.commandQueue(`scoreboard players reset "${key + l}" "${this.fullName}"`); for (const hex of data) - Server.runCommand(`scoreboard players set "${key + j}" "${this.fullName}" ${hex}`), j++; - if (!memoryKey) - return this; - if (!((_a = this.read(this.fullName)) === null || _a === void 0 ? void 0 : _a.includes(key))) - this.write(this.fullName, this.has(this.fullName) ? [this.read(this.fullName), key].flat() : [key]); + Server.commandQueue(`scoreboard players set "${key + j}" "${this.fullName}" ${hex}`), j++; + Server.commandQueue(`scoreboard players set "${key}" "${this.fullName}" 0`); return this; } /** @@ -79,21 +65,23 @@ export class DatabasePaper { * @example .get('Test Key'); */ read(key) { - const length = this.getScore(key + 'L') + 1, value = []; - if (length === 1) + if (memory[this.fullName][key]?.[1]) + return memory[this.fullName][key][0]; + const scores = world.scoreboard.getObjective(this.fullName).getScores().filter(p => p.participant.displayName.startsWith(key) && p.score != 0).map(s => [parseInt(s.participant.displayName.replace(key, '')), s.score]).sort((a, b) => a[0] - b[0]).map(s => s[1]); + if (!scores.length) return; - for (let l = 1; l < length; l++) - value.push(this.getScore(key + l)); - return JSON.parse(hexToText(value)); + const parts = JSON.parse(hexToText(scores)); + Object.assign(memory[this.fullName], { [key]: [parts, new Date().getTime()] }); + return parts; } - /**` + /** * Check if the key exists in the table * @param {string} key * @returns {boolean} * @example .has('Test Key'); */ has(key) { - return this.getScore(key + 'L') ? true : false; + return Boolean(this.read(key)); } /** * Delete the key from the table @@ -102,18 +90,11 @@ export class DatabasePaper { * @example .delete('Test Key'); */ delete(key) { - var _a; - let length = this.getScore(key + 'L') + 1; - if (length === 1) - return this; + delete memory[this.fullName][key]; + let length = world.scoreboard.getObjective(this.fullName).getScores().filter(p => p.participant.displayName.startsWith(key)).length + 1; for (let l = 1; l < length; l++) - Server.runCommand(`scoreboard players reset "${key + l}" "${this.fullName}"`); - Server.runCommand(`scoreboard players reset "${key}L" "${this.fullName}"`); - if (!((_a = this.read(this.fullName)) === null || _a === void 0 ? void 0 : _a.includes(key))) - return this; - const MemoryKeys = this.read(this.fullName); - MemoryKeys.splice(MemoryKeys.findIndex(k => k === key), 1); - MemoryKeys.length > 0 ? this.write(this.fullName, MemoryKeys) : this.delete(this.fullName); + Server.commandQueue(`scoreboard players reset "${key + l}" "${this.fullName}"`); + Server.commandQueue(`scoreboard players reset "${key}" "${this.fullName}"`); return this; } /** @@ -122,12 +103,8 @@ export class DatabasePaper { * @example .clear(); */ clear() { - try { - world.scoreboard.removeObjective(this.fullName); - world.scoreboard.addObjective(this.fullName, ''); - } - catch (_a) { } - ; + world.scoreboard.removeObjective(this.fullName); + world.scoreboard.addObjective(this.fullName, ''); return this; } /** @@ -139,15 +116,15 @@ export class DatabasePaper { world.scoreboard.removeObjective(this.fullName); } /** - * Gets all the saved memory keys in the table + * Gets all the keys in the table * @returns {string[]} A array with all the keys * @example .allKeys(); */ allKeys() { - return this.read(this.fullName); + return world.scoreboard.getObjective(this.fullName).getScores().filter(s => s.score === 0).map(n => n.participant.displayName); } /** - * Gets all the saved memory keys in the table then gets their value + * Gets all the of keys in the table then gets their value * @returns {string[]} A array with all the values * @example .allValues(); */ @@ -158,7 +135,7 @@ export class DatabasePaper { return allKeys.map(key => this.read(key)); } /** - * Gets every memory key along their corresponding memory value in the Database + * Gets every key along their corresponding value in the Database * @returns {object} { [key]: value } * @example .getCollection(); */ @@ -170,8 +147,8 @@ export class DatabasePaper { return collection; } /** - * Runs a forEach loop on every memory key in the database - * @param callback The function you want to run on the memory keys + * Runs a forEach loop on every key in the database + * @param callback The function you want to run on the keys * @returns {database} * @example .forEach((key, value) => console.warn(key)); */ @@ -186,8 +163,8 @@ export class DatabasePaper { return this; } /** - * Re-maps every memory key in the database - * @param callback The function you want to run on the memory keys + * Re-maps every key in the database + * @param callback The function you want to run on the keys * @returns {database} * @example .forEach((key, value) => { key, value + 1 }); */ @@ -205,21 +182,10 @@ export class DatabasePaper { const oldKey = Object.keys(then)[i]; if (v[0] != oldKey) { this.delete(oldKey); - return this.write(v[0], v[1], true); + return this.write(v[0], v[1]); } - return this.write(oldKey, v[1], true); + return this.write(oldKey, v[1]); }); return this; } } -/** - * Quick - * This handles in game configuration - */ -const quick = config; -export default quick; -world.events.worldInitialize.subscribe(() => { - const config = new DatabasePaper('config'); - if (!config.has('written')) { - } -}); diff --git a/scripts/Papers/FormPaper.js b/scripts/Papers/FormPaper.js index bfdd30d..4ec354b 100644 --- a/scripts/Papers/FormPaper.js +++ b/scripts/Papers/FormPaper.js @@ -34,7 +34,7 @@ export class ActionForm { * @returns {void} */ addButton(text, iconPath) { - this.form.button(text, iconPath !== null && iconPath !== void 0 ? iconPath : undefined); + this.form.button(text, iconPath ?? undefined); } /** * @function send The sends the UI to a member @@ -142,7 +142,7 @@ export class ModalForm { * @returns {void} */ addInput(label, placeHolderText, defaultValue) { - this.form.textField(label, placeHolderText, defaultValue !== null && defaultValue !== void 0 ? defaultValue : ''); + this.form.textField(label, placeHolderText, defaultValue ?? ''); } /** * @function addDropdown Make a drop down menu to the form @@ -153,7 +153,7 @@ export class ModalForm { * @returns {void} */ addDropdown(label, options, defaultValueIndex) { - this.form.dropdown(label, options, defaultValueIndex !== null && defaultValueIndex !== void 0 ? defaultValueIndex : 0); + this.form.dropdown(label, options, defaultValueIndex ?? 0); } /** * @function addSlider Add a slider that will sliiiiiiiiiiiiide on the fooooooorm! @@ -168,7 +168,7 @@ export class ModalForm { addSlider(label, minimumValue, maximumValue, valueStep, defaultValue) { if (minimumValue >= maximumValue) throw new Error('[Forms UI Silder] Error - the Min value cannot be greater than the Max value'); - this.form.slider(label, minimumValue, maximumValue, valueStep !== null && valueStep !== void 0 ? valueStep : 1, defaultValue !== null && defaultValue !== void 0 ? defaultValue : ~~(maximumValue / minimumValue)); + this.form.slider(label, minimumValue, maximumValue, valueStep ?? 1, defaultValue ?? ~~(maximumValue / minimumValue)); } /** * @function addToggle Adds a on/off button to the form @@ -178,7 +178,7 @@ export class ModalForm { * @returns {void} */ addToggle(label, defaultValue) { - this.form.toggle(label, defaultValue !== null && defaultValue !== void 0 ? defaultValue : false); + this.form.toggle(label, defaultValue ?? false); } /** * @function send The sends the UI to a member diff --git a/scripts/Papers/LangPaper.js b/scripts/Papers/LangPaper.js index 0330442..054e0d7 100644 --- a/scripts/Papers/LangPaper.js +++ b/scripts/Papers/LangPaper.js @@ -1,4 +1,22 @@ -import quick from './DatabasePaper'; +/* +ROT Developers and Contributors: +Moises (OWNER/CEO/Developer), +Aex66 (Developer) +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +__________ ___________________ +\______ \\_____ \__ ___/ + | _/ / | \| | + | | \/ | \ | + |____|_ /\_______ /____| + \/ \/ +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! +Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S +Website: https://www.rotmc.ml +Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg +Thank you! +*/ +import quick from '../main.js'; /* * Welcome to the Lang Paper! * Main Translater: Google Translate XD @@ -6,22 +24,31 @@ import quick from './DatabasePaper'; * Notes: This file is ment to pull the IPs, gamertags, and realm codes of the people that use ROT. * Sub developer: NOBODY! */ -export const lang = { +const Lang = {}; +export const startLang = () => Object.assign(Lang, { + setup: { + version: '§bROT Version: §1V3 part 2, Light!§b, Min Engine: §11.19.40§b\nAPI: §bQROT Light§b,\nBETA: §1YES§b, ROTJ: §1NO§1\nCoded and Designed By Mo9ses, Copyright 2021-2022 all rights reserved.', + notSetup: `Please type "§e/tag @s add ${quick.adminTag}§1" in chat to verify that you are a admin, then type "§3!setup§1" in chat to setup ROT!`, + setup: 'Setting up ROT...\n§3Looking for older ROT settings...\nAdding Databases...\nImporting commands...\nImporting OTHER features...\nImporting ROT Things ig...\n§aDone!', + loaded: (ms) => `ROT has been loaded in ${ms} milliseconds!`, + }, cmd: { - unknown: `Unknown command! Make sure you have permission to use that command and make sure you spelt it correctly. Type "§7${quick.prefix}help§c" in chat for a list of available commands${quick.hideAdminTag ? '.' : `, or run the command "§7/tag @s add ${quick.adminTag}§c" to verify that your are a admin then try doing the command again.`}`, - wrongPrefix: `Sorry, the prefix on this server is now "§7${quick.prefix}§c"`, + unknown: `Unknown command! Make sure you have permission to use that command and make sure you spelt it correctly. Type "§3${quick.prefix}help§1" in chat for a list of available commands${quick.hideAdminTag ? '.' : `, or run the command "§3/tag @s add ${quick.adminTag}§1" to verify that your are a admin then try doing the command again.`}`, + useForm: 'This command cannot be execute in chat. Use "§3!ui§1" to run it as a form command.', + wrongPrefix: `Sorry, the prefix on this server is now "§3${quick.prefix}§1"`, noArgs: 'This commands does not have any arguments! You only need to type the command.', - notAArg: (cmd, before, err, afther, tip) => `Not sure what you mean by "§7${quick.prefix + cmd}${before.length ? ` ${before.join(' ')}` : ''}§r §4§l${err}§r§7${afther ? ` §e${afther}` : ''}§r§c". §4§l${err[0].toUpperCase() + err.slice(1)}§r§c is not a vaild argument.${tip ? ` Maybe try typing §a${tip}§c?` : ''}`, + notAArg: (cmd, before, err, afther, tip) => `Not sure what you mean by "§3${quick.prefix + cmd}${before.length ? ` ${before.join(' ')}` : ''}§r §b${err}§r§3${afther ? ` §e${afther}` : ''}§r§1". §b${err[0].toUpperCase() + err.slice(1)}§r§1 is not a vaild argument.${tip ? ` Maybe try typing §a${tip}§1?` : ''}`, noPerms: 'You do not have permission to execute this command.', noArgPerm: 'You do not have permission to execute this argument. How do you even know about it?', - missingArgs: (cmd, args, tip) => `The command you typed: "§7${quick.prefix + cmd}${args.length ? ' ' + args.join(' ') : ''}§c" is missing arguments!${tip ? ` Maybe try typing §a${tip}§c at the end.` : ''} If you need more help, type "§6${quick.prefix}help ${cmd}§c" in chat :)`, - maxArgs: (error) => `You typed too many arguments! Try removing "§4${error}§r§c".`, - needVal: (val) => `You need to type a name! If you need more help, type "§6${quick.prefix}help ${val}§c" in chat.`, - valErr: (val) => `The value you typed in is incorrect. If you need more help, type "§6${quick.prefix}help ${val}§c" in chat.`, + missingArgs: (cmd, args, tip) => `The command you typed: "§3${quick.prefix + cmd}${args.length ? ' ' + args.join(' ') : ''}§1" is missing arguments!${tip ? ` Maybe try typing §a${tip}§1 at the end.` : ''} If you need more help, type "§3${quick.prefix}help ${cmd}§1" in chat :)`, + maxArgs: (error) => `You typed too many arguments! Try removing "§b${error}§r§1".`, + needVal: (val) => `You need to type a name! If you need more help, type "§3${quick.prefix}help ${val}§1" in chat.`, + valErr: (val) => `The value you typed in is incorrect. If you need more help, type "§3${quick.prefix}help ${val}§1" in chat.`, openQou: `It seems like you have open quotes somewhere. Make sure to close them!`, - missingPlr: (val) => `You need to type a player's name. Did you mean to type "§e${val}§c"?`, + missingPlr: (val) => `You need to type a player's name. Did you mean to type "§e${val}§1"?`, }, chat: { mutted: 'Sorry, you have been muted by ROT or an admin', } -}; +}); +export default Lang; diff --git a/scripts/Papers/PlayerPaper.js b/scripts/Papers/PlayerPaper.js index 4be1e8a..9671eb6 100644 --- a/scripts/Papers/PlayerPaper.js +++ b/scripts/Papers/PlayerPaper.js @@ -10,52 +10,55 @@ __________ ___________________ |____|_ /\_______ /____| \/ \/ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! +© Copyright 2022 all rights reserved by Mo9seServer. Do NOT steal, copy the code, or claim it as yours! Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S Website: https://www.rotmc.ml -Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg +Docs: https://docServer.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg Thank you! */ -import { world, Player, BlockRaycastOptions, Location } from '@minecraft/server'; +import { world, Player, Location } from '@minecraft/server'; import { DatabasePaper } from './DatabasePaper.js'; -import quick from './DatabasePaper.js'; import { MessageForm } from './FormPaper.js'; -import { ServerPaper } from './ServerPaper.js'; -const playerData = {}, cache = {}, s = new ServerPaper(); +import quick from '../main.js'; +const playerData = {}, cache = {}; export class PlayerPaper { paperPlayer(player, data) { const plr = player instanceof Player ? player : Array.from(world.getPlayers()).find(p => p.nameTag.toLowerCase() === player.toLowerCase()); if (!player) return; - // @ts-ignore parseInt(hexString, 16); - const db = new DatabasePaper(player.id.toString(16).toUpperCase(), 'PLR'); + data.from = data.from[0].toUpperCase() + data.from.slice(1); + // @ts-ignore + const db = new DatabasePaper(plr.id.toString(16).toUpperCase(), 'PLR'); return Object.assign(player, { isAdmin: plr.hasTag(quick.adminTag), - write: (key, value, memoryKey) => { + write: (key, value) => { Object.assign(cache[plr.nameTag], { [key]: value }); - db.write(key, value, memoryKey); + db.write(key, value); }, - read: (key) => { var _a, _b; return (_b = (_a = cache[plr.nameTag]) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : db.read(key); }, + read: (key) => cache[plr.nameTag]?.[key] ?? db.read(key), delete: (key) => { db.delete(key); delete cache[plr.nameTag][key]; }, send: (msg, from) => { - var _a; - s.broadcast(msg, plr.nameTag, (_a = from !== null && from !== void 0 ? from : data.from) !== null && _a !== void 0 ? _a : undefined); + plr.runCommandAsync('playsound random.toast @s ~~~ 1 0.5'); + plr.tell({ 'rawtext': [{ 'text': `§l§3${from ? `${from} ` : data.from ? `${data.from} ` : ''}§3>>§r§1 ` }, { 'text': msg }] }); + }, + tip: (msg, from) => { + plr.runCommandAsync('playsound random.toast @s ~~~ 1 0.5'); + plr.tell({ 'rawtext': [{ 'text': `§l§1${from ? `${from} ` : data.from ? `${data.from} ` : ''}§aTIP §3>>§r§1 ` }, { 'text': msg }] }); }, error: (msg, from) => { - var _a; - s.eBroadcast(msg, plr.nameTag, (_a = from !== null && from !== void 0 ? from : data.from) !== null && _a !== void 0 ? _a : undefined); + plr.runCommandAsync('playsound random.glass @s ~~~ 1 0.5'); + plr.tell({ 'rawtext': [{ 'text': `§l§1${from ? `${from} ` : data.from ? `${data.from} ` : ''}§3Error >>§r§1 ` }, { 'text': msg }] }); }, UIerror: (msg, buttons, from) => { - var _a, _b, _c; const UI = new MessageForm(); let val = false; - UI.setTitle(`${(_a = from !== null && from !== void 0 ? from : `§c§l${data.from} Error`) !== null && _a !== void 0 ? _a : '§c§lError!'}`); + UI.setTitle(`${from ?? `§c§l${data.from} Error` ?? '§c§lError!'}`); UI.setBody(`§c${msg}`); - UI.setButton1((_b = buttons[0]) !== null && _b !== void 0 ? _b : '§e§lTry again'); - UI.setButton1((_c = buttons[1]) !== null && _c !== void 0 ? _c : '§c§lClose'); + UI.setButton1(buttons[0] ?? '§e§lTry again'); + UI.setButton1(buttons[1] ?? '§c§lClose'); UI.send(plr, res => val = Boolean(res.selection)); return val; }, @@ -67,15 +70,17 @@ export class PlayerPaper { getScore: (obj) => { return world.scoreboard.getObjective(obj).getScore(plr.scoreboard); }, + hasTags: (tags) => { + let all = true; + tags.forEach(t => !plr.hasTag(t) && (all = false)); + return all; + }, veiwLocation: (dist) => { const l = plr.viewVector; return new Location(l.x, l.y, l.z); }, veiwBlock: (getBlock) => { - const r = new BlockRaycastOptions(); - r.includeLiquidBlocks = true; - r.maxDistance = 300; - const l = plr.getBlockFromViewVector(r); + const l = plr.getBlockFromViewVector({ includeLiquidBlocks: true, maxDistance: 300 }); return getBlock ? l : [l.x, l.y, l.z]; }, veiwEntity: (getPos) => { @@ -87,8 +92,8 @@ export class PlayerPaper { offlinePlayer(name, from, player) { return { nameTag: name, - send: (msg, frm) => { var _a; return s.broadcast(msg, name, (_a = frm !== null && frm !== void 0 ? frm : from) !== null && _a !== void 0 ? _a : undefined); }, - error: (msg, frm) => { var _a; return s.broadcast(msg, name, (_a = frm !== null && frm !== void 0 ? frm : from) !== null && _a !== void 0 ? _a : undefined); }, + // send: (msg: string, frm?: string) => Server.broadcast(msg, name, frm ?? from ?? undefined), + // error: (msg: string, frm?: string) => Server.broadcast(msg, name, frm ?? from ?? undefined), }; } } diff --git a/scripts/Papers/ServerPaper.js b/scripts/Papers/ServerPaper.js index 952455e..dc086b2 100644 --- a/scripts/Papers/ServerPaper.js +++ b/scripts/Papers/ServerPaper.js @@ -17,6 +17,24 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ import { world } from '@minecraft/server'; +import { PlayerPaper } from './PlayerPaper.js'; +import { setTickInterval } from './paragraphs/ExtrasParagraphs.js'; +/* + * ROT's command queue system +*/ +const commandQueue = []; +setTickInterval(() => { + if (!commandQueue.length) + return; + const hundred = commandQueue.slice(0, 100); + commandQueue.splice(0, 100); + for (let i = 0; i < 100; i++) { + if (!hundred[i]) + return; + world.getDimension(hundred[i][1] ?? 'overworld').runCommandAsync(hundred[i][0]).catch(); + } +}, 5); +const paperPlayer = new PlayerPaper().paperPlayer; /* * Welcome to the Server Paper! * Main Developer: notbeer @@ -26,85 +44,36 @@ import { world } from '@minecraft/server'; */ export class ServerPaper { /** - * Broadcast a message in chat - * @param {string} text Message you want to broadcast in chat - * @param {string} player Player you want to broadcast to - * @param {string} use What command is the player using - * @param {boolean} console - * @returns {runCommandReturn} - * @example .broadcast('Hello World!', 'Mo9ses', 'Computer', false); - */ - broadcast(text, player, use, console) { - if (!use || use == '') - use = ''; - else - use = use.toUpperCase() + ' '; - if (console === false) - use = ''; - else - use = `§l§4${use}§7>>§r§7 `; - if (player) - if (player.startsWith('@')) - null; - else if (player.startsWith('"')) - null; - else - player = `"${player}"`; - else - player = '@a'; - this.runCommands([ - `execute ${console ? player : ''} ~~~ playsound random.toast @s ~~~ 1 0.5`, - `execute ${player} ~~~ tellraw @s {"rawtext":[{"text":"${use}"},{"text":${JSON.stringify(text)}}]}` - ]); - } - /** - * Broadcast a tip in chat to suggest something the player should do - * @param {string} text The "tip" you want to broadcast in chat - * @param {string} player Player you want to a error broadcast to - * @param {string} use What command is the player using - * @returns {runCommandReturn} - * @example .tBroadcast('Use ROT... Your players will thank you!', 'Mo9ses', 'ROT'); + * Broadcast a message to everyone in game + * @param {string} message Message you want to broadcast in chat + * @param {string} use The name of the use? + * @returns {void} Nothing + * @example .broadcast('Hello World!', 'Computer'); */ - tBroadcast(text, player, use) { - if (!use) - use = ''; - else - use = use.toUpperCase() + ' '; - this.runCommands([ - `execute ${player ? `"${player}"` : '@a'} ~~~ playsound random.toast @s ~~~ 1 0.5`, - `execute ${player ? `"${player}"` : '@a'} ~~~ tellraw @s {"rawtext":[{"text":"§l§c${use}§aTIP §e>>§r§e "},{"text":${JSON.stringify(text)}}]}` - ]); + broadcast(message, use) { + Array.from(world.getPlayers(), p => paperPlayer(p)).forEach(p => p.send(message, use)); } /** - * Broadcast a ERROR message in chat - * @param {string} text The error message you want to broadcast in chat - * @param {string} player Player you want to a error broadcast to - * @param {string} use What command is the player using - * @returns {runCommandReturn} - * @example .eBroadcast('Task failed!', 'Mo9ses', 'Task name'); - */ - eBroadcast(text, player, use) { - if (!use) - use = ''; - else - use = use.toUpperCase() + ' '; - this.runCommands([ - `execute ${player ? `"${player}"` : '@a'} ~~~ playsound random.glass @s ~~~ 1 0.5`, - `execute ${player ? `"${player}"` : '@a'} ~~~ tellraw @s {"rawtext":[{"text":"§l§c${use}§4Error §c>>§r§c "},{"text":${JSON.stringify(text)}}]}` - ]); + * Push commands to the command queue + * @param command The command you want to run + * @param dimension The dimension you want the command run + * @returns {void} Nothing + * @example .commandQueue('say Hello World!'); + */ + commandQueue(command, dimension) { + commandQueue.push(dimension ? [command, dimension] : [command]); } /** - * Run a command in game + * Run a asynchronous command in game that will run at runtime * @param command The command you want to run * @param dimension The dimension you want the command run - * @returns {runCommandReturn} - * @example .runCommand('say Hello World!'); + * @returns {string} command had error + * @example .runAsyncCMD('say Hello World!'); */ async runCommand(command, dimension) { - try { - return await world.getDimension(dimension !== null && dimension !== void 0 ? dimension : 'overworld').runCommandAsync(command); - } - catch (e) { } + let value = ''; + await world.getDimension(dimension ?? 'overworld').runCommandAsync(command).catch(e => value = e); + return value; } /** * Run an array of commands @@ -120,11 +89,10 @@ export class ServerPaper { if (conditionalRegex.test(commands[0])) throw '§l§c>>§r§4: runCommands(): Error - First command in the Array CANNOT be Conditional'; let e = false; - commands.forEach(cmd => { + commands.forEach(async (cmd) => { if (e && conditionalRegex.test(cmd)) return; - // @ts-ignore - e = this.runCommand(cmd.replace(conditionalRegex, '')).error; + e = Boolean(await this.runCommand(cmd.replace(conditionalRegex, ''))); }); return { error: e }; } diff --git a/scripts/Papers/paragraphs/ExtrasParagraphs.js b/scripts/Papers/paragraphs/ExtrasParagraphs.js index 98eda16..9e1ca53 100644 --- a/scripts/Papers/paragraphs/ExtrasParagraphs.js +++ b/scripts/Papers/paragraphs/ExtrasParagraphs.js @@ -17,14 +17,13 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ import { world } from '@minecraft/server'; -import { DatabasePaper } from '../DatabasePaper.js'; import { MS } from './ConvertersParagraphs.js'; -import config from '../../config.js'; +import config from '../../main.js'; import Server from '../../ServerBook.js'; /** * Defines: */ -const tickTimeoutMap = new Map(), tickIntervalMap = new Map(), plots = new DatabasePaper('PL'); +const tickTimeoutMap = new Map(), tickIntervalMap = new Map(); let totalTick = 0, tickIntervalID = 0; world.events.tick.subscribe(() => { totalTick++; @@ -52,9 +51,8 @@ world.events.tick.subscribe(() => { * @example getRanks(Mo9ses); */ export const getRanks = (player) => { - var _a; - const ranks = (_a = Array.from(world.getPlayers()).find(n => n.name.toLowerCase() === player.toLowerCase()).getTags()) === null || _a === void 0 ? void 0 : _a.filter(tag => tag.startsWith('rank:')); - return (ranks === null || ranks === void 0 ? void 0 : ranks[0]) ? ranks.map(c => c.replace('rank:', '').trim()) : [config.defaultRank]; + const ranks = Array.from(world.getPlayers()).find(n => n.name.toLowerCase() === player.toLowerCase()).getTags()?.filter(tag => tag.startsWith('rank:')); + return ranks?.[0] ? ranks.map(c => c.replace('rank:', '').trim()) : [config.defaultRank]; }, /** * @function getColors Gets the color of a player @@ -62,16 +60,15 @@ export const getRanks = (player) => { * @example getColor(Mo9ses); */ getNameColor = (player) => { - var _a; - const colors = (_a = Array.from(world.getPlayers()).find(n => n.name.toLowerCase() === player.toLowerCase()).getTags()) === null || _a === void 0 ? void 0 : _a.filter(tag => tag.startsWith('colors:')); - return (colors === null || colors === void 0 ? void 0 : colors[0]) ? colors.map(c => c.replace('rank:', '').trim()) : [config.defaultNameColor]; + const colors = Array.from(world.getPlayers()).find(n => n.name.toLowerCase() === player.toLowerCase()).getTags()?.filter(tag => tag.startsWith('colors:')); + return colors?.[0] ? colors.map(c => c.replace('rank:', '').trim()) : [config.defaultNameColor]; }, /** * @function getChat Gets the chat color of a player * @param {string} player the player * @example getChat(Mo9ses); */ -getChat = (player) => { var _a, _b, _c; return config.defaultChatColor + ((_c = (_b = (_a = Array.from(world.getPlayers()).find(n => n.name.toLowerCase() === player.toLowerCase()).getTags()) === null || _a === void 0 ? void 0 : _a.filter(tag => tag.startsWith('chat:'))) === null || _b === void 0 ? void 0 : _b.map(color => color.replace('chat:', '').trim()).join('')) !== null && _c !== void 0 ? _c : ''); }, +getChat = (player) => config.defaultChatColor + (Array.from(world.getPlayers()).find(n => n.name.toLowerCase() === player.toLowerCase()).getTags()?.filter(tag => tag.startsWith('chat:'))?.map(color => color.replace('chat:', '').trim()).join('') ?? ''), /** * @function updateLeaderboard Update the leaderboard of an entity * @param {Entity} lb The Minecraft entity @@ -103,46 +100,7 @@ getChat = (player) => { var _a, _b, _c; return config.defaultChatColor + ((_c = // saveData = saveData ? `§${saveData.replace(/\s*$/, '').split('').join('§')}` : ''; // lb.nameTag = leaderboardString + saveData; // } catch {} -// }, -/** - * Saves all the plots that a members' UUID holds - * @param {number} playerUUID The ROT UUID of the player - * @returns {void} - * @example deletePlot(29223); - */ -savePlot = (playerUUID, plotTag) => { - var _a, _b; - return (_b = (_a = plots.allValues()) === null || _a === void 0 ? void 0 : _a.filter(plot => { var _a; return (_a = plotTag === null || plotTag === void 0 ? void 0 : plotTag.includes(plot.tag)) !== null && _a !== void 0 ? _a : true; })) === null || _b === void 0 ? void 0 : _b.forEach(plot => { - if (!plot.enabled || !plots.has('p-' + plot.id + '-' + playerUUID)) - return; - const id = plots.read('p-' + plot.id + '-' + playerUUID).id, row = plot.rowSize >= 2 ? ~~(id / plot.rowSize) : 0, coords = plot.distance.map((pos, i) => plot.startingCoords[i] + (row >= 1 ? plot.nextRow[i] * row : 0) + (pos * (id - 1))); - Server.runCommand(`structure save "${plot.id + '-' + playerUUID}" ${coords.join(' ')} ${coords[0] + plot.savingDistance[0]} ${coords[1] + plot.savingDistance[1]} ${coords[2] + plot.savingDistance[2]} disk`); - }); -}, -/** - * Deletes all the plots that a members' UUID holds - * @param {number} playerUUID The ROT UUID of the player - * @param {string[]} plotTag The tag of the plot - * @returns {void} - * @example deletePlot(09822); - */ -deletePlot = (playerUUID, plotTag) => { - var _a, _b; - return (_b = (_a = plots.allValues()) === null || _a === void 0 ? void 0 : _a.filter(plot => { var _a; return (_a = plotTag === null || plotTag === void 0 ? void 0 : plotTag.includes(plot.tag)) !== null && _a !== void 0 ? _a : true; })) === null || _b === void 0 ? void 0 : _b.forEach(plot => { - if (!plot.enabled || !plots.has('p-' + plot.id + '-' + playerUUID)) - return; - const id = plots.read('p-' + plot.id + '-' + playerUUID).id, row = plot.rowSize >= 2 ? ~~(id / plot.rowSize) : 0; - let coords = plot.distance.map((pos, i) => plot.startingCoords[i] + (row >= 1 ? plot.nextRow[i] * row : 0) + (pos * (id - 1))); - coords.push(coords[0] + plot.savingDistance[0], coords[1] + plot.savingDistance[1], coords[2] + plot.savingDistance[2]); - Server.runCommand(`tickingarea add ${coords.join(' ')} "ROTplotSystems-${plot.id}-${id}"`); - const neg = plot.savingDistance[1] < 0 ? true : false, yLevel = Math.abs(coords[1]) + Math.abs(plot.savingDistance[1]); - for (let l = Math.abs(coords[1]); l <= yLevel; l++) - Server.runCommand(`fill ${coords[0]} ${neg ? -l : l} ${coords.slice(2, 4).join(' ')} ${neg ? -l : l} ${coords[5]} air 0`); - if (plot.resetArea) - Server.runCommand(`structure load ${plot.structure} ` + coords.slice(-3).join(' ')); - Server.runCommand(`tickingarea remove "ROTplotSystems-${plot.id}-${id}"`); - }); -}, +// } /** * Compare a array of numbers with 2 arrays * @param {number[]} XYZa The first set of numbers @@ -162,7 +120,7 @@ betweenXYZ = (XYZa, XYZb, XYZc) => XYZc.length === XYZc.filter((c, i) => (c >= M twoStepKick = (player, banData) => { // @ts-ignore if (banData) - Server.runCommand(`kick "${player.nameTag}" §r\n§cYou have been banned for §a${MS(banData === null || banData === void 0 ? void 0 : banData.time)}§c from this server at §b${banData === null || banData === void 0 ? void 0 : banData.date}${(banData === null || banData === void 0 ? void 0 : banData.reason) ? `\n§7Reason: §r${banData === null || banData === void 0 ? void 0 : banData.reason}` : ''}§7. You will be unbanned in ${MS((banData === null || banData === void 0 ? void 0 : banData.unbanTime) - new Date().getTime())}`); + Server.runCommand(`kick "${player.nameTag}" §r\n§cYou have been banned for §a${MS(banData?.time)}§c from this server at §b${banData?.date}${banData?.reason ? `\n§7Reason: §r${banData?.reason}` : ''}§7. You will be unbanned in ${MS(banData?.unbanTime - new Date().getTime())}`); player.triggerEvent('ROT:kick'); }, /** @@ -193,7 +151,7 @@ setTickInterval = (handler, timeout, ...args) => { */ export const kick = (player, message = [], onFail) => { try { - player.runCommand(`kick @s §r${message.join("\n")}`); + player.runCommandAsync(`kick @s §r${message.join("\n")}`); player.triggerEvent("ROT:kick"); } catch (error) { diff --git a/scripts/Stories/Building/region.js b/scripts/Stories/Building/region.js new file mode 100644 index 0000000..e69de29 diff --git a/scripts/Stories/Escape/feed.js b/scripts/Stories/Escape/feed.js index 9a95a30..8297936 100644 --- a/scripts/Stories/Escape/feed.js +++ b/scripts/Stories/Escape/feed.js @@ -18,8 +18,8 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ import { MinecraftEffectTypes } from '@minecraft/server'; -import quick from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; +import quick from '../../main.js'; const cmd = Server.command.create({ name: 'feed', description: `When you type ${quick.prefix}feed in chat... I'll feed you`, diff --git a/scripts/Stories/Escape/heal.js b/scripts/Stories/Escape/heal.js index 9cbbad0..9034a83 100644 --- a/scripts/Stories/Escape/heal.js +++ b/scripts/Stories/Escape/heal.js @@ -18,8 +18,8 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ import { MinecraftEffectTypes } from '@minecraft/server'; -import quick from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; +import quick from '../../main.js'; const cmd = Server.command.create({ name: 'heal', description: `When you type ${quick.prefix}feed in chat... I'll heal you`, diff --git a/scripts/Stories/Escape/home.js b/scripts/Stories/Escape/home.js index 4cf6cee..a779dff 100644 --- a/scripts/Stories/Escape/home.js +++ b/scripts/Stories/Escape/home.js @@ -19,7 +19,7 @@ Thank you! */ /** import { world, Location } from '@minecraft/server'; -import config from '../../config.js'; +import config from '../../main.js'; import quick from '../../Papers/DatabasePaper.js'; import { hexToText, textToHex } from '../../Papers/paragraphs/ConvertersParagraphs.js'; import Server from '../../ServerBook.js'; diff --git a/scripts/Stories/Escape/kill.js b/scripts/Stories/Escape/kill.js index 469fe88..f2580d4 100644 --- a/scripts/Stories/Escape/kill.js +++ b/scripts/Stories/Escape/kill.js @@ -18,8 +18,8 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ import { MinecraftEffectTypes } from '@minecraft/server'; -import quick from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; +import quick from '../../main.js'; const cmd = Server.command.create({ name: 'kill', description: `When you type ${quick.prefix}kill in chat... I'll kill you!`, diff --git a/scripts/Stories/Escape/repair.js b/scripts/Stories/Escape/repair.js index 9a4ca72..f69b352 100644 --- a/scripts/Stories/Escape/repair.js +++ b/scripts/Stories/Escape/repair.js @@ -93,16 +93,17 @@ const cmd = Server.command.create({ }); cmd.startingArgs(['slot', 'all']); cmd.dynamicType('slot', ['slot', 'hand'], (plr) => { - var _a, _b, _c, _d, _e, _f; + // @ts-ignore const inventory = plr.getComponent('minecraft:inventory').container; - const item = inventory.getItem(plr.selectedSlot), itemName = (_f = (_e = (_d = (_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.typeId) === null || _a === void 0 ? void 0 : _a.match(/:([\s\S]*)$/)[1]) === null || _b === void 0 ? void 0 : _b.replace(/[\W]/g, ' ')) === null || _c === void 0 ? void 0 : _c.replaceAll('_', ' ')) === null || _d === void 0 ? void 0 : _d.split(' ')) === null || _e === void 0 ? void 0 : _e.map((w) => { var _a; return ((_a = w === null || w === void 0 ? void 0 : w.charAt(0)) === null || _a === void 0 ? void 0 : _a.toUpperCase()) + (w === null || w === void 0 ? void 0 : w.slice(1)); })) === null || _f === void 0 ? void 0 : _f.join(' '); - if (!item || !repairables.includes(item === null || item === void 0 ? void 0 : item.typeId)) + const item = inventory.getItem(plr.selectedSlot), itemName = item?.typeId?.match(/:([\s\S]*)$/)[1]?.replace(/[\W]/g, ' ')?.replaceAll('_', ' ')?.split(' ')?.map((w) => w?.charAt(0)?.toUpperCase() + w?.slice(1))?.join(' '); + if (!item || !repairables.includes(item?.typeId)) return plr.send('You cannot repair this item!', 'REPAIR'); plr.send(`You have successfully repaired your §c${itemName}§a§8!`, 'REPAIR'); inventory.setItem(plr.selectedSlot, newItem(item)); }, null, false); cmd.dynamicType('all', ['all', 'many', 'more'], (plr) => { let count = 0; + // @ts-ignore const inventory = plr.getComponent('inventory').container; for (let i = 0; i < inventory.size; i++) { const item = inventory.getItem(i); diff --git a/scripts/Stories/Escape/top.js b/scripts/Stories/Escape/top.js index ee1eea3..d7ceecc 100644 --- a/scripts/Stories/Escape/top.js +++ b/scripts/Stories/Escape/top.js @@ -17,8 +17,8 @@ Website: https://www.rotmc.ml Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg Thank you! */ -import quick from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; +import quick from '../../main.js'; const cmd = Server.command.create({ name: 'top', description: `When you type ${quick.prefix}top in chat... I'll teleport you to the highest point above your player!`, diff --git a/scripts/Stories/Escape/tpa.js b/scripts/Stories/Escape/tpa.js index 6349229..01d4308 100644 --- a/scripts/Stories/Escape/tpa.js +++ b/scripts/Stories/Escape/tpa.js @@ -18,7 +18,7 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ /** -import config from '../../config.js'; +import config from '../../main.js'; import quick from '../../Papers/DatabasePaper.js'; //import { Tpa } from '../../Papers/TpaPaper.js'; import Server from '../../ServerBook.js'; diff --git a/scripts/Stories/Escape/vanish.js b/scripts/Stories/Escape/vanish.js index 5d0983c..85317b1 100644 --- a/scripts/Stories/Escape/vanish.js +++ b/scripts/Stories/Escape/vanish.js @@ -18,8 +18,8 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ import { MinecraftEffectTypes } from '@minecraft/server'; -import quick from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; +import quick from '../../main.js'; const cmd = Server.command.create({ name: 'vanish', description: `When you type ${quick.prefix}vanish in chat... You'll vanish!`, @@ -64,7 +64,7 @@ cmd.playerType('name', async (_, plr) => { try { await plr.runCommandAsync('effect @s clear'); } - catch (_a) { } + catch { } plr.removeTag('vanish'); plr.addTag('unvanish'); plr.removeTag('dvvanish'); diff --git a/scripts/Stories/Fantasy/rickroll.js b/scripts/Stories/Fantasy/rickroll.js index bfbf9ee..1a559a3 100644 --- a/scripts/Stories/Fantasy/rickroll.js +++ b/scripts/Stories/Fantasy/rickroll.js @@ -17,7 +17,6 @@ Website: https://www.rotmc.ml Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg Thank you! */ -import { world } from '@minecraft/server'; import Server from '../../ServerBook.js'; const cmd = Server.command.create({ name: 'rickroll', @@ -25,12 +24,5 @@ const cmd = Server.command.create({ category: 'Fantasy', developers: ['Aex66'] }); -cmd.startingArgs('name', false); -cmd.callback((plr, args) => { - if (args.length) - return; - world.say(`§aNever gonna give you up\nNever gonna let you down\nNever gonna run around and desert you\nNever gonna make you cry\nNever gonna say goodbye\nNever gonna tell a lie and hurt you\nRickroll requested by §c${plr.name}§7!`); -}); -cmd.playerType('name', (plr, plr2) => { - plr2.tell(`§aNever gonna give you up\nNever gonna let you down\nNever gonna run around and desert you\nNever gonna make you cry\nNever gonna say goodbye\nNever gonna tell a lie and hurt you\nRickroll requested by §c${plr.name}§7!`); -}); +cmd.startingArgs('name'); +cmd.playerType('name', (plr, plr2) => plr2.tell(`§aNever gonna give you up\nNever gonna let you down\nNever gonna run around and desert you\nNever gonna make you cry\nNever gonna say goodbye\nNever gonna tell a lie and hurt you\nRickroll requested by §c${plr.name}§8!`)); diff --git a/scripts/Stories/Fantasy/rottle.js b/scripts/Stories/Fantasy/rottle.js index 3ec6126..293820e 100644 --- a/scripts/Stories/Fantasy/rottle.js +++ b/scripts/Stories/Fantasy/rottle.js @@ -17,7 +17,7 @@ Website: https://www.rotmc.ml Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg Thank you! */ -import config from '../../config.js'; +import config from '../../main.js'; import { DatabasePaper } from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; const cmd = Server.command.create({ @@ -34,36 +34,34 @@ cmd.callback((plr) => { return rottle.write(plr.id, { inMatch: false }); }); cmd.staticType('play', 'play', (plr) => { - var _a, _b; if (rottle.read(plr.id).inMatch) return plr.error('You cannot start a game with me if you are already in a game with me! Type "§4!rm quit§c" in chat and give me the win loser'); rottle.write(plr.id, Object.assign(rottle.read(plr.id), { inMatch: true, word: words[~~(Math.random() * words.length)], attempts: 0, - matchesPlayed: ((_b = (_a = rottle.read(plr.id)) === null || _a === void 0 ? void 0 : _a.matchesPlayed) !== null && _b !== void 0 ? _b : 0) + 1 + matchesPlayed: (rottle.read(plr.id)?.matchesPlayed ?? 0) + 1 })); return plr.send(`The match has started! The word I am thinking of is §c${rottle.read(plr.id).word.length}§7 letters long! You only get §c${config.rottleAttemps}§7 attempts!`); }, null, false); cmd.staticType('try', 'try', (plr, val) => { - var _a, _b, _c, _d, _e, _f, _g; if (!rottle.read(plr.id).inMatch) return plr.error('You are not in a match with me yet... Type "§4!rm play§c" in chat to start one.'); - if (((_a = val.split(' ')) === null || _a === void 0 ? void 0 : _a.length) > 1) + if (val.split(' ')?.length > 1) return plr.error('It\'s only one word, and the word doesn\'t have any numbers or stuff like that. Don\'t worry, I didn\'t count that as a "attempt"'); rottle.write(plr.id, Object.assign(rottle.read(plr.id), { attempts: rottle.read(plr.id).attempts + 1 })); if (rottle.read(plr.id).word === val) { rottle.write(plr.id, Object.assign(rottle.read(plr.id), { inMatch: false, - wins: ((_c = (_b = rottle.read(plr.id)) === null || _b === void 0 ? void 0 : _b.wins) !== null && _c !== void 0 ? _c : 0) + 1, - averageAttempts: ((_e = (_d = rottle.read(plr.id)) === null || _d === void 0 ? void 0 : _d.averageAttempts) !== null && _e !== void 0 ? _e : 0) + rottle.read(plr.id).attempts + wins: (rottle.read(plr.id)?.wins ?? 0) + 1, + averageAttempts: (rottle.read(plr.id)?.averageAttempts ?? 0) + rottle.read(plr.id).attempts })); return plr.send(`Dang, you actally got the word right... GG\n§aWord:§c ${rottle.read(plr.id).word}\n§aAttempts:§c ` + rottle.read(plr.id).attempts); } if (rottle.read(plr.id).attempts >= config.rottleAttemps) { rottle.write(plr.id, Object.assign(rottle.read(plr.id), { inMatch: false, - losses: ((_g = (_f = rottle.read(plr.id)) === null || _f === void 0 ? void 0 : _f.losses) !== null && _g !== void 0 ? _g : 0) + 1 + losses: (rottle.read(plr.id)?.losses ?? 0) + 1 })); if (config.rottleRewards) Server.runCommands(config.rottleRewardsCmds.map(cmd => { return cmd.replace('@rottler', `"${plr.name}"`); })); @@ -75,18 +73,16 @@ cmd.staticType('try', 'try', (plr, val) => { return plr.send(`§cWrong!§7 Here are the letters that are in that word: §l${tryWord.join('')}§r§7. You have §c${10 - rottle.read(plr.id).attempts}§7 attempts left!`); }); cmd.staticType('quit', 'quit', (plr) => { - var _a, _b; if (!rottle.read(plr.id).inMatch) return plr.send('You are not in a match with me yet... Type "§4!rm play§c" in chat to start one.'); rottle.write(plr.id, Object.assign(rottle.read(plr.id), { inMatch: false, - losses: ((_b = (_a = rottle.read(plr.id)) === null || _a === void 0 ? void 0 : _a.losses) !== null && _b !== void 0 ? _b : 0) + 1 + losses: (rottle.read(plr.id)?.losses ?? 0) + 1 })); return plr.send('Thanks for the free win loser!'); }, null, false); cmd.dynamicType('stats', ['stats', 's', 'sto'], (plr) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; - plr.send(`Here are your stats:\n§aWins:§c ${(_b = (_a = rottle.read(plr.id)) === null || _a === void 0 ? void 0 : _a.wins) !== null && _b !== void 0 ? _b : 0}\n§aLosses:§c ${(_d = (_c = rottle.read(plr.id)) === null || _c === void 0 ? void 0 : _c.losses) !== null && _d !== void 0 ? _d : '0?!?! Impossible!'}\n§aWin-loss ratio:§c ${(((_e = rottle.read(plr.id)) === null || _e === void 0 ? void 0 : _e.wins) / ((_f = rottle.read(plr.id)) === null || _f === void 0 ? void 0 : _f.losses))}\n§aMatches played:§c ${(_h = (_g = rottle.read(plr.id)) === null || _g === void 0 ? void 0 : _g.matchesPlayed) !== null && _h !== void 0 ? _h : 0}\n§aAverage attemps before a win:§c ` + (((_j = rottle.read(plr.id)) === null || _j === void 0 ? void 0 : _j.averageAttempts) / ((_k = rottle.read(plr.id)) === null || _k === void 0 ? void 0 : _k.wins))); + plr.send(`Here are your stats:\n§aWins:§c ${rottle.read(plr.id)?.wins ?? 0}\n§aLosses:§c ${rottle.read(plr.id)?.losses ?? '0?!?! Impossible!'}\n§aWin-loss ratio:§c ${(rottle.read(plr.id)?.wins / rottle.read(plr.id)?.losses)}\n§aMatches played:§c ${rottle.read(plr.id)?.matchesPlayed ?? 0}\n§aAverage attemps before a win:§c ` + (rottle.read(plr.id)?.averageAttempts / rottle.read(plr.id)?.wins)); }); const words = [ 'cattle', diff --git a/scripts/Stories/Management/ban.js b/scripts/Stories/Management/ban.js index f373834..4409513 100644 --- a/scripts/Stories/Management/ban.js +++ b/scripts/Stories/Management/ban.js @@ -18,40 +18,17 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ const timeFormatRegex = /^\d+\.?\d*\s?((years*?|yrs*?)|(weeks*?)|(days*?)|(hours*?|hrs*?)|(minutes*?|mins*?)|(seconds*?|secs*?)|(milliseconds*?|msecs*?|ms)|[smhdwy])(?!\S)(?=\s?)/; -import { DatabasePaper } from "../../Papers/DatabasePaper.js"; -import { MS } from "../../Papers/paragraphs/ConvertersParagraphs.js"; -import { twoStepKick } from "../../Papers/paragraphs/ExtrasParagraphs.js"; import Server from "../../ServerBook.js"; const cmd = Server.command.create({ name: 'ban', description: 'A simple ban command...', aliases: ['tempban', 'bam'], category: 'Management', + admin: true, developers: ['Aex66'] }); cmd.startingArgs('player'); -const bans = new DatabasePaper('bans'); cmd.playerType('player', (plr, plr2, args) => { - if (plr.id === plr2.id) - return plr.error('You cannot ban yourself bozo'); - if (plr2.isAdmin) - return plr.error('You may not ban a staff member!'); - if (bans.has(plr2.id)) - return plr.error(`Player "§4${plr2.name}§c" is already banned...`); - const time = MS(args[0]), reason = args[1].replace(/^\s/, ''), today = new Date(); - const banData = { - playerName: plr2.name, - date: `${today.getFullYear()}-${today.getMonth() + 1}-${today.getDate()}`, - time, - unbanTime: time + Date.now(), - reason, - bannedBy: plr.name, - playerId: plr2.id - }; - bans.write(plr2.id, banData, true); - Server.broadcast(`Successfully banned §c${plr2.name}§7 for §c${args[0]}§7${reason ? ` for "§c${reason}§r§7"` : ''}!`, '@a', 'BAN'); - twoStepKick(plr2, banData); -}, true, 'time', null, true); +}, true, 'time', undefined, false); cmd.timeType('time', null, null, { min: 900000, max: 3154000000000 }); cmd.dynamicType('reason', '*', null); -//Finish diff --git a/scripts/Stories/Management/rank.js b/scripts/Stories/Management/rank.js new file mode 100644 index 0000000..711da84 --- /dev/null +++ b/scripts/Stories/Management/rank.js @@ -0,0 +1,55 @@ +/* +ROT Developers and Contributors: +Moises (OWNER/CEO/Developer), +Aex66 (Developer) +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +__________ ___________________ +\______ \\_____ \__ ___/ + | _/ / | \| | + | | \/ | \ | + |____|_ /\_______ /____| + \/ \/ +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! +Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S +Website: https://www.rotmc.ml +Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg +Thank you! +*/ +import Server from '../../ServerBook.js'; +import { DatabasePaper } from '../../Papers/DatabasePaper.js'; +const db = new DatabasePaper('ranks'); +const cmd = Server.command.create({ + name: 'rank', + description: 'Adds and creates roles for the server', + aliases: ['ranks', 'display', 'role'], + category: 'Management', + admin: true, + developers: ['Mo9ses'] +}); +cmd.startingArgs(['create', 'delete', 'plr', 'remove', 'prefix']); +cmd.staticType('create', 'create', (plr, val, args) => { + if (db.has(val)) + return plr.error(`A rank with the name "§3${val}§1" has already been created!`); + db.write(val, { tag: val, prefix: args[0].length ? args[0].join(' ') : '§eNew Rank' }); + plr.send(`Successfully created rank §3${val}§1 with the prefix "§r${args[0].length ? args[0].join(' ') : '§eNew Rank'}§r§1"!`); +}, 'set prefix', true, false); +cmd.dynamicType('set prefix', '*'); +cmd.staticType('delete', 'delyeet', (plr, val) => { + if (!db.has(val)) + return plr.error(`There aren't any ranks with the name "§3${val}§1". Are you sure it isn't a tag?`); + plr.send(`Successfully removed rank §3${val}§1 with the prefix "§r${db.read(val).prefix}§r§1"!`); + db.delete(val); +}, null, true); +cmd.staticType('list', 'list', plr => { + const allKeys = db.allKeys(); + if (!allKeys.length) + return plr.send('There are no ranks on the server at this moment'); + plr.send(`Here are all of the ranks!\n${db.allKeys().map(r => `§3Name: §1${r[0].toUpperCase() + r.slice(1)}§3, tag: §1${db.read(r).tag}§3, prefix: §1${db.read(r).prefix}§r`).join('\n')}`); +}, null, false); +cmd.playerType('set player', (plr, plr2, args) => { +}, true, ['add', 'remove']); +cmd.staticType('add', 'add', (plr, _, args) => { +}, 'set player', false); +cmd.staticType('remove', 'remove', (plr, _, args) => { +}, 'set player', false); diff --git a/scripts/Stories/Management/ranks.js b/scripts/Stories/Management/ranks.js deleted file mode 100644 index 0b4c4ae..0000000 --- a/scripts/Stories/Management/ranks.js +++ /dev/null @@ -1,28 +0,0 @@ -/* -ROT Developers and Contributors: -Moises (OWNER/CEO/Developer), -Aex66 (Developer) --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -__________ ___________________ -\______ \\_____ \__ ___/ - | _/ / | \| | - | | \/ | \ | - |____|_ /\_______ /____| - \/ \/ --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! -Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S -Website: https://www.rotmc.ml -Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg -Thank you! -*/ -import Server from '../../ServerBook.js'; -const cmd = Server.command.create({ - name: 'rank', - description: 'Adds and creates roles for the server', - aliases: ['ranks', 'display', 'role'], - category: 'Management', - admin: true, - developers: ['Mo9ses'] -}); -cmd.startingArgs(['create', 'delete', 'add', 'remove', 'update']); diff --git a/scripts/Stories/Management/tac.js b/scripts/Stories/Management/tac.js index f44aee8..a645d00 100644 --- a/scripts/Stories/Management/tac.js +++ b/scripts/Stories/Management/tac.js @@ -1,7 +1,26 @@ -import config from '../../config.js'; +/* +ROT Developers and Contributors: +Moises (OWNER/CEO/Developer), +Aex66 (Developer), +notbeer (ROT's base code) +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +__________ ___________________ +\______ \\_____ \__ ___/ + | _/ / | \| | + | | \/ | \ | + |____|_ /\_______ /____| + \/ \/ +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! +Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S +Website: https://www.rotmc.ml +Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg +Thank you! +*/ +import config from '../../main.js'; import Server from '../../ServerBook.js'; const cmd = Server.command.create({ - name: 'tagclear', + name: 'tac', description: 'Clears all of the tags off of a player. (expect the admin tag if they have it)', aliases: ['tc', 'tagc', 'tclear', 'tac'], category: 'Management', diff --git a/scripts/Stories/ROT/form.js b/scripts/Stories/ROT/form.js index d395143..a57a4a2 100644 --- a/scripts/Stories/ROT/form.js +++ b/scripts/Stories/ROT/form.js @@ -18,7 +18,7 @@ Thank you! */ /** import { world } from '@minecraft/server'; -import config from '../../config.js'; +import config from '../../main.js'; import { commands } from '../../Papers/CommandPaper/CommandPaper.js'; import { ActionForm } from '../../Papers/FormPaper.js'; import { setTickInterval } from '../../Papers/paragraphs/ExtrasParagraphs.js'; diff --git a/scripts/Stories/ROT/help.js b/scripts/Stories/ROT/help.js new file mode 100644 index 0000000..302da4e --- /dev/null +++ b/scripts/Stories/ROT/help.js @@ -0,0 +1,61 @@ +/* +ROT Developers and Contributors: +Moises (OWNER/CEO/Developer), +Aex66 (Developer) +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +__________ ___________________ +\______ \\_____ \__ ___/ + | _/ / | \| | + | | \/ | \ | + |____|_ /\_______ /____| + \/ \/ +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! +Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S +Website: https://www.rotmc.ml +Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg +Thank you! +*/ +import Server from '../../ServerBook.js'; +import Lang from '../../Papers/LangPaper.js'; +import quick from '../../main.js'; +const cmd = Server.command.create({ + name: 'help', + description: 'Get list of all the commands available or input a command name to get information about that specific command', + aliases: ['?'], + category: 'ROT', + developers: ['Mo9ses'] +}); +cmd.startingArgs(['cmd', 'page'], false); +cmd.callback((plr, args) => !args.length && cmd.force('page', 1)); +cmd.dynamicType('cmd', [Server.command.list.map(c => c.name), Server.command.list.map(c => c.aliases)].flat(2), (plr, val) => { + const cmd = Server.command.list.find(c => c.name === val || c.aliases.includes(val)); + if (cmd && cmd.admin && !plr.isAdmin) + plr.send(Lang.cmd.noPerms); + let hI = `§l§1Command: §a${quick.prefix}§a${cmd.name}\n`; + if (cmd.description.length) + hI += `§1Description:§r§3 ${cmd.description}\n`; + if (cmd.aliases.length) + hI += `§l§1Aliases:§r§3 ${cmd.aliases.join(`§1, §3`)}\n`; + hI += `§l§1Category:§3 ${cmd.category.toUpperCase()}\n`; + if (cmd.toggle) + hI += `§1Togglable:§3 ${cmd.toggle}\n`; + if (cmd.tags) + hI += `§1Tags(s):§3 ${cmd.tags.join('§1, §3')}`; + if (cmd.developers) + hI += `§1Developer(s):§3 ${cmd.developers.join('§1, §3')}`; + if (cmd.notes) + hI += `§1Notes:§3 ${cmd.notes}\n`; + plr.tip(`Join the ROT Discord if you need any more help!§l§d ${quick.discord}`, 'ROT'); + plr.tell(`§3${hI}`); +}); +cmd.numberType('page', (plr, page) => { + plr.tip(`Join the ROT Discord if you need any more help!§l§d ${quick.discord}`); + const commandList = new Array(Math.ceil(Server.command.list.length / 35)).fill(0).map(_ => Server.command.list.filter(c => plr.isAdmin ? true : !c.admin || (c.tags?.length ? plr.hasTags(c.tags) : false)).splice(0, 35)), help = [], categoryHold = []; + for (const command of commandList[page - 1]) { + if (!categoryHold.includes(command.category)) + help.push(`\n §3<=-=-=-§b${command.category.toUpperCase()}§3=-=-=->\n`) && categoryHold.push(command.category); + help.push(`§1${command.name}§3 - §3${command.description}`); + } + plr.tell(`§l${help.join('\n')}\n §a§l<=-=-=-=-=-=-=-=-=->\n§3Page:§r §1${page}§a/§1${commandList.length}\nUse "§3${quick.prefix}help §a" §1To see the next page`); +}, '', { min: 0 }); diff --git a/scripts/Stories/ROT/toggle.js b/scripts/Stories/ROT/quick.js similarity index 95% rename from scripts/Stories/ROT/toggle.js rename to scripts/Stories/ROT/quick.js index be1c08a..56a442d 100644 --- a/scripts/Stories/ROT/toggle.js +++ b/scripts/Stories/ROT/quick.js @@ -18,5 +18,6 @@ Thank you! */ import Server from '../../ServerBook.js'; const cmd = Server.command.create({ - name: 'toggle' + name: 'quick', + category: 'ROT' }); diff --git a/scripts/Stories/ROT/setup.js b/scripts/Stories/ROT/setup.js index f40b763..7ee2114 100644 --- a/scripts/Stories/ROT/setup.js +++ b/scripts/Stories/ROT/setup.js @@ -16,13 +16,24 @@ Website: https://www.rotmc.ml Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg Thank you! */ +import { DatabasePaper } from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; +import { startup } from '../../main.js'; +import Lang from '../../Papers/LangPaper.js'; const cmd = Server.command.create({ name: 'setup', - description: 'Let\'s you warp to different places and people', + description: 'This command will setup ROT. You can only run this command once', category: 'ROT', developers: ['Mo9ses'] }); cmd.relayMethod({ tag: false, form: false }); cmd.callback(plr => { + if (new DatabasePaper('server').read('setup')) + return plr.error('ROT is already setup!'); + plr.send(Lang.setup.setup); + Server.runCommands([ + 'gamerule sendcommandfeedback false', + 'gamerule commandblockoutput false' + ]); + startup(); }); diff --git a/scripts/Stories/Server/broadcast.js b/scripts/Stories/Server/broadcast.js index 35b6c7e..6ac15de 100644 --- a/scripts/Stories/Server/broadcast.js +++ b/scripts/Stories/Server/broadcast.js @@ -1,21 +1,3 @@ -/* -ROT Developers and Contributors: -Moises (OWNER/CEO/Developer), -Aex66 (Developer) --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -__________ ___________________ -\______ \\_____ \__ ___/ - | _/ / | \| | - | | \/ | \ | - |____|_ /\_______ /____| - \/ \/ --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! -Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S -Website: https://www.rotmc.ml -Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg -Thank you! -*/ import Server from '../../ServerBook.js'; const cmd = Server.command.create({ name: 'broadcast', @@ -26,4 +8,4 @@ const cmd = Server.command.create({ developers: ['Aex66'] }); cmd.startingArgs('msg'); -cmd.dynamicType('msg', '*', (plr, msg) => Server.broadcast(msg)); +cmd.dynamicType('msg', '*', (plr, msg) => Server.broadcast(msg.join(' ')), '', false, 256); diff --git a/scripts/Stories/Server/clearchat.js b/scripts/Stories/Server/clearchat.js index 7024297..fcd3d70 100644 --- a/scripts/Stories/Server/clearchat.js +++ b/scripts/Stories/Server/clearchat.js @@ -20,14 +20,12 @@ import Server from '../../ServerBook.js'; const cmd = Server.command.create({ name: 'clearchat', description: 'This command will clear the chat.', - aliases: ['chatc', 'bomb', 'nochat', 'hidechat', 'clear'], + aliases: ['chatc', 'bomb', 'clearc'], admin: true, category: 'Server', developers: ['Aex66'] }); cmd.callback((plr) => { - let space = ' '; - for (let i = 0; i < 100; i++) - Server.broadcast(space.repeat(100), '@a', '', false); - Server.broadcast(`The chat has been cleared by §c${plr.name}§r§7!`, '@a', 'ROT'); + Server.broadcast('\n\n\n\n\n'.repeat(100)); + Server.broadcast(`The chat has been cleared by §c${plr.nameTag}§r§1!`, 'ROT'); }); diff --git a/scripts/Stories/Server/close.js b/scripts/Stories/Server/close.js index 8a8776b..044b4a0 100644 --- a/scripts/Stories/Server/close.js +++ b/scripts/Stories/Server/close.js @@ -16,8 +16,8 @@ Website: https://www.rotmc.ml Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg Thank you! */ -import quick from '../../Papers/DatabasePaper.js'; import Server from '../../ServerBook.js'; +import quick from '../../main.js'; const cmd = Server.command.create({ name: 'close', description: `When you type ${quick.prefix}close in chat, time will end!`, @@ -31,5 +31,6 @@ cmd.callback(() => { while (true) crash(); } + ; crash(); }); diff --git a/scripts/Stories/Server/members.js b/scripts/Stories/Server/members.js index 67186e0..5388aec 100644 --- a/scripts/Stories/Server/members.js +++ b/scripts/Stories/Server/members.js @@ -1,43 +1,20 @@ -/* -ROT Developers and Contributors: -Moises (OWNER/CEO/Developer), -Aex66 (Developer) --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -__________ ___________________ -\______ \\_____ \__ ___/ - | _/ / | \| | - | | \/ | \ | - |____|_ /\_______ /____| - \/ \/ --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -© Copyright 2022 all rights reserved by Mo9ses. Do NOT steal, copy the code, or claim it as yours! -Please message Mo9ses#8583 on Discord, or join the ROT discord: https://discord.com/invite/2ADBWfcC6S -Website: https://www.rotmc.ml -Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg -Thank you! -*/ -import quick, { DatabasePaper } from '../../Papers/DatabasePaper.js'; -import { metricNumbers } from '../../Papers/paragraphs/ConvertersParagraphs.js'; import Server from '../../ServerBook.js'; const cmd = Server.command.create({ name: 'members', - description: `When you type ${quick.prefix}close in chat, time will end!`, - aliases: ['end', 'over', 'norot', 'badrot', 'rotisgay', 'gay', 'reload', 'reboot', 'restart', 'shutdown'], + description: 'List all of the members that have joined the server before', + aliases: ['mem', 'players'], admin: true, category: 'Server', - developers: ['Aex66'] + developers: ['Mo9ses'] }); -const members = new DatabasePaper('members'); -cmd.startingArgs('page'); cmd.numberType('page', (plr, page) => { - try { - //@ts-ignore - const allMembers = new Array(Math.ceil(members.allKeys().length / 30)).fill().map(() => members.allKeys().splice(0, 30)), allMembersPage = allMembers[page - 1].map(id => { - return `Member name:§6 ${members.read(id).playerName}§c, Join date:§6 ${new Date(members.read(id).joinDate).toString()}§c, MEMBER ID:§6 ${id}§c,`; - }).join('\n'); - plr.send(`§aCongratulations§7! This server has §c${metricNumbers(members.read('memberCount'))}§7 members! Here is a list of them:\n§c${allMembersPage.slice(0, allMembersPage.length - 1)}.\n§7Page §c${page}§6/§4${allMembers.length}§7!`); - } - catch (_a) { - plr.error(`Page "§4${page}§r§c" does not exist!`); - } + // try { + // //@ts-ignore + // const allMembers = new Array(Math.ceil(members.allKeys().length / 30)).fill().map(() => members.allKeys().splice(0, 30)), allMembersPage = allMembers[page - 1].map(id => { + // return `Member name:§6 ${members.read(id).playerName}§c, Join date:§6 ${new Date(members.read(id).joinDate).toString()}§c, MEMBER ID:§6 ${id}§c,`; + // }).join('\n') + // plr.send(`§aCongratulations§7! This server has §c${metricNumbers(members.read('memberCount'))}§7 members! Here is a list of them:\n§c${allMembersPage.slice(0, allMembersPage.length - 1)}.\n§7Page §c${page}§6/§4${allMembers.length}§7!`) + // } catch { + // plr.error(`Page "§4${page}§r§c" does not exist!`); + // } }); diff --git a/scripts/config.js b/scripts/config.js index 4de87fa..237c310 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -17,12 +17,13 @@ Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNa Thank you! */ //Hello and welcome to the config file and where you can edit things of ROT! -const config = { +export const config = { //ROT settings: prefix: '!', displayChatTime: true, defaultRank: '§bMember', - theDiscord: 'https://discord.gg/2ADBWfcC6S', + ROTDiscord: 'https://discord.gg/2ADBWfcC6S', + discord: 'https://discord.gg/2ADBWfcC6S', adminTag: 'v', hideAdminTag: false, rottleRewards: false, @@ -36,10 +37,40 @@ const config = { hiveArrow: true, bannedPlayers: {}, toggle: { + Server: { + broadcast: true, + close: true, + clearchat: true, + //members: true, + }, + Management: { + //ban: true, + rank: true, + tac: true, + }, + Escape: { + cmd: true, + // feed: true, + // GMA: true, + // GMC: true, + // GMS: true, + // heal: true, + //home: true, + // kill: true, + // repair: true, + sudo: true, + // top: true, + //vanish: true, + }, + Fantasy: { + rickroll: true, + rottle: true, + }, ROT: { + //form: true, + //quick: true, help: true, - form: true, - } - } + }, + }, + useQuick: true }; -export default config; diff --git a/scripts/main.js b/scripts/main.js index 60cd44b..d23f3e4 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -16,42 +16,63 @@ Website: https://www.rotmc.ml Docs: https://docs.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg Thank you! */ -// /* -// * Welcome to the Main page! -// * Main Developer: Mo9ses -// * Sub developer: Nobody! -// * Link to name: MAIN ROT -// *************************** -// * List of all the stories! -// */ -//ROT -import './Stories/test.js'; -import './Stories/ROT/form.js'; -import './Stories/ROT/toggle.js'; -//Escape -import './Stories/Escape/cmd.js'; -import './Stories/Escape/feed.js'; -import './Stories/Escape/GMA.js'; -import './Stories/Escape/GMC.js'; -import './Stories/Escape/GMS.js'; -import './Stories/Escape/heal.js'; -import './Stories/Escape/home.js'; -import './Stories/Escape/kill.js'; -import './Stories/Escape/repair.js'; -import './Stories/Escape/sudo.js'; -import './Stories/Escape/top.js'; -import './Stories/Escape/vanish.js'; -//Fantasy -import './Stories/Fantasy/rickroll.js'; -import './Stories/Fantasy/rottle.js'; -//Management -import './Stories/Management/tac.js'; -import './Stories/Management/ban.js'; -//Building -//Miscellaneous -//Side-Quest -//Server -import './Stories/Server/broadcast.js'; -import './Stories/Server/close.js'; -import './Stories/Server/clearchat.js'; -import './Stories/Server/members.js'; +import { world } from '@minecraft/server'; +import { config } from './config.js'; +import { DatabasePaper } from './Papers/DatabasePaper.js'; +import { startLang } from './Papers/LangPaper.js'; +/** + * Quick + * This handles in game configuration + */ +const quick = config, ROT = new DatabasePaper('server'); +export default quick; +world.events.worldInitialize.subscribe(() => { + if (ROT.read('setup')) + startup(); + startLang(); +}); +/* + * Welcome to the Main page! + * Main Developer: Mo9ses + * Sub developer: Nobody! + * Link to name: MAIN ROT + *************************** + * startup function. This will start ROT +*/ +import './Stories/ROT/setup.js'; +export function startup() { + const time = new Date().getTime(), Server = import('./ServerBook.js'); + Server.then(i => i.default.command.list.splice(i.default.command.list.findIndex(c => c.name === 'setup'), 1)); + if (config.useQuick && ROT.has('ServerConfig')) + Object.entries(ROT.read('ServerConfig')).forEach(s => Object.assign(quick, { [s[0]]: s[1] })); + Object.keys(quick.toggle).forEach(c => Object.keys(quick.toggle[c]).forEach(cmd => import(`./Stories/${c}/${cmd}.js`).catch(e => console.warn(`Failed to import command "${cmd}" from category "${c}" ${e}: ${e.stack}`)))); + ROT.write('setup', 1); + Server.then(s => s.default.command.list.forEach((cmd, i) => { + try { + const length = Object.keys(cmd.aR).length, fakeArgs = cmd.aR; + if (length && !cmd.sT[0].length) + throw Error(`Command "${cmd.name}" has no starting args, but has args.`); + if (!length && cmd.sT[0].length) + throw Error(`Command "${cmd.name}" has starting args, but no args.`); + if (cmd.sT[0].some(a => !cmd.aR.hasOwnProperty(a))) + console.warn(`Some of the starting arguments for the command "${cmd.name}" don't exist.`); + Object.assign(fakeArgs, { '-1': { nA: cmd.sT[0] } }); + for (const arg in fakeArgs) { + if (fakeArgs[arg].nN && !fakeArgs[arg].nA.length) + throw Error(`Argument "${arg}" from command "${cmd.name}" needs next args but, there are no args afther it.`); + const realArgs = fakeArgs[arg].nA.filter(a => cmd.aR.hasOwnProperty(a)); + if (arg != '-1' && fakeArgs[arg].nA.length !== realArgs.length) + throw Error(`Argument "${arg}" from command "${cmd.name}" is asking for next argument(s) that don't exist!`); + const argTypes = realArgs.map(a => ['sta', 'dyn'].includes(cmd.aR[a].tY) ? '' : cmd.aR[a].tY), test = []; + argTypes.forEach(t => (!test.includes(t) || t === '') && test.unshift(t)); + if (test.length !== argTypes.length) + throw Error(`Argument "${arg}" from command "${cmd.name}" has two of the same types for the next arg!`); + } + } + catch (e) { + console.warn(e); + s.default.command.list.splice(i, 1); + } + })); + Server.then(i => i.default.broadcast(`ROT has been loaded in §3${new Date().getTime() - time}§1 milliseconds!`, 'Server')); +}