From 30c4667a2bb6e41c35a86afd28114e4570466068 Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Sun, 25 Jan 2015 19:11:18 +0000 Subject: [PATCH] created new 'slash' module for executing commands. --- src/main/js/modules/slash.js | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/js/modules/slash.js diff --git a/src/main/js/modules/slash.js b/src/main/js/modules/slash.js new file mode 100644 index 0000000..148b9fa --- /dev/null +++ b/src/main/js/modules/slash.js @@ -0,0 +1,53 @@ +'use strict'; +/*global module, require, server, __plugin*/ +var _ = require('underscore'); +/************************************************************************ +## The slash Module + +This module provides a single function which makes it easy to execute +minecraft commands via javascript. + +### The slash() function + +This function makes it easy to execute one or more minecraft commands. + +#### Parameters + + * commands : A String or Array of strings - each string is a command to be executed. + * sender: The player or server on whose behalf the commands should be executed. + +#### Examples + +Invoke the `/defaultgamemode creative` command (as server). + +```javascript +var slash = require('slash'); +slash('defaultgamemode creative', server); +``` + +Set the time of day to Midday and toggle downfall: + +```javascript +var slash = require('slash'); +slash([ + 'time set 6000', + 'toggledownfall' +], server); +``` + +***/ +function slash( commands, sender ){ + if (_.isArray(commands)){ + _.each(commands, function(command){ + slash(command, sender); + }); + return; + } + if (__plugin.canary){ + server.executeVanillaCommand(sender, commands); + } + if (__plugin.bukkit){ + server.dispatchCommand(sender, commands); + } +} +module.exports = slash;