From 51148036e492748fa5d923ae984d453ec10ecbbd Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sat, 10 Oct 2015 15:56:47 +0200 Subject: [PATCH] put modpe in its own command namespace (/modpe ), add the same /time command that minecraft has --- src/lib/playerPlugins/commands.js | 19 +++++++++++++++++-- src/lib/serverPlugins/daycycle.js | 4 +++- src/lib/serverPlugins/modpe.js | 9 +++------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/lib/playerPlugins/commands.js b/src/lib/playerPlugins/commands.js index 91e839d..707fba5 100644 --- a/src/lib/playerPlugins/commands.js +++ b/src/lib/playerPlugins/commands.js @@ -5,8 +5,6 @@ module.exports = inject; function inject(serv, player, options) { function handleCommand(command) { var results; - if (options.modpe) - player.chat("§1######## VANILLA ########"); if (options.commands[command]) player.chat("" + options.commands[command]); else if (results = command.match(/^gamemode ([0-3])$/)) { @@ -81,6 +79,23 @@ function inject(serv, player, options) { .catch(err => player.chat(results[1] + " is not banned")); } } + else if(results = command.match(/^time (add|query|set)(?: ([0-9]+))?/)) { + var action=results[1]; + var value=results[2]!==undefined ? parseInt(results[2]) : null; + if(action=="query") + player.chat("It is "+serv.time); + else if(action=="set") { + player.chat("Time was changed from "+serv.time+" to "+value); + serv.setTime(value); + } + else if(action=="add") { + player.chat("Time was changed from "+serv.time+" to "+(value + serv.time)); + serv.setTime(value + serv.time); + } + } + else if(results = command.match(/^modpe (.+)$/)) { + player.emit("modpe",results[1]); + } else player.chat("Invalid command."); } diff --git a/src/lib/serverPlugins/daycycle.js b/src/lib/serverPlugins/daycycle.js index 1331193..fd8f61e 100644 --- a/src/lib/serverPlugins/daycycle.js +++ b/src/lib/serverPlugins/daycycle.js @@ -16,6 +16,8 @@ function inject(serv, settings) { serv.on('tick', function(count) { if (!serv.doDaylightCycle) return; - if (count % 20 == 0) serv.setTime((serv.time + 20) % 24000); // Vanilla only does it every second + if (count % 20 == 0) { + serv.setTime((serv.time + 20) % 24000); // Vanilla only does it every second + } }) } \ No newline at end of file diff --git a/src/lib/serverPlugins/modpe.js b/src/lib/serverPlugins/modpe.js index 84082d6..0c7b9f1 100644 --- a/src/lib/serverPlugins/modpe.js +++ b/src/lib/serverPlugins/modpe.js @@ -183,11 +183,9 @@ function inject(serv,settings) serv.world.getBlockType(new vec3(packet.location.x, packet.location.y, packet.location.z))); }); - player._client.on('chat', function (packet) { - if(packet.message[0]=="/") { - var command = packet.message.slice(1); - procCmd(command); - } + player.on('modpe', function (command) { + console.log(command); + procCmd(command); }); function newLevel() { @@ -216,7 +214,6 @@ function inject(serv,settings) } function procCmd(command) { - player.chat("§2######### MODPE #########"); mods.forEach(function (element, index, array) { element.procCmd(command); });