!display name component support

This commit is contained in:
Ethan 2021-02-20 06:05:30 -05:00
parent 311d174398
commit e048bb1e08
8 changed files with 125 additions and 67 deletions

View File

@ -84,7 +84,9 @@ public class ConfigItem {
}
nbtItem.addTag(new ItemTag("ItemId", id));
nbtItem.setDisplayNameComponent(LegacyComponent.parse(getName()));
if (getName() != null)
nbtItem.setDisplayNameComponent(LegacyComponent.parse(getName()));
if (hasLore()) {
List<Component> lore = new ArrayList<>();

View File

@ -3,6 +3,8 @@ package net.Indyuce.mmoitems.api.item.util.crafting;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.ConditionalDisplay;
import net.Indyuce.mmoitems.api.crafting.condition.Condition.CheckedCondition;
@ -17,7 +19,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.text.DecimalFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
public class CraftingRecipeDisplay extends ConfigItem {
private static final DecimalFormat craftingTimeFormat = new DecimalFormat("0.#");
@ -119,12 +125,17 @@ public class CraftingRecipeDisplay extends ConfigItem {
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(MythicLib.plugin.parseColors(
name.replace("#name#", (amount > 1 ? (ChatColor.WHITE + "" + amount + " x ") : "") + MMOUtils.getDisplayName(item))));
meta.setLore(lore);
item.setItemMeta(meta);
return NBTItem.get(item).addTag(new ItemTag("recipeId", craftingRecipe.getId())).toItem();
NBTItem nbtItem = NBTItem.get(item);
nbtItem.setDisplayNameComponent(LegacyComponent.parse(name.replace("#name#", (amount > 1 ? (ChatColor.WHITE + "" + amount + " x ") : "") + MMOUtils.getDisplayName(item))));
List<Component> componentLore = new ArrayList<>();
lore.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
return nbtItem.addTag(new ItemTag("recipeId", craftingRecipe.getId())).toItem();
}
}
}

View File

@ -1,9 +1,12 @@
package net.Indyuce.mmoitems.api.item.util.crafting;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue.CraftingInfo;
import net.Indyuce.mmoitems.api.item.util.ConfigItem;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue.CraftingInfo;
import net.Indyuce.mmoitems.api.item.util.ConfigItem;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
@ -82,11 +85,17 @@ public class QueueItemDisplay extends ConfigItem {
item.setAmount(position);
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(MythicLib.plugin.parseColors(name.replace("#name#", meta.getDisplayName())));
meta.setLore(lore);
item.setItemMeta(meta);
return MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).addTag(new ItemTag("queueId", crafting.getUniqueId().toString()))
NBTItem nbtItem = NBTItem.get(item);
nbtItem.setDisplayNameComponent(LegacyComponent.parse(name.replace("#name#", meta.getDisplayName())));
List<Component> componentLore = new ArrayList<>();
lore.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
return nbtItem.addTag(new ItemTag("queueId", crafting.getUniqueId().toString()))
.toItem();
}
}

View File

@ -1,24 +1,26 @@
package net.Indyuce.mmoitems.api.item.util.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.ConditionalDisplay;
import net.Indyuce.mmoitems.api.crafting.condition.Condition.CheckedCondition;
import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe;
import net.Indyuce.mmoitems.api.crafting.recipe.UpgradingRecipe;
import net.Indyuce.mmoitems.api.item.util.ConfigItem;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
public class UpgradingRecipeDisplay extends ConfigItem {
public UpgradingRecipeDisplay() {
@ -90,11 +92,17 @@ public class UpgradingRecipeDisplay extends ConfigItem {
ItemStack item = upgradingRecipe.getItem().getPreview();
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(MythicLib.plugin.parseColors(name.replace("#name#", MMOUtils.getDisplayName(item))));
meta.setLore(lore);
item.setItemMeta(meta);
return MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).addTag(new ItemTag("recipeId", recipe.getRecipe().getId())).toItem();
NBTItem nbtItem = NBTItem.get(item);
nbtItem.setDisplayNameComponent(LegacyComponent.parse(name.replace("#name#", MMOUtils.getDisplayName(item))));
List<Component> componentLore = new ArrayList<>();
lore.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
return nbtItem.addTag(new ItemTag("recipeId", recipe.getRecipe().getId())).toItem();
}
}
}

View File

