Search in sources :

Example 81 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project UltimateChat by FabioZumbi12.

the class UltimateFancy method parseHoverItem.

private JSONObject parseHoverItem(ItemStack item) {
    StringBuilder itemBuild = new StringBuilder();
    StringBuilder itemTag = new StringBuilder();
    // serialize itemstack
    String itemType = item.getType().toString().replace("_ITEM", "").replace("_SPADE", "_SHOVEL").replace("GOLD_", "GOLDEN_");
    itemBuild.append("id:" + itemType + ",Count:" + 1 + ",Damage:" + item.getDurability() + ",");
    if (item.hasItemMeta()) {
        ItemMeta meta = item.getItemMeta();
        if (meta.hasLore()) {
            StringBuilder lore = new StringBuilder();
            for (String lorep : meta.getLore()) {
                lore.append(lorep + ",");
            }
            itemTag.append("display:{Lore:[" + lore.toString().substring(0, lore.length() - 1) + "]},");
        } else if (meta.hasDisplayName()) {
            itemTag.append("display:{Name:" + meta.getDisplayName() + "},");
        } else if (meta.hasLore() && meta.hasDisplayName()) {
            StringBuilder lore = new StringBuilder();
            for (String lorep : meta.getLore()) {
                lore.append(lorep + ",");
            }
            itemTag.append("display:{Name:" + meta.getDisplayName() + ",Lore:[" + lore.toString().substring(0, lore.length() - 1) + "]},");
        }
        // enchants
        try {
            if (meta instanceof PotionMeta) {
                StringBuilder itemEnch = new StringBuilder();
                itemEnch.append("CustomPotionEffects:[");
                if (UCUtil.getBukkitVersion() >= 190) {
                    PotionData pot = ((PotionMeta) meta).getBasePotionData();
                    itemEnch.append("{Id:" + pot.getType().getEffectType().getId() + ",Duration:" + pot.getType().getEffectType().getDurationModifier() + ",Ambient:true,},");
                } else {
                    Potion pot = Potion.fromItemStack(item);
                    itemEnch.append("{Id:" + pot.getType().getEffectType().getId() + ",Duration:" + pot.getType().getEffectType().getDurationModifier() + ",Ambient:true,},");
                }
                itemTag.append(itemEnch.toString().substring(0, itemEnch.length() - 1) + "],");
            } else if (meta instanceof EnchantmentStorageMeta) {
                StringBuilder itemEnch = new StringBuilder();
                itemEnch.append("ench:[");
                for (Entry<Enchantment, Integer> ench : ((EnchantmentStorageMeta) meta).getStoredEnchants().entrySet()) {
                    itemEnch.append("{id:" + ench.getKey().getId() + ",lvl:" + ench.getValue() + "},");
                }
                itemTag.append(itemEnch.toString().substring(0, itemEnch.length() - 1) + "],");
            } else if (meta.hasEnchants()) {
                StringBuilder itemEnch = new StringBuilder();
                itemEnch.append("ench:[");
                for (Entry<Enchantment, Integer> ench : meta.getEnchants().entrySet()) {
                    itemEnch.append("{id:" + ench.getKey().getId() + ",lvl:" + ench.getValue() + "},");
                }
                itemTag.append(itemEnch.toString().substring(0, itemEnch.length() - 1) + "],");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            UChat.get().getUCLogger().severe("Error on parse item hand for " + item.toString());
        }
    }
    if (itemTag.length() > 0) {
        itemBuild.append("tag:{" + itemTag.toString().substring(0, itemTag.length() - 1) + "},");
    }
    JSONObject obj = new JSONObject();
    obj.put("action", "show_item");
    obj.put("value", ChatColor.stripColor("{" + itemBuild.toString().substring(0, itemBuild.length() - 1).replace(" ", "_") + "}"));
    return obj;
}
Also used : Potion(org.bukkit.potion.Potion) PotionMeta(org.bukkit.inventory.meta.PotionMeta) Entry(java.util.Map.Entry) PotionData(org.bukkit.potion.PotionData) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) JSONObject(org.json.simple.JSONObject) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 82 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project FunnyGuilds by FunnyGuilds.

