Added inventory module for bukkit too

This commit is contained in:
walterhiggins 2015-03-24 19:37:44 +00:00
parent 1a4b087562
commit 06d80171fb
6 changed files with 47 additions and 28 deletions

View file

@ -4603,8 +4603,6 @@ The inventory module exposes a single function which when passed a player or NPC
* remove : removes items from the inventory (Expects parameters of type `net.canarymod.api.inventory.Item` - I strongly recommend using the `items` module for constructing items)
* contains : checks to see if there is the specified type and amount of item in the inventory (Expects parameters of type `net.canarymod.api.inventory.Item` - I strongly recommend using the `items` module for constructing items)
The Inventory module currently only works with CanaryMod.
## Classroom Plugin
The `classroom` object contains a couple of utility functions for use

View file

@ -0,0 +1,18 @@
function inventory(entity){
var inv = entity.inventory;
var result = {
add: function(items){
inv.addItem([items]);
return result;
},
remove: function(items){
inv.removeItem([items]);
return result;
},
contains: function(items){
return inv['contains(org.bukkit.inventory.ItemStack)'](items);
}
};
return result;
}
module.exports = inventory;

View file

@ -1,11 +1,12 @@
var bkItemStack = org.bukkit.inventory.ItemStack;
/*global require, module, Packages */
var bkItemStack = Packages.org.bukkit.inventory.ItemStack;
var bkMaterial = Packages.org.bukkit.Material;
var items = function( material, amount ) {
material = material.toUpperCase();
return new bkItemStack(bukkit.material[material],amount);
return new bkItemStack(bkMaterial[material],amount);
};
var materials = bukkit.material.values();
var materials = bkMaterial.values();
for (var i = 0;i < materials.length; i++ ){
var name = (''+materials[i].name()).toLowerCase();

View file

@ -0,0 +1,20 @@
function inventory(entity){
var inv = entity.inventory;
var result = {
add: function(items){
inv['addItem(net.canarymod.api.inventory.Item)'](items);
return result;
},
remove: function(items){
inv['decreaseItemStackSize(int, int)'](items.id, items.amount);
return result;
},
contains: function(items){
var type = items.type;
var amount = items.amount;
return inv['hasItemStack(ItemType, int )'](type, amount);
}
};
return result;
}
module.exports = inventory;

View file

@ -35,26 +35,9 @@ The inventory module exposes a single function which when passed a player or NPC
* remove : removes items from the inventory (Expects parameters of type `net.canarymod.api.inventory.Item` - I strongly recommend using the `items` module for constructing items)
* contains : checks to see if there is the specified type and amount of item in the inventory (Expects parameters of type `net.canarymod.api.inventory.Item` - I strongly recommend using the `items` module for constructing items)
The Inventory module currently only works with CanaryMod.
***/
function inventory(entity){
var inv = entity.inventory;
var result = {
add: function(items){
inv['addItem(net.canarymod.api.inventory.Item)'](items);
return result;
},
remove: function(items){
inv['decreaseItemStackSize(int, int)'](items.id, items.amount);
return result;
},
contains: function(items){
var type = items.type;
var amount = items.amount;
return inv['hasItemStack(ItemType, int )'](type, amount);
}
};
return result;
if ( __plugin.canary ) {
module.exports = require('../canary/inventory');
} else {
module.exports = require('../bukkit/inventory');
}
module.exports = inventory;

View file

@ -169,4 +169,3 @@ function onCanaryArrowHit( event ) {
}
}
events.projectileHit( __plugin.bukkit ? onBukkitArrowHit : onCanaryArrowHit);