fixes issue #199

This commit is contained in:
walterhiggins 2015-01-17 09:31:14 +00:00
parent 74a97e0ca0
commit 2fad33b35d
2 changed files with 85 additions and 4 deletions

View file

@ -400,6 +400,9 @@ Walter Higgins
* [signs.getTargetedBy() function](#signsgettargetedby-function) * [signs.getTargetedBy() function](#signsgettargetedby-function)
* [Sounds Module](#sounds-module) * [Sounds Module](#sounds-module)
* [Usage (Bukkit) :](#usage-bukkit-) * [Usage (Bukkit) :](#usage-bukkit-)
* [Teleport Module](#teleport-module)
* [Parameters](#parameters)
* [Example](#example-2)
* [Utilities Module](#utilities-module) * [Utilities Module](#utilities-module)
* [utils.player() function](#utilsplayer-function) * [utils.player() function](#utilsplayer-function)
* [utils.world( worldName ) function](#utilsworld-worldname--function) * [utils.world( worldName ) function](#utilsworld-worldname--function)
@ -456,7 +459,7 @@ Walter Higgins
* [Administration options](#administration-options) * [Administration options](#administration-options)
* [NumberGuess mini-game:](#numberguess-mini-game) * [NumberGuess mini-game:](#numberguess-mini-game)
* [Description](#description-1) * [Description](#description-1)
* [Example](#example-2) * [Example](#example-3)
* [Cow Clicker Mini-Game](#cow-clicker-mini-game) * [Cow Clicker Mini-Game](#cow-clicker-mini-game)
* [How to Play](#how-to-play) * [How to Play](#how-to-play)
* [Rules](#rules) * [Rules](#rules)
@ -4820,6 +4823,36 @@ Example
<p style="color:gold;font-weight:bold">Hello World</p> <p style="color:gold;font-weight:bold">Hello World</p>
## 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');
```
## Utilities Module ## Utilities Module
The `utils` module is a storehouse for various useful utility The `utils` module is a storehouse for various useful utility

View file

@ -1,10 +1,58 @@
function teleport( entity, location){ '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;
}
}
if (__plugin.bukkit){ if (__plugin.bukkit){
var bkTeleportCause = org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; var bkTeleportCause = org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
entity.teplort( location, bkTeleportCause.PLUGIN); entity.teleport( destination, bkTeleportCause.PLUGIN);
} }
if (__plugin.canary){ if (__plugin.canary){
entity['teleportTo(Location)'](location); entity['teleportTo(Location)'](destination);
} }
} }
module.exports = teleport; module.exports = teleport;