@ -3,6 +3,8 @@ package net.Indyuce.mmoitems.api.item.util.identify;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
@ -19,7 +21,11 @@ import org.bukkit.util.io.BukkitObjectOutputStream;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.ByteArrayOutputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class UnidentifiedItem extends ConfigItem {
public UnidentifiedItem(Type type) {
@ -102,11 +108,17 @@ public class UnidentifiedItem extends ConfigItem {
ItemMeta meta = unidentified.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setUnbreakable(true);
meta.setDisplayName(MythicLib.plugin.parseColors(name));
meta.setLore(lore);
unidentified.setItemMeta(meta);
return unidentified;
NBTItem nbtItem = NBTItem.get(unidentified);
nbtItem.setDisplayNameComponent(LegacyComponent.parse(name));
List<Component> componentLore = new ArrayList<>();
lore.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
return nbtItem.toItem();
}
private String serialize(ItemStack item) {

View File

@ -1,14 +1,8 @@
package net.Indyuce.mmoitems.api.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
@ -26,7 +20,15 @@ import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.Upgradable;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ItemModInstance {
private final NBTItem nbtItem;
@ -124,14 +126,21 @@ public class ItemModInstance {
ItemStack stack = mmoItem.newBuilder().build();
stack.setAmount(amount);
ItemMeta meta = stack.getItemMeta();
if (cachedName != null)
meta.setDisplayName(cachedName);
if (cachedLore != null)
meta.setLore(cachedLore);
stack.setItemMeta(meta);
if (cachedEnchants != null)
stack.addUnsafeEnchantments(cachedEnchants);
return stack;
stack.setItemMeta(meta);
NBTItem nbtItem = NBTItem.get(stack);
if (cachedName != null)
nbtItem.setDisplayNameComponent(LegacyComponent.parse(cachedName));
if (cachedLore != null) {
List<Component> componentLore = new ArrayList<>();
cachedLore.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
}
return nbtItem.toItem();
}
/*

View File

@ -1,9 +1,15 @@
package net.Indyuce.mmoitems.gui;
import java.util.ArrayList;
import java.util.List;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient.CheckedIngredient;
import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe;
import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe;
import net.Indyuce.mmoitems.api.crafting.recipe.UpgradingRecipe;
import net.Indyuce.mmoitems.api.item.util.ConfigItems;
import net.Indyuce.mmoitems.api.util.message.Message;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -13,14 +19,8 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient.CheckedIngredient;
import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe;
import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe;
import net.Indyuce.mmoitems.api.crafting.recipe.UpgradingRecipe;
import net.Indyuce.mmoitems.api.util.message.Message;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import java.util.ArrayList;
import java.util.List;
public class CraftingStationPreview extends PluginInventory {
private final CraftingStationView previous;
@ -81,11 +81,11 @@ public class CraftingStationPreview extends PluginInventory {
inv.setItem(16, item);
}
if (recipe.getRecipe() instanceof UpgradingRecipe) {
ItemStack stack = ((UpgradingRecipe) recipe.getRecipe()).getItem().getPreview();
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(meta.getDisplayName() + ChatColor.GREEN + "+1!");
stack.setItemMeta(meta);
inv.setItem(16, stack);
NBTItem nbtItem = NBTItem.get(((UpgradingRecipe) recipe.getRecipe()).getItem().getPreview());
nbtItem.setDisplayNameComponent(LegacyComponent.parse(
nbtItem.toItem().getItemMeta().getDisplayName() + ChatColor.GREEN + "+1!"));
inv.setItem(16, nbtItem.toItem());
}
inv.setItem(10, ConfigItems.BACK.getItem());

View File

@ -2,6 +2,8 @@ package net.Indyuce.mmoitems.manager;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
@ -18,6 +20,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -139,16 +142,20 @@ public class UpdaterManager implements Listener {
//if (did.hasOption(KeepOption.KEEP_DURABILITY) && item.getItem().getItemMeta() instanceof Damageable && newItemMeta instanceof Damageable)
((Damageable) newItemMeta).setDamage(((Damageable) item.getItem().getItemMeta()).getDamage());
newItem.setItemMeta(newItemMeta);
NBTItem nbtItem = NBTItem.get(newItem);
/*
* keep name so players who renamed the item in the anvil does not have
* to rename it again
*/
//if (did.hasOption(KeepOption.KEEP_NAME) && item.getItem().getItemMeta().hasDisplayName())
newItemMeta.setDisplayName(item.getItem().getItemMeta().getDisplayName());
nbtItem.setDisplayNameComponent(LegacyComponent.parse(item.getItem().getItemMeta().getDisplayName()));
newItemMeta.setLore(lore);
newItem.setItemMeta(newItemMeta);
return newItem;
List<Component> componentLore = new ArrayList<>();
lore.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
return nbtItem.toItem();
}
public enum KeepOption {