Search in sources :

Example 36 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.

the class IPItem method setFlagValue.

/**
 * @param flagValue
 *            the flagValue to set
 */
public void setFlagValue(boolean flagValue) {
    this.flagValue = flagValue;
    description.clear();
    ItemMeta meta = item.getItemMeta();
    if (flagValue) {
        description.add(ChatColor.GREEN + "Allowed by all");
    } else {
        description.add(ChatColor.RED + "Disallowed for visitors");
    }
    meta.setLore(description);
    item.setItemMeta(meta);
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 37 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.

the class IPItem method createToggleableItem.

private void createToggleableItem(boolean flagValue, Material material, int durability, String name, UUID uuid) {
    this.flagValue = flagValue;
    this.slot = -1;
    this.name = name;
    this.type = Type.TOGGLE;
    description.clear();
    item = new ItemStack(material);
    item.setDurability((short) durability);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(ChatColor.WHITE + name);
    if (flagValue) {
        if (uuid == null)
            description.add(ChatColor.GREEN + ASkyBlock.getPlugin().myLocale().igsAllowed);
        else
            description.add(ChatColor.GREEN + ASkyBlock.getPlugin().myLocale(uuid).igsAllowed);
    } else {
        if (uuid == null)
            description.add(ChatColor.RED + ASkyBlock.getPlugin().myLocale().igsDisallowed);
        else
            description.add(ChatColor.RED + ASkyBlock.getPlugin().myLocale(uuid).igsDisallowed);
    }
    meta.setLore(description);
    // Remove extraneous info
    if (!Bukkit.getServer().getVersion().contains("1.7") && !Bukkit.getServer().getVersion().contains("1.8")) {
        meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
        meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
        meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
        meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
    }
    item.setItemMeta(meta);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 38 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.

the class MiniShopItem method getItemClean.

/**
 * Returns a clean version of this item with no meta data
 *
 * @return Clean item stack
 */
public ItemStack getItemClean() {
    ItemStack temp = this.item.clone();
    ItemMeta meta = temp.getItemMeta();
    meta.setDisplayName(null);
    List<String> lore = new ArrayList<String>(1);
    if (item.getType().equals(Material.MOB_SPAWNER)) {
        lore.add(Util.prettifyText(entityType.name()));
    }
    meta.setLore(lore);
    temp.setItemMeta(meta);
    return temp;
}
Also used : ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 39 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.

the class WarpPanel method updateText.

/**
 * Updates the meta text on the skull by looking at the warp sign
 * This MUST be run 1 TICK AFTER the sign has been created otherwise the sign is blank
 * @param playerSkull
 * @param playerUUID - the player's UUID
 * @return updated skull item stack
 */
private ItemStack updateText(ItemStack playerSkull, final UUID playerUUID) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Updating text on item");
    ItemMeta meta = playerSkull.getItemMeta();
    // get the sign info
    Location signLocation = plugin.getWarpSignsListener().getWarp(playerUUID);
    if (signLocation == null) {
        plugin.getWarpSignsListener().removeWarp(playerUUID);
        return playerSkull;
    }
    // Get the sign info if it exists
    if (signLocation.getBlock().getType().equals(Material.SIGN_POST) || signLocation.getBlock().getType().equals(Material.WALL_SIGN)) {
        Sign sign = (Sign) signLocation.getBlock().getState();
        List<String> lines = new ArrayList<String>(Arrays.asList(sign.getLines()));
        // Check for PVP and add warning
        Island island = plugin.getGrid().getIsland(playerUUID);
        if (island != null) {
            if ((signLocation.getWorld().equals(ASkyBlock.getIslandWorld()) && island.getIgsFlag(SettingsFlag.PVP)) || (signLocation.getWorld().equals(ASkyBlock.getNetherWorld()) && island.getIgsFlag(SettingsFlag.NETHER_PVP))) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: pvp warning added");
                lines.add(ChatColor.RED + plugin.myLocale().igs.get(SettingsFlag.PVP));
            }
        }
        meta.setLore(lines);
        if (DEBUG)
            plugin.getLogger().info("DEBUG: lines = " + lines);
    }
    playerSkull.setItemMeta(meta);
    return playerSkull;
}
Also used : ArrayList(java.util.ArrayList) Sign(org.bukkit.block.Sign) Island(com.wasteofplastic.acidisland.Island) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Location(org.bukkit.Location)

