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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations