put modpe in its own command namespace (/modpe <command>), add the same /time command that minecraft has

This commit is contained in:
Romain Beaumont 2015-10-10 15:56:47 +02:00
parent 7fd8e56d3e
commit 51148036e4
3 changed files with 23 additions and 9 deletions

View file

@ -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.");
}

View file

@ -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
}
})
}

View file

@ -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);
});