This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/js/modules/entities.js

39 lines
915 B
JavaScript
Raw Normal View History

2015-11-21 18:07:40 +01:00
'use strict';
2015-12-30 14:01:11 +01:00
/*global __plugin, org, Packages, module, exports*/
2015-11-21 18:07:40 +01:00
var entities = {},
entitytypes,
t, i, name;
if (__plugin.bukkit) {
entitytypes = org.bukkit.entity.EntityType.values();
}
if (__plugin.canary) {
entitytypes = Packages.net.canarymod.api.entity.EntityType.values();
}
2015-12-30 14:01:11 +01:00
function getEntityHandler( entityType ) {
return function( entity ){
if (arguments.length == 0){
return entityType;
}
if (arguments.length == 1){
if (entity){
if (__plugin.bukkit){
return entity.type == entityType;
}
if (__plugin.canary){
return entity.entityType == entityType;
}
}
}
return null;
};
}
2015-11-21 18:07:40 +01:00
for (t in entitytypes) {
if (entitytypes[t] && entitytypes[t].ordinal) {
2015-12-30 14:01:11 +01:00
name = ('' + entitytypes[t].name()).replace(/^(.*)/,function(a){
return a.toLowerCase();
});
entities[name] = getEntityHandler(entitytypes[t]);
2015-11-21 18:07:40 +01:00
}
}
module.exports = entities;