Skip to content

Commit

Permalink
ROT V3 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mo9ses committed Dec 8, 2022
1 parent 4c607b9 commit 72679fd
Show file tree
Hide file tree
Showing 34 changed files with 631 additions and 599 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
305 changes: 144 additions & 161 deletions scripts/Papers/CommandPaper/CommandPaper.js

Large diffs are not rendered by default.

38 changes: 34 additions & 4 deletions scripts/Papers/CommandPaper/CommandTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
Expand Down Expand Up @@ -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!'
},
Expand All @@ -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 = {};
Expand Down
106 changes: 36 additions & 70 deletions scripts/Papers/DatabasePaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand All @@ -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;
}
/**
Expand All @@ -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
Expand All @@ -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;
}
/**
Expand All @@ -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;
}
/**
Expand All @@ -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();
*/
Expand All @@ -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();
*/
Expand All @@ -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));
*/
Expand All @@ -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 });
*/
Expand All @@ -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')) {
}
});
10 changes: 5 additions & 5 deletions scripts/Papers/FormPaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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!
Expand All @@ -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
Expand All @@ -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
Expand Down
49 changes: 38 additions & 11 deletions scripts/Papers/LangPaper.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
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
* Main Developer: Mo9ses
* 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;
Loading

0 comments on commit 72679fd

Please sign in to comment.