2015-01-17 10:31:14 +01:00
|
|
|
'use strict';
|
|
|
|
/*global __plugin, org, module, require*/
|
|
|
|
var utils = require('utils');
|
|
|
|
/************************************************************************
|
|
|
|
## Teleport Module
|
|
|
|
|
|
|
|
This module provides a function to teleport entities (Players or NPCs).
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
|
|
* entity - The player or NPC to be teleported. If of type String, then a player with that name will be teleported.
|
|
|
|
* destination - The location to which they should be teleported. If not of type Location but is a Player, Block or any
|
|
|
|
object which has a `location` property then that works too. If of type String, then it's assumed that the destination is the player with that name.
|
|
|
|
|
|
|
|
### Example
|
|
|
|
|
|
|
|
The following code will teleport each player back to their spawn position.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
var teleport = require('teleport'),
|
|
|
|
utils = require('utils'),
|
|
|
|
players = utils.players(),
|
|
|
|
i = 0;
|
|
|
|
for ( ; i < players.length; i++ ) {
|
|
|
|
teleport( players[i], players[i].spawnPosition );
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The following code will teleport 'tom' to 'jane's location.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
var teleport = require('teleport');
|
|
|
|
teleport('tom' , 'jane');
|
|
|
|
```
|
|
|
|
***/
|
|
|
|
function teleport( entity, destination){
|
|
|
|
if (typeof entity === 'String' || entity instanceof java.lang.String){
|
|
|
|
entity = utils.player(entity);
|
|
|
|
}
|
|
|
|
if (typeof destination === 'String' || destination instanceof java.lang.String){
|
|
|
|
var player = utils.player(destination);
|
|
|
|
if (player){
|
|
|
|
destination = player.location;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (destination.location){
|
|
|
|
destination = destination.location;
|
|
|
|
}
|
|
|
|
}
|
2015-01-11 01:09:56 +01:00
|
|
|
if (__plugin.bukkit){
|
|
|
|
var bkTeleportCause = org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2015-01-17 10:31:14 +01:00
|
|
|
entity.teleport( destination, bkTeleportCause.PLUGIN);
|
2015-01-11 01:09:56 +01:00
|
|
|
}
|
|
|
|
if (__plugin.canary){
|
2015-01-17 10:31:14 +01:00
|
|
|
entity['teleportTo(Location)'](destination);
|
2015-01-11 01:09:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = teleport;
|