2015-11-21 18:07:40 +01:00
/*global require, module, __plugin, Packages*/
'use strict' ;
var entities = require ( 'entities' ) ;
2016-12-20 18:12:43 +01:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# # Spawn Module
2015-11-21 18:07:40 +01:00
2016-12-20 18:12:43 +01:00
Provides a single function to 'spawn' an entity at a given location .
# # # Parameters
* entityType - < String | Object > The type of entity to spawn . This can be a string ( see entities module for reference ) or a framework - specific object type ( see https : //hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html). A list of [all possible entities][ents] functions (equivalent to the EntityType enum).
* location - where the entity should be spawned .
[ ents ] : # entities - module
# # # Example
Using the entities module as a helper , spawn a new polar bear at the world ' s default spawn location :
` ` ` javascript
var entities = require ( 'entities' ) ,
spawn = require ( 'spawn' ) ;
...
var spawnLocation = world . spawnLocation ;
spawn ( entities . polar _bear ( ) , spawnLocation ) ;
` ` `
This module is in turn used by the Drone ' s ` spawn() ` method and the ` jsp spawn ` command .
* * * /
2015-11-21 18:07:40 +01:00
module . exports = function ( entityType , location ) {
2015-12-30 14:01:11 +01:00
var entityTypeFn ;
2015-11-21 18:07:40 +01:00
if ( typeof entityType === 'string' ) {
2015-12-30 14:01:11 +01:00
entityTypeFn = entities [ entityType . toLowerCase ( ) ] ;
entityType = entityTypeFn ( ) ;
2015-11-21 18:07:40 +01:00
}
var world = location . world ;
if ( _ _plugin . bukkit ) {
world . spawnEntity ( location , entityType ) ;
}
if ( _ _plugin . canary ) {
var Canary = Packages . net . canarymod . Canary ,
entityInstance = Canary . factory ( ) . entityFactory . newEntity ( entityType , location ) ;
entityInstance . spawn ( ) ;
}
} ;