Search in sources :

Example 41 with ItemStack

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);
    }
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) ItemStack(org.bukkit.inventory.ItemStack)

Example 42 with 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));
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 43 with ItemStack

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);
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) ItemStack(org.bukkit.inventory.ItemStack)

Example 44 with ItemStack

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);
}
Also used : EntityEquipment(org.bukkit.inventory.EntityEquipment) ItemStack(org.bukkit.inventory.ItemStack)

Example 45 with ItemStack

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());
    }
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) Recipe(org.bukkit.inventory.Recipe) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)1282 Player (org.bukkit.entity.Player)262 EventHandler (org.bukkit.event.EventHandler)183 ItemMeta (org.bukkit.inventory.meta.ItemMeta)167 ArrayList (java.util.ArrayList)130 Inventory (org.bukkit.inventory.Inventory)115 Location (org.bukkit.Location)88 Material (org.bukkit.Material)87 PlayerInventory (org.bukkit.inventory.PlayerInventory)84 Entity (org.bukkit.entity.Entity)63 Block (org.bukkit.block.Block)52 TagCompound (de.keyle.knbt.TagCompound)47 Map (java.util.Map)44 LivingEntity (org.bukkit.entity.LivingEntity)44 HashMap (java.util.HashMap)40 Mage (com.elmakers.mine.bukkit.api.magic.Mage)39 Enchantment (org.bukkit.enchantments.Enchantment)38 SkullMeta (org.bukkit.inventory.meta.SkullMeta)38 Vector (org.bukkit.util.Vector)35 Test (org.junit.Test)32