Skip to content

Commit

Permalink
ROT V3 part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mo9ses committed Dec 9, 2022
1 parent 72679fd commit 30324eb
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 105 deletions.
20 changes: 10 additions & 10 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"format_version": 2,
"header": {
"name": "§4§lROT V3 §aPart 2",
"name": "§3§lROT V3 §aPart 3",
"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": "62dd78b5-8197-4f8f-97cd-8f1f9ddc4c9f",
"uuid": "d061afe6-08db-4925-b1a4-655f7f69a7dd",
"version": [
2,
3,
0
0,
3
],
"min_engine_version": [
1,
18,
31
19,
40
]
},
"modules": [
Expand All @@ -21,9 +21,9 @@
"type": "data",
"uuid": "42f17752-1b47-4dbe-82b7-0b0d96192698",
"version": [
2,
3,
0
0,
3
]
},
{
Expand All @@ -32,9 +32,9 @@
"language": "javascript",
"uuid": "a188da6f-fccc-473a-94aa-f6fa7ef59962",
"version": [
2,
3,
0
0,
3
],
"entry": "scripts/main.js"
}
Expand Down
25 changes: 11 additions & 14 deletions scripts/Papers/CommandPaper/CommandPaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Server from '../../ServerBook.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
*/
Expand All @@ -40,23 +39,23 @@ world.events.beforeChat.subscribe(data => {
return;
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)}`;
const message = data.message.charAt(0).toUpperCase() + data.message.slice(1), rank = `§7[${player.getPrefixes().join('§r§7, ')}§r§7] ${player.getNameColors().join('')}`;
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}`));
return Array.from(world.getPlayers()).forEach(plr => plr.tell(`${rank}${player.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);
});
/*
* Welcome to the CommandPaper!
* Main Developer: Mo9ses
* Sub developer: notbeer
* Sub developer: Nobody!
* Link to name: Command Paper
*/
export class CommandPaper {
Expand Down Expand Up @@ -127,18 +126,15 @@ export class CommandPaper {
for (const a of nextArgs) {
if (!['sta', 'dyn'].includes(cmd.aR[a].tY))
continue;
if (cmd.aR[a].tY === 'sta') {
if (cmd.aR[a].tV[0].includes(args[0]))
return { aRN: a, tV: args[1], nA: args.slice(cmd.aR[a].tV[1] ? 2 : 1) };
if (cmd.aR[a].tY === 'sta')
if (staticBook[cmd.aR[a].tV[0]].val.includes(args[0]))
return { aRN: a, tV: args[1], nA: args.slice(cmd.aR[a].tV[1] ? 2 : 1) };
continue;
}
return { aRN: a, tV: cmd.aR[a].tV[1] ? args[1] : cmd.aR[a].tV[0], nA: args.slice(cmd.aR[a].tV[1] ? 2 : 1) };
else
continue;
const res = cmd.aR[a].tV[0].find((v) => v === '*' || args.slice(0, v.split(' ').length).join(' ') === v);
if (res)
return { aRN: a, tV: cmd.aR[a].tV[2] ? args.slice(0, cmd.aR[a].tV[2]) : cmd.aR[a].tV[0].includes('*') ? args.slice(0, res.split(' ').length).join(' ') : args[0], nA: cmd.aR[a].tV[2] ? args.slice(cmd.aR[a].tV[2]) : args.slice(res.split(' ').length) };
}
;
const argTypes = {};
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);
Expand Down Expand Up @@ -189,7 +185,8 @@ export class CommandPaper {
else
testing = false;
}
if (left !== args[0])
const minMax = cmd.aR[argTypes['plr']].tV;
if (left !== args[0] && (minMax?.min ?? 0) <= time && time <= (minMax?.max ?? 0))
return { aRN: argTypes['tim'], tV: time, nA: args.slice(1) };
}
}
Expand All @@ -209,7 +206,7 @@ export class CommandPaper {
if (type.tY === 'boo')
return 'true';
if (type.tV === 'tim')
return '';
return MS(type.tV.max);
return;
}
/**
Expand All @@ -226,7 +223,7 @@ export class CommandPaper {
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))
if (player.isAdmin ? false : 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');
Expand Down
2 changes: 1 addition & 1 deletion scripts/Papers/LangPaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const startLang = () => Object.assign(Lang, {
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 "§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?` : ''}`,
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 ? ` §3${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: "§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 :)`,
Expand Down
104 changes: 68 additions & 36 deletions scripts/Papers/PlayerPaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,67 @@ Website: https://www.rotmc.ml
Docs: https://docServer.google.com/document/d/1hasFU7_6VOBfjXrQ7BE_mTzwacOQs5HC21MJNaraVgg
Thank you!
*/
import { world, Player, Location } from '@minecraft/server';
import { DatabasePaper } from './DatabasePaper.js';
import { MessageForm } from './FormPaper.js';
import { world, Player } from '@minecraft/server';
import { DatabasePaper } from './DatabasePaper';
import quick from '../main.js';
const playerData = {}, cache = {};
/*
* Defining possibly arbitrary varibles
*/
const ranksDB = new DatabasePaper('ranks');
/*
* Welcome to the PlayerPaper!
* Main Developer: Mo9ses
* Sub developer: Nobody!
* Link to name: Player Paper
*/
export class PlayerPaper {
/**
* Converts a normal Minecraft player to the ROT paper standard
* @param {Player | string} player The player you want to transform
* @param {playerData} data Additional paper data
* @returns {PlayerType} Don't get this confused with playertype
*/
paperPlayer(player, data) {
const plr = player instanceof Player ? player : Array.from(world.getPlayers()).find(p => p.nameTag.toLowerCase() === player.toLowerCase());
if (!player)
return;
data.from = data.from[0].toUpperCase() + data.from.slice(1);
if (data?.from)
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) => {
Object.assign(cache[plr.nameTag], { [key]: value });
db.write(key, value);
},
read: (key) => cache[plr.nameTag]?.[key] ?? db.read(key),
delete: (key) => {
db.delete(key);
delete cache[plr.nameTag][key];
},
write: (key, value) => db.write(key, value),
read: (key) => db.read(key),
delete: (key) => db.delete(key),
send: (msg, from) => {
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 }] });
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 }] });
plr.tell({ 'rawtext': [{ 'text': `§l§1${from ? `${from} ` : data?.from ? `${data.from} ` : ''}§aTIP §3>>§r§1 ` }, { 'text': msg }] });
},
error: (msg, from) => {
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 }] });
plr.tell({ 'rawtext': [{ 'text': `§l§1${from ? `${from} ` : data?.from ? `${data.from} ` : ''}§3Error >>§r§1 ` }, { 'text': msg }] });
},
UIerror: (msg, buttons, from) => {
const UI = new MessageForm();
let val = false;
UI.setTitle(`${from ?? `§c§l${data.from} Error` ?? '§c§lError!'}`);
UI.setBody(`§c${msg}`);
UI.setButton1(buttons[0] ?? '§e§lTry again');
UI.setButton1(buttons[1] ?? '§c§lClose');
UI.send(plr, res => val = Boolean(res.selection));
return val;
/**
* @function getRanks Gets the ranks of a player
* @example getRanks(Mo9ses);
*/
getPrefixes: () => {
const ranks = plr.getTags().filter(tag => tag.startsWith('rank:')).map(c => c.replace('rank:', '').trim());
ranksDB.allKeys().forEach(k => plr.hasTag(ranksDB.read(k).tag) && ranks.push(ranksDB.read(k).prefix));
return ranks.length ? ranks : [quick.defaultRank];
},
/**
* @function getColors Gets the color of a player
* @example getColor(Mo9ses);
*/
getNameColors: () => {
const colors = plr.getTags().filter(tag => tag.startsWith('colors:')).map(c => c.replace('rank:', '').trim());
return colors.length ? colors : [quick.defaultNameColor];
},
/**
* Get players score on a specific objective
Expand All @@ -75,20 +91,37 @@ export class PlayerPaper {
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 l = plr.getBlockFromViewVector({ includeLiquidBlocks: true, maxDistance: 300 });
return getBlock ? l : [l.x, l.y, l.z];
},
veiwEntity: (getPos) => {
const l = plr.getEntitiesFromViewVector({ maxDistance: 300 });
return getPos ? [l[0].location.x, l[0].location.y, l[0].location.z] : l;
}
},
// UIerror: (msg: string, buttons: string[], from?: string): boolean => {
// const UI = new MessageForm();
// let val = false;
// UI.setTitle(`${from ?? `§c§l${data.from} Error` ?? '§c§lError!'}`);
// UI.setBody(`§c${msg}`);
// UI.setButton1(buttons[0] ?? '§e§lTry again');
// UI.setButton1(buttons[1] ?? '§c§lClose');
// UI.send(plr, res => val = Boolean(res.selection));
// return val;
// },
// veiwLocation: (dist: [number, number, number]) => { //To be finished
// const l = plr.viewVector;
// return new Location(l.x, l.y, l.z);
// },
});
}
/**
* Used to execute certain functions on players that might be offline or online
* @param name The name of the player
* @param from Where this will be used
* @param player Additional information sent if the player is online
* @returns {OfflineType}
*/
offlinePlayer(name, from, player) {
return {
nameTag: name,
Expand All @@ -97,8 +130,7 @@ export class PlayerPaper {
};
}
}
world.events.playerJoin.subscribe(({ player }) => {
new DatabasePaper(player.id, 'PLR');
Object.assign(cache, { [player.name]: { 'default': 0 } });
});
world.events.playerLeave.subscribe(data => delete cache[data.playerName]);
/*
* I don't think this is useful...
*/
world.events.playerJoin.subscribe(({ player }) => new DatabasePaper(player.id, 'PLR'));
12 changes: 6 additions & 6 deletions scripts/Papers/paragraphs/ConvertersParagraphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ const toMS = (value) => {
const toDuration = (value, { compactDuration, fullDuration, avoidDuration } = {}) => {
const absMs = Math.abs(value);
const duration = [
{ short: 'w', long: 'week', duration: Math.floor(absMs / 6.048e+8) },
{ short: 'd', long: 'day', duration: Math.floor(absMs / 8.64e+7) % 7 },
{ short: 'h', long: 'hour', duration: Math.floor(absMs / 3.6e+6) % 24 },
{ short: 'm', long: 'minute', duration: Math.floor(absMs / 60000) % 60 },
{ short: 's', long: 'second', duration: Math.floor(absMs / 1000) % 60 },
{ short: 'ms', long: 'millisecond', duration: absMs % 1000 }
{ short: 'W', long: 'Week', duration: Math.floor(absMs / 6.048e+8) },
{ short: 'D', long: 'Day', duration: Math.floor(absMs / 8.64e+7) % 7 },
{ short: 'H', long: 'Hour', duration: Math.floor(absMs / 3.6e+6) % 24 },
{ short: 'M', long: 'Minute', duration: Math.floor(absMs / 60000) % 60 },
{ short: 'S', long: 'Second', duration: Math.floor(absMs / 1000) % 60 },
{ short: 'MS', long: 'Millisecond', duration: absMs % 1000 }
];
const mappedDuration = duration
.filter(obj => obj.duration !== 0 && avoidDuration ? fullDuration && !avoidDuration.map(v => v.toLowerCase()).includes(obj.short) : obj.duration)
Expand Down
18 changes: 1 addition & 17 deletions scripts/Papers/paragraphs/ExtrasParagraphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,8 @@ world.events.tick.subscribe(() => {
* Notes: I don't really know what goes on down here...
* Sub developer: Mo9ses
* Link to name: Miscellaneous
****************************************
* @function getRanks Gets the ranks of a player you
* @param {string} player the player
* @example getRanks(Mo9ses);
*/
export const getRanks = (player) => {
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
* @param {string} player the player
* @example getColor(Mo9ses);
*/
getNameColor = (player) => {
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];
},
export const
/**
* @function getChat Gets the chat color of a player
* @param {string} player the player
Expand Down
23 changes: 13 additions & 10 deletions scripts/Stories/Management/rank.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ const cmd = Server.command.create({
admin: true,
developers: ['Mo9ses']
});
cmd.startingArgs(['create', 'delete', 'plr', 'remove', 'prefix']);
cmd.startingArgs(['create', 'delete', 'list', 'plr', /*'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', '*');
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"!`);
}, 'any', true, false);
cmd.dynamicType('any', '*');
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?`);
Expand All @@ -47,9 +47,12 @@ cmd.staticType('list', 'list', plr => {
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) => {
cmd.playerType('plr', (plr, plr2, args) => {
if (args[0] === 'add')
plr2.addTag(args[1].join(' '));
else
plr.removeTag(args[1].join(' '));
plr.send(`The rank "§3${args[1].join(' ')}§1" have been ${args[0] === 'add' ? '§agranted§1 to' : '§crevoked§1 from'} §3${plr2.nameTag}§1!`);
}, true, ['add', 'remove']);
cmd.staticType('add', 'add', (plr, _, args) => {
}, 'set player', false);
cmd.staticType('remove', 'remove', (plr, _, args) => {
}, 'set player', false);
cmd.staticType('add', 'add', null, 'any', false);
cmd.staticType('remove', 'remove', null, 'any', false);
2 changes: 1 addition & 1 deletion scripts/Stories/Server/clearchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ const cmd = Server.command.create({
});
cmd.callback((plr) => {
Server.broadcast('\n\n\n\n\n'.repeat(100));
Server.broadcast(`The chat has been cleared by §c${plr.nameTag}§r§1!`, 'ROT');
Server.broadcast(`The chat has been cleared by §3${plr.nameTag}§r§1!`, 'ROT');
});
Loading

0 comments on commit 30324eb

Please sign in to comment.