From 9b113e2c9be4a1a74cbc5d1609125a384d1fd2f2 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 20 Dec 2016 16:38:20 +0000 Subject: [PATCH] fix issue #312 - updated slash docs and code --- docs/API-Reference.md | 13 ++++++++----- src/main/js/modules/slash.js | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/docs/API-Reference.md b/docs/API-Reference.md index 0a4f849..3316238 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -5240,7 +5240,7 @@ 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. + * sender: (optional) The player on whose behalf the commands should be executed. If not specified the commands will be executed as the server console user. #### Examples @@ -5248,17 +5248,20 @@ Invoke the `/defaultgamemode creative` command (as server). ```javascript var slash = require('slash'); -slash('defaultgamemode creative', server); +slash('defaultgamemode creative'); ``` -Set the time of day to Midday and toggle downfall: +Set the time of day to Midday and toggle downfall (as player 'JohnDoe'): ```javascript -var slash = require('slash'); +var slash = require('slash'), + utils = require('utils'); +var johnDoe = utils.player('John_Doe'); + slash([ 'time set 6000', 'toggledownfall' -], server); +], johnDoe); ``` ## Sounds Module diff --git a/src/main/js/modules/slash.js b/src/main/js/modules/slash.js index 62dd942..92e66a7 100644 --- a/src/main/js/modules/slash.js +++ b/src/main/js/modules/slash.js @@ -14,7 +14,7 @@ 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. + * sender: (optional) The player on whose behalf the commands should be executed. If not specified the commands will be executed as the server console user. #### Examples @@ -22,17 +22,20 @@ Invoke the `/defaultgamemode creative` command (as server). ```javascript var slash = require('slash'); -slash('defaultgamemode creative', server); +slash('defaultgamemode creative'); ``` -Set the time of day to Midday and toggle downfall: +Set the time of day to Midday and toggle downfall (as player 'JohnDoe'): ```javascript -var slash = require('slash'); +var slash = require('slash'), + utils = require('utils'); +var johnDoe = utils.player('John_Doe'); + slash([ 'time set 6000', 'toggledownfall' -], server); +], johnDoe); ``` ***/ @@ -51,7 +54,12 @@ function slash( commands, sender ){ } } if (__plugin.bukkit){ - server.dispatchCommand(sender, commands); + if (!sender){ + // if sender is not specified assume server console + server.dispatchCommand(server.consoleSender, commands); + } else { + server.dispatchCommand(sender, commands); + } } } module.exports = slash;