fix issue #312 - updated slash docs and code

This commit is contained in:
BuildTools 2016-12-20 16:38:20 +00:00
parent 18add90fff
commit 9b113e2c9b
2 changed files with 22 additions and 11 deletions

View file

@ -5240,7 +5240,7 @@ This function makes it easy to execute one or more minecraft commands.
#### Parameters #### Parameters
* commands : A String or Array of strings - each string is a command to be executed. * 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 #### Examples
@ -5248,17 +5248,20 @@ Invoke the `/defaultgamemode creative` command (as server).
```javascript ```javascript
var slash = require('slash'); 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 ```javascript
var slash = require('slash'); var slash = require('slash'),
utils = require('utils');
var johnDoe = utils.player('John_Doe');
slash([ slash([
'time set 6000', 'time set 6000',
'toggledownfall' 'toggledownfall'
], server); ], johnDoe);
``` ```
## Sounds Module ## Sounds Module

View file

@ -14,7 +14,7 @@ This function makes it easy to execute one or more minecraft commands.
#### Parameters #### Parameters
* commands : A String or Array of strings - each string is a command to be executed. * 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 #### Examples
@ -22,17 +22,20 @@ Invoke the `/defaultgamemode creative` command (as server).
```javascript ```javascript
var slash = require('slash'); 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 ```javascript
var slash = require('slash'); var slash = require('slash'),
utils = require('utils');
var johnDoe = utils.player('John_Doe');
slash([ slash([
'time set 6000', 'time set 6000',
'toggledownfall' 'toggledownfall'
], server); ], johnDoe);
``` ```
***/ ***/
@ -51,7 +54,12 @@ function slash( commands, sender ){
} }
} }
if (__plugin.bukkit){ if (__plugin.bukkit){
if (!sender){
// if sender is not specified assume server console
server.dispatchCommand(server.consoleSender, commands);
} else {
server.dispatchCommand(sender, commands); server.dispatchCommand(sender, commands);
} }
} }
}
module.exports = slash; module.exports = slash;