Example 40 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Prism-Bukkit by prism.

the class ItemStackAction method setItemStackFromNewDataFormat.

/**
	 * 
	 */
protected void setItemStackFromNewDataFormat() {
    if (data == null || !data.startsWith("{"))
        return;
    actionData = gson.fromJson(data, ItemStackActionData.class);
    item = new ItemStack(this.block_id, actionData.amt, (short) this.block_subid);
    // Restore enchantment
    if (actionData.enchs != null && actionData.enchs.length > 0) {
        for (final String ench : actionData.enchs) {
            final String[] enchArgs = ench.split(":");
            final Enchantment enchantment = Enchantment.getById(Integer.parseInt(enchArgs[0]));
            // Restore book enchantment
            if (item.getType().equals(Material.ENCHANTED_BOOK)) {
                final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
                bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
                item.setItemMeta(bookEnchantments);
            } else // Restore item enchantment
            {
                item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
            }
        }
    }
    // Leather color
    if (item.getType().name().contains("LEATHER_") && actionData.color > 0) {
        final LeatherArmorMeta lam = (LeatherArmorMeta) item.getItemMeta();
        lam.setColor(Color.fromRGB(actionData.color));
        item.setItemMeta(lam);
    } else // Skulls
    if (item.getType().equals(Material.SKULL_ITEM) && actionData.owner != null) {
        final SkullMeta meta = (SkullMeta) item.getItemMeta();
        meta.setOwner(actionData.owner);
        item.setItemMeta(meta);
    } else // Written books
    if (item.getItemMeta() instanceof BookMeta) {
        final BookMeta bookMeta = (BookMeta) item.getItemMeta();
        bookMeta.setAuthor(actionData.by);
        bookMeta.setTitle(actionData.title);
        bookMeta.setPages(actionData.content);
        item.setItemMeta(bookMeta);
    }
    // Fireworks
    if (block_id == 402 && actionData.effectColors != null && actionData.effectColors.length > 0) {
        final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) item.getItemMeta();
        final Builder effect = FireworkEffect.builder();
        if (actionData.effectColors != null) {
            for (int i = 0; i < actionData.effectColors.length; i++) {
                effect.withColor(Color.fromRGB(actionData.effectColors[i]));
            }
            fireworkMeta.setEffect(effect.build());
        }
        if (actionData.fadeColors != null) {
            for (int i = 0; i < actionData.fadeColors.length; i++) {
                effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
            }
            fireworkMeta.setEffect(effect.build());
        }
        if (actionData.hasFlicker) {
            effect.flicker(true);
        }
        if (actionData.hasTrail) {
            effect.trail(true);
        }
        fireworkMeta.setEffect(effect.build());
        item.setItemMeta(fireworkMeta);
    }
    // Item display names
    final ItemMeta meta = item.getItemMeta();
    if (actionData.name != null) {
        meta.setDisplayName(actionData.name);
    }
    if (actionData.lore != null) {
        meta.setLore(Arrays.asList(actionData.lore));
    }
    item.setItemMeta(meta);
}
Also used : Builder(org.bukkit.FireworkEffect.Builder) SkullMeta(org.bukkit.inventory.meta.SkullMeta) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ItemMeta (org.bukkit.inventory.meta.ItemMeta)88 ItemStack (org.bukkit.inventory.ItemStack)36 ArrayList (java.util.ArrayList)18 Map (java.util.Map)11 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)10 ListTag (com.wasteofplastic.org.jnbt.ListTag)10 StringTag (com.wasteofplastic.org.jnbt.StringTag)10 Tag (com.wasteofplastic.org.jnbt.Tag)10 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)4 Enchantment (org.bukkit.enchantments.Enchantment)4 EventHandler (org.bukkit.event.EventHandler)4 Material (org.bukkit.Material)3 BookMeta (org.bukkit.inventory.meta.BookMeta)3 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)3 SkullMeta (org.bukkit.inventory.meta.SkullMeta)3 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)2 NMSAbstraction (com.wasteofplastic.acidisland.nms.NMSAbstraction)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2