use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class ItemAttributeNBT method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("nbt_attributes")) {
dList list = mechanism.getValue().asType(dList.class);
ItemStack itemStack = item.getItemStack();
for (String string : list) {
String[] split = string.split("/");
String attribute = EscapeTags.unEscape(split[0]);
String slot = EscapeTags.unEscape(split[1]);
int op = new Element(split[2]).asInt();
double amt = new Element(split[3]).asDouble();
itemStack = CustomNBT.addAttribute(itemStack, attribute, slot, op, amt);
}
item.setItemStack(itemStack);
}
}
use of org.bukkit.inventory.ItemStack in project Bukkit by Bukkit.
the class ConfigurationSectionTest method testGetItemStack_String_ItemStack.
@Test
public void testGetItemStack_String_ItemStack() {
ConfigurationSection section = getConfigurationSection();
String key = "exists";
ItemStack value = new ItemStack(Material.WOOD, 50, (short) 2);
ItemStack def = new ItemStack(Material.STONE, 1);
section.set(key, value);
assertEquals(value, section.getItemStack(key, def));
assertEquals(def, section.getItemStack("doesntExist", def));
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class FireworkBurstsScriptEvent method getContext.
@Override
public dObject getContext(String name) {
if (name.equals("entity")) {
return entity;
} else if (name.equals("location")) {
return location;
} else if (name.equals("item")) {
ItemStack itemStack = new ItemStack(Material.FIREWORK);
itemStack.setItemMeta(event.getEntity().getFireworkMeta());
return new dItem(itemStack);
}
return super.getContext(name);
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class PlayerEquipsArmorScriptEvent method handleChangedArmor.
private void handleChangedArmor(final Player player, final String reason) {
EntityEquipment oldEquipment = player.getEquipment();
final ItemStack oldHelmet = oldEquipment.getHelmet();
final ItemStack oldChestplate = oldEquipment.getChestplate();
final ItemStack oldLeggings = oldEquipment.getLeggings();
final ItemStack oldBoots = oldEquipment.getBoots();
Bukkit.getScheduler().runTaskLater(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
EntityEquipment newEquipment = player.getEquipment();
handleEvent(player, "helmet", oldHelmet, newEquipment.getHelmet(), reason);
handleEvent(player, "chestplate", oldChestplate, newEquipment.getChestplate(), reason);
handleEvent(player, "leggings", oldLeggings, newEquipment.getLeggings(), reason);
handleEvent(player, "boots", oldBoots, newEquipment.getBoots(), reason);
}
}, 1);
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class ItemRecipeFormedScriptEvent method onRecipeFormed.
@EventHandler
public void onRecipeFormed(PrepareItemCraftEvent event) {
HumanEntity humanEntity = event.getView().getPlayer();
if (dEntity.isNPC(humanEntity)) {
return;
}
Recipe eRecipe = event.getRecipe();
if (eRecipe == null || eRecipe.getResult() == null) {
return;
}
inventory = event.getInventory();
result = new dItem(eRecipe.getResult());
recipe = new dList();
for (ItemStack itemStack : inventory.getMatrix()) {
if (itemStack != null) {
recipe.add(new dItem(itemStack).identify());
} else {
recipe.add(new dItem(Material.AIR).identify());
}
}
player = dEntity.getPlayerFrom(humanEntity);
resultChanged = false;
cancelled = false;
fire();
if (cancelled) {
inventory.setResult(null);
} else if (resultChanged) {
inventory.setResult(result.getItemStack());
}
}
Aggregations