This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/js/plugins/examples/example-4-hello-parameters.js
walterhiggins 19162c3688 First phase of transition from Bukkit to Canary.
Some of the plugins are not yet supported.
If you're feeling brave you can build from source using ant.
2014-09-29 23:42:41 +01:00

41 lines
1.3 KiB
JavaScript

/*************************************************************************
## Example Plugin #4 - Using parameters in commands.
A simple minecraft plugin. Handling parameters.
### Usage:
At the in-game prompt type ...
/jsp hello-params Hi
/jsp hello-params Saludos
/jsp hello-params Greetings
... and a message `Hi {player-name}` or `Saludos {player-name}` etc
will appear (where {player-name} is replaced by your own name).
This example demonstrates adding and using parameters in commands.
This differs from example 3 in that the greeting can be changed from
a fixed 'Hello ' to anything you like by passing a parameter.
command( 'hello-params', function ( parameters, player ) {
var salutation = parameters[0] ;
echo( player, salutation + ' ' + player.name );
});
***/
command('hello-params', function( parameters, player ) {
/*
parameters is an array (or list) of strings. parameters[0]
refers to the first element in the list. Arrays in Javascript
are 0-based. That is, the 1st element is parameters[0], the 2nd
element is parameters[1], the 3rd element is parameters[2] and
so on. In this example, parameters[1] refers to the first word
which appears after `jsp hello-params `.
*/
var salutation = parameters[0] ;
echo( player, salutation + ' ' + player.name );
});