the class ExcItems method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    Player player = (Player) sender;
    PluginConfig config = Settings.getConfig();
    List<ItemStack> guildItems = config.createItems;
    List<ItemStack> guiItems = config.guiItems;
    String title = config.guiItemsTitle;
    if (!config.useCommonGUI && player.hasPermission("funnyguilds.vip.items")) {
        guildItems = config.createItemsVip;
        guiItems = config.guiItemsVip;
        title = config.guiItemsVipTitle;
    }
    GuiWindow gui = new GuiWindow(title, guiItems.size() / 9 + (guiItems.size() % 9 != 0 ? 1 : 0));
    gui.setCloseEvent(close -> gui.unregister());
    for (ItemStack item : guiItems) {
        item = item.clone();
        if (config.addLoreLines && guildItems.contains(item)) {
            ItemMeta meta = item.getItemMeta();
            List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
            int pinvAmount = ItemUtils.getItemAmount(item, player.getInventory());
            int ecAmount = ItemUtils.getItemAmount(item, player.getEnderChest());
            for (String line : config.guiItemsLore) {
                line = StringUtils.replace(line, "{PINV-AMOUNT}", Integer.toString(pinvAmount));
                line = StringUtils.replace(line, "{PINV-PERCENT}", StringUtils.getPercent(pinvAmount, item.getAmount()));
                line = StringUtils.replace(line, "{EC-AMOUNT}", Integer.toString(ecAmount));
                line = StringUtils.replace(line, "{EC-PERCENT}", StringUtils.getPercent(ecAmount, item.getAmount()));
                line = StringUtils.replace(line, "{ALL-AMOUNT}", Integer.toString(pinvAmount + ecAmount));
                line = StringUtils.replace(line, "{ALL-PERCENT}", StringUtils.getPercent(pinvAmount + ecAmount, item.getAmount()));
                lore.add(line);
            }
            meta.setLore(lore);
            item.setItemMeta(meta);
        }
        gui.setToNextFree(new GuiItem(item));
    }
    gui.open(player);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) GuiItem(net.dzikoysk.funnyguilds.element.gui.GuiItem) GuiWindow(net.dzikoysk.funnyguilds.element.gui.GuiWindow) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 83 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Skills by StarTux.

the class BukkitSkillSacrifice method rewardsForItem.

List<Reward> rewardsForItem(ItemStack item) {
    List<Reward> result = new ArrayList<>();
    if (item == null)
        return result;
    addReward(result, rewardForItem(item));
    for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
        addReward(result, rewardForEnchantment(entry.getKey(), entry.getValue()));
    }
    if (item.hasItemMeta()) {
        ItemMeta meta = item.getItemMeta();
        if (meta instanceof EnchantmentStorageMeta) {
            for (Map.Entry<Enchantment, Integer> entry : ((EnchantmentStorageMeta) meta).getStoredEnchants().entrySet()) {
                addReward(result, rewardForEnchantment(entry.getKey(), entry.getValue()));
            }
        }
        if (meta instanceof SpawnEggMeta) {
            SpawnEggMeta spawnEggMeta = (SpawnEggMeta) meta;
            if (spawnEggMeta.getSpawnedType() != null) {
                addReward(result, rewardForEntityType(spawnEggMeta.getSpawnedType()));
            }
        }
    }
    return result;
}
Also used : EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) ArrayList(java.util.ArrayList) CustomReward(com.winthier.skills.CustomReward) Reward(com.winthier.skills.Reward) Enchantment(org.bukkit.enchantments.Enchantment) HashMap(java.util.HashMap) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 84 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Essentials by EssentialsX.

the class SpawnerProvider method setDisplayName.

protected ItemStack setDisplayName(ItemStack is, EntityType type) {
    ItemMeta meta = is.getItemMeta();
    String displayName;
    if (entityToDisplayName.containsKey(type)) {
        displayName = entityToDisplayName.get(type);
    } else {
        displayName = type.getName();
    }
    meta.setDisplayName(ChatColor.RESET + displayName + " Spawner");
    is.setItemMeta(meta);
    return is;
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 85 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project VoxelGamesLibv2 by VoxelGamesLib.

the class ItemBuilder method meta.

/**
 * Changes the meta of this item
 *
 * @param consumer the consumer that should be applied to the meta
 * @return this builder for chaining
 * @since 1.3
 */
@Nonnull
public ItemBuilder meta(@Nonnull Consumer<ItemMeta> consumer) {
    ItemMeta meta = is.getItemMeta();
    consumer.accept(meta);
    is.setItemMeta(meta);
    return this;
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta) Nonnull(javax.annotation.Nonnull)

Aggregations

ItemMeta (org.bukkit.inventory.meta.ItemMeta)361 ItemStack (org.bukkit.inventory.ItemStack)205 ArrayList (java.util.ArrayList)87 Player (org.bukkit.entity.Player)45 Inventory (org.bukkit.inventory.Inventory)33 Map (java.util.Map)29 Enchantment (org.bukkit.enchantments.Enchantment)23 EventHandler (org.bukkit.event.EventHandler)23 SkullMeta (org.bukkit.inventory.meta.SkullMeta)22 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)20 ListTag (com.wasteofplastic.org.jnbt.ListTag)20 StringTag (com.wasteofplastic.org.jnbt.StringTag)20 Tag (com.wasteofplastic.org.jnbt.Tag)20 PlayerInventory (org.bukkit.inventory.PlayerInventory)17 IOException (java.io.IOException)15 Material (org.bukkit.Material)14 PotionMeta (org.bukkit.inventory.meta.PotionMeta)14 Mage (com.elmakers.mine.bukkit.api.magic.Mage)12 BookMeta (org.bukkit.inventory.meta.BookMeta)12 List (java.util.List)11