2013-12-31 21:33:00 +01:00
|
|
|
/*************************************************************************
|
2014-01-04 19:39:49 +01:00
|
|
|
## Example Plugin #6 - Re-use - Using 'utils' to get Player objects.
|
2013-12-31 21:33:00 +01:00
|
|
|
|
|
|
|
A simple minecraft plugin. Finding players by name.
|
|
|
|
|
|
|
|
### Usage:
|
|
|
|
|
|
|
|
At the in-game prompt type ...
|
2013-12-31 19:21:40 +01:00
|
|
|
|
2013-12-31 21:33:00 +01:00
|
|
|
/jsp hello-byname {player-name}
|
2013-12-31 19:21:40 +01:00
|
|
|
|
2013-12-31 21:33:00 +01:00
|
|
|
... substituting {player-name} with the name of a player currently
|
|
|
|
online and a message `Hello ...` will be sent to the named
|
|
|
|
player.
|
2013-12-31 19:21:40 +01:00
|
|
|
|
2013-12-31 21:33:00 +01:00
|
|
|
This example builds on example-5 and also introduces a new concept -
|
|
|
|
use of shared modules. That is : modules which are not specific to
|
|
|
|
any one plugin or set of plugins but which can be used by all
|
|
|
|
plugins. Shared modules should be placed in the
|
|
|
|
`scriptcraft/modules` directory.
|
2013-12-31 19:21:40 +01:00
|
|
|
|
2013-12-31 22:09:50 +01:00
|
|
|
* The utils module is used. Because the 'utils' module is
|
|
|
|
located in the modules folder we don't need to specify an exact
|
|
|
|
path, just 'utils' will do.
|
2013-12-31 19:21:40 +01:00
|
|
|
|
2013-12-31 22:09:50 +01:00
|
|
|
* The `utils.player()` function is used to obtain a player object
|
|
|
|
matching the player name. Once a player object is obtained, a
|
|
|
|
message is sent to that player.
|
|
|
|
|
|
|
|
Source Code ...
|
2013-12-31 21:33:00 +01:00
|
|
|
|
|
|
|
var utils = require('utils');
|
|
|
|
var greetings = require('./example-1-hello-module');
|
|
|
|
|
|
|
|
command('hello-byname', function( parameters, sender ) {
|
|
|
|
var playerName = parameters[0];
|
|
|
|
var recipient = utils.player(playerName);
|
|
|
|
if (recipient)
|
|
|
|
greetings.hello(recipient);
|
|
|
|
else
|
|
|
|
sender.sendMessage('Player ' + playerName + ' not found.');
|
|
|
|
});
|
2013-12-31 22:09:50 +01:00
|
|
|
|
2013-12-31 21:33:00 +01:00
|
|
|
***/
|
2013-12-31 19:21:40 +01:00
|
|
|
|
|
|
|
var utils = require('utils');
|
|
|
|
var greetings = require('./example-1-hello-module');
|
|
|
|
|
|
|
|
command('hello-byname', function( parameters, sender ) {
|
|
|
|
var playerName = parameters[0];
|
|
|
|
var recipient = utils.player(playerName);
|
|
|
|
if (recipient)
|
|
|
|
greetings.hello(recipient);
|
|
|
|
else
|
|
|
|
sender.sendMessage('Player ' + playerName + ' not found.');
|
|
|
|
});
|