forked from walterhiggins/ScriptCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawn.js
More file actions
49 lines (40 loc) · 1.55 KB
/
Copy pathspawn.js
File metadata and controls
49 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*global require, module, __plugin, Packages*/
'use strict';
var entities = require('entities');
/************************************************************************
## Spawn Module
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.
***/
module.exports = function(entityType, location) {
var entityTypeFn;
if (typeof entityType === 'string') {
entityTypeFn = entities[entityType.toLowerCase()];
entityType = entityTypeFn();
}
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();
}
};