mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-23 18:42:44 +00:00
Added arguments information
parent
ef57812742
commit
5fc1dbbe7d
@ -1,3 +1,36 @@
|
||||
## Arguments
|
||||
|
||||
When calling a JavaScript placeholder, arguments may be supplied for extra functionality. These arguments are included after the placeholder name, and are separated by commas. When included, the arguments are passed to the script through an array called `args`.
|
||||
|
||||
For example, the arguments in the placeholder `%javascript_example_test,3,args%` would be `test`, `3`, and `args`.
|
||||
|
||||
Here is an example that returns a random number between the given arguments.
|
||||
|
||||
```Javascript
|
||||
var min = 1;
|
||||
var max = 25;
|
||||
|
||||
function randomInteger() {
|
||||
if (args.length == 2) {
|
||||
min = args[0];
|
||||
max = args[1];
|
||||
}
|
||||
|
||||
var random = Math.random() * (max - min);
|
||||
random += min;
|
||||
|
||||
return Math.floor(random);
|
||||
}
|
||||
|
||||
randomInteger();
|
||||
```
|
||||
|
||||
Note that it is a good idea to include defaults, or at the very least check that the arguments exist before using them. In the example above, the defaults are `min = 1` and `max = 25`. So, if the above script were called without any arguments, a random integer between 1 and 25 would still be returned.
|
||||
|
||||
Examples (assuming the identifier is called _randomintbetween_):
|
||||
- `%javascript_randomintbetween_5,100%` would return a random integer between 5 and 100.
|
||||
- `%javascript_randomintbetween_200,5000%` would return a random integer between 200 and 5000.
|
||||
|
||||
## Player Information
|
||||
|
||||
When a placeholder script is called, the player that is passed to the Javascript-Expansion is also passed to the placeholder script. This player can be accessed with `BukkitPlayer`. After receiving, you can access all of the [player methods](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Player.html) included in the Spigot API.
|
||||
|
Loading…
x
Reference in New Issue
Block a user