diff --git a/config/default-settings.json b/config/default-settings.json index 27ef0fa..a250ab1 100644 --- a/config/default-settings.json +++ b/config/default-settings.json @@ -6,15 +6,15 @@ "logging": true, "gameMode": 1, "generation": { - "name":"diamond_square", + "name": "diamond_square", "options":{ - "worldHeight":80 + "worldHeight": 80 } }, - "kickTimeout":10000, + "kickTimeout": 10000, "plugins": { }, "modpe": false, - "view-distance":10 + "view-distance": 10 } diff --git a/src/lib/command.js b/src/lib/command.js index 20a4721..05fa032 100644 --- a/src/lib/command.js +++ b/src/lib/command.js @@ -24,10 +24,11 @@ class Command { return res; } - async use(command) { + async use(command, op=true) { var res = this.find(command); if(res) { + if (res[0].params.op && !op) return 'You do not have permission to use this command'; var parse = res[0].params.parse; if(parse) { if(typeof parse == 'function') { @@ -74,6 +75,10 @@ class Command { var first = !(this.parent && this.parent.parent); return this.params.merged || (!end && first) ? '' : ' '; } + + setOp(op) { + this.params.op = op; + } } module.exports=Command; \ No newline at end of file diff --git a/src/lib/plugins/blocks.js b/src/lib/plugins/blocks.js index 43d00b4..d47c383 100644 --- a/src/lib/plugins/blocks.js +++ b/src/lib/plugins/blocks.js @@ -32,6 +32,7 @@ module.exports.player=function(player,serv) base: 'setblock', info: 'to put a block', usage: '/setblock ', + op: true, parse(str) { var results = str.match(/^(~|~?-?[0-9]*) (~|~?-?[0-9]*) (~|~?-?[0-9]*) ([0-9]{1,3}) ([0-9]{1,3})/); if(!results) return false; diff --git a/src/lib/plugins/commands.js b/src/lib/plugins/commands.js index 61f99c6..6f20440 100644 --- a/src/lib/plugins/commands.js +++ b/src/lib/plugins/commands.js @@ -18,7 +18,7 @@ module.exports.player=function(player) { if(used.indexOf(hash[key]) > -1) continue; used.push(hash[key]); - if(hash[key].params.info) { + if(hash[key].params.info && (player.op || !hash[key].params.op)) { var str = hash[key].params.usage + ' ' + hash[key].params.info; if(hash[key].params.aliases && hash[key].params.aliases.length) { str += ' (aliases: ' + hash[key].params.aliases.join(', ') + ')'; @@ -76,7 +76,7 @@ module.exports.player=function(player) { player.handleCommand = async (str) => { try { - var res = await player.commands.use(str); + var res = await player.commands.use(str, player.op); if (res) player.chat('' + res); } catch(err) { diff --git a/src/lib/plugins/daycycle.js b/src/lib/plugins/daycycle.js index 5649a2b..5e36fc4 100644 --- a/src/lib/plugins/daycycle.js +++ b/src/lib/plugins/daycycle.js @@ -29,6 +29,7 @@ module.exports.player=function(player,serv){ base: 'night', info: 'to change a time to night', usage: '/night', + op: true, action() { return player.handleCommand('time set night'); } @@ -38,6 +39,7 @@ module.exports.player=function(player,serv){ base: 'time', info: 'to change a time', usage: '/time ', + op: true, parse(str) { var data = str.match(/^(add|query|set)(?: ([0-9]+|day|night))?/); if(!data) return false; @@ -68,6 +70,7 @@ module.exports.player=function(player,serv){ base: 'day', info: 'to change a time to day', usage: '/day', + op: true, action() { return player.handleCommand('time set day'); } diff --git a/src/lib/plugins/login.js b/src/lib/plugins/login.js index 563c384..9d9cf02 100644 --- a/src/lib/plugins/login.js +++ b/src/lib/plugins/login.js @@ -38,6 +38,7 @@ module.exports.player=function(player,serv) player.health = 20; player.food = 20; player.crouching = false; // Needs added in prismarine-entity later + player.op = true; // REMOVE THIS WHEN OUT OF TESTING player.username=player._client.username; serv.players.push(player); serv.uuidToPlayer[player._client.uuid] = player; diff --git a/src/lib/plugins/moderation.js b/src/lib/plugins/moderation.js index 3378e4d..98b0444 100644 --- a/src/lib/plugins/moderation.js +++ b/src/lib/plugins/moderation.js @@ -71,6 +71,7 @@ module.exports.player=function(player,serv) base: 'kick', info: 'to kick a player', usage: '/kick [reason]', + op: true, parse(str) { if(!str.match(/([a-zA-Z0-9_]+)(?: (.*))?/)) return false; @@ -95,6 +96,7 @@ module.exports.player=function(player,serv) base: 'ban', info: 'to ban a player', usage: '/ban [reason]', + op: true, parse(str) { if(!str.match(/([a-zA-Z0-9_]+)(?: (.*))?/)) return false; @@ -125,6 +127,7 @@ module.exports.player=function(player,serv) base: 'pardon', info: 'to pardon a player', usage: '/pardon ', + op: true, parse(str) { if(!str.match(/([a-zA-Z0-9_]+)/)) return false; diff --git a/src/lib/plugins/particle.js b/src/lib/plugins/particle.js index 41b4768..f5824a5 100644 --- a/src/lib/plugins/particle.js +++ b/src/lib/plugins/particle.js @@ -29,6 +29,7 @@ module.exports.player=function(player,serv){ base: 'particle', info: 'emit a particle at a position', usage: '/particle [amount] [ ]', + op: true, parse(str) { var results=str.match(/(\d+)(?: (\d+))?(?: (\d+))?(?: (\d+))?(?: (\d+))?(?: (\d+))?/); if(!results) return false; diff --git a/src/lib/plugins/players.js b/src/lib/plugins/players.js index 570f289..dcd4122 100644 --- a/src/lib/plugins/players.js +++ b/src/lib/plugins/players.js @@ -19,6 +19,7 @@ module.exports.player=function(player){ aliases: ['gm'], info: 'to change game mode', usage: '/gamemode <0-3>', + op: true, parse(str) { var results; if(!(results = str.match(/^([0-3])$/))) diff --git a/src/lib/plugins/pvp.js b/src/lib/plugins/pvp.js index f5c85e4..a9cc304 100644 --- a/src/lib/plugins/pvp.js +++ b/src/lib/plugins/pvp.js @@ -39,6 +39,7 @@ module.exports.player=function(player,serv) base: 'killall', info: 'Kill everything', usage: '/killall', + op: true, action() { Object.keys(serv.entities).forEach(key => serv.entities[key].takeDamage({damage:20})); } diff --git a/src/lib/plugins/sound.js b/src/lib/plugins/sound.js index 678a698..29292c7 100644 --- a/src/lib/plugins/sound.js +++ b/src/lib/plugins/sound.js @@ -68,6 +68,7 @@ module.exports.player=function(player,serv) { base: 'playsound', info: 'to play sound for yourself', usage: '/playsound [volume] [pitch]', + op: true, parse(str) { var results=str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/); if(!results) return false; @@ -87,6 +88,7 @@ module.exports.player=function(player,serv) { base: 'playsoundforall', info: 'to play sound for everyone', usage: '/playsoundforall [volume] [pitch]', + op: true, parse(str) { var results=str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/); if(!results) return false; diff --git a/src/lib/plugins/spawn.js b/src/lib/plugins/spawn.js index 36ce4c5..39eb868 100644 --- a/src/lib/plugins/spawn.js +++ b/src/lib/plugins/spawn.js @@ -72,6 +72,7 @@ module.exports.player=function(player,serv){ base: 'spawn', info: 'Spawn a mob', usage: '/spawn ', + op: true, parse(str) { var results=str.match(/(\d+)/); if (!results) return false; @@ -90,6 +91,7 @@ module.exports.player=function(player,serv){ base: 'spawnObject', info: 'Spawn an object', usage: '/spawnObject ', + op: true, parse(str) { var results=str.match(/(\d+)/); if (!results) return false; @@ -108,6 +110,7 @@ module.exports.player=function(player,serv){ base: 'summon', info: 'Summon an entity', usage: '/summon ', + op: true, action(name) { var entity=entitiesByName[name]; if(!entity) { @@ -124,6 +127,7 @@ module.exports.player=function(player,serv){ base: 'attach', info: 'attach an entity on an other entity', usage: '/attach ', + op: true, parse(str) { var pars=str.split(' '); if(pars.length!=2) diff --git a/src/lib/plugins/tp.js b/src/lib/plugins/tp.js index adf8be6..534b4e1 100644 --- a/src/lib/plugins/tp.js +++ b/src/lib/plugins/tp.js @@ -4,7 +4,7 @@ module.exports.player = (player, serv) => { var getPos = (num, dir='x', p=player) => { if (num[0] == '~') return p.position[dir] + parseInt(num.slice(1, num.length) || 0)*32; - else return parseInt(num); + else return parseInt(num)*32; } player.commands.add({ @@ -12,6 +12,7 @@ module.exports.player = (player, serv) => { aliases: ['tp'], info: 'to teleport a player', usage: '/teleport [target player] [y] [z]', + op: true, parse(str) { return str.match(/^(((\w* )?~?-?\d* ~?-?\d* ~?-?\d*)|(\w* \w*))$/) ? str.split(' ') : false; }, diff --git a/src/lib/plugins/world.js b/src/lib/plugins/world.js index 97ee6bf..04378a9 100644 --- a/src/lib/plugins/world.js +++ b/src/lib/plugins/world.js @@ -179,6 +179,7 @@ module.exports.player=function(player,serv,settings) { base: 'changeworld', info: 'to change world', usage: '/changeworld overworld|nether', + op: true, action(world) { if(world=="nether") player.changeWorld(serv.netherworld, {dimension: -1}); if(world=="overworld") player.changeWorld(serv.overworld, {dimension: 0});