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/canary/items.js
walterhiggins 19162c3688 First phase of transition from Bukkit to Canary.
Some of the plugins are not yet supported.
If you're feeling brave you can build from source using ant.
2014-09-29 23:42:41 +01:00

46 lines
1.2 KiB
JavaScript

var ItemType = Packages.net.canarymod.api.inventory.ItemType;
var Canary = Packages.net.canarymod.Canary;
var itemFactory = Canary.factory().itemFactory;
function items( material, amount ) {
material = material.toUpperCase();
var result = itemFactory["newItem(net.canarymod.api.inventory.ItemType)"](material);
result.amount = amount;
return result;
}
var materials = ItemType.class.getDeclaredFields();
for (var i = 0;i < materials.length; i++ ){
if (materials[i].type != ItemType.class) {
continue;
}
var materialField = materials[i];
var name = (''+materialField.name).replace(/^(.)/,function(a){ return a.toLowerCase() });
items[name] = (function(material){
return function(amount){
if (typeof amount == 'undefined'){
return material;
}
if (typeof amount == 'number'){
var itemStack = itemFactory["newItem(net.canarymod.api.inventory.ItemType)"](material);
itemStack.amount = amount;
return itemStack;
} else {
var result = (amount == material);
if (!result){
if (amount.getId && amount.getData){
var m2 = ItemType.fromIdAndData(amount.id, amount.data);
result = (m2 == material);
}
}
return result;
}
};
})(materialField.get(ItemType));
}
module.exports = items;