Merge remote-tracking branch 'origin/master'

This commit is contained in:
Gunging 2021-02-20 21:51:08 -06:00
commit b383993f6a
4 changed files with 17 additions and 29 deletions

View File

@ -1,19 +1,14 @@
package net.Indyuce.mmoitems.api.item.build; package net.Indyuce.mmoitems.api.item.build;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent; 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.ItemStats;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.UpgradeTemplate;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.util.DynamicLore; import net.Indyuce.mmoitems.api.item.util.DynamicLore;
import net.Indyuce.mmoitems.api.util.StatFormat;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.MaterialData; import net.Indyuce.mmoitems.stat.data.MaterialData;
import net.Indyuce.mmoitems.stat.data.StringListData; import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.data.type.StatData;
@ -174,6 +169,7 @@ public class ItemStackBuilder {
array.add(s); array.add(s);
if (array.size() != 0) if (array.size() != 0)
tags.add(new ItemTag("MMOITEMS_DYNAMIC_LORE", array.toString())); tags.add(new ItemTag("MMOITEMS_DYNAMIC_LORE", array.toString()));
meta.setLore(list);
/* /*
* This tag is added to entirely override default vanilla item attribute * This tag is added to entirely override default vanilla item attribute
@ -182,19 +178,18 @@ public class ItemStackBuilder {
*/ */
meta.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, fakeModifier); meta.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, fakeModifier);
if (mmoitem.hasData(ItemStats.NAME) && meta.hasDisplayName()) {
meta.setDisplayName(getMeta().getDisplayName());
}
item.setItemMeta(meta); item.setItemMeta(meta);
NBTItem nbtItem = NBTItem.get(item); NBTItem nbtItem = NBTItem.get(item);
nbtItem.addTag(tags); if (mmoitem.hasData(ItemStats.NAME) && meta.hasDisplayName()) {
if (meta.hasDisplayName())
nbtItem.setDisplayNameComponent(LegacyComponent.parse(meta.getDisplayName())); nbtItem.setDisplayNameComponent(LegacyComponent.parse(meta.getDisplayName()));
}
List<Component> componentLore = new ArrayList<>(); return nbtItem.addTag(tags);
list.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
return nbtItem;
} }
/** /**

View File

@ -6,7 +6,6 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent; import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.utils.adventure.text.Component; import io.lumine.mythic.utils.adventure.text.Component;
import io.lumine.mythic.utils.adventure.text.format.TextDecoration;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -27,10 +26,7 @@ public class DynamicLore {
for (JsonElement e : array) { for (JsonElement e : array) {
String s = replace(e.getAsString()); String s = replace(e.getAsString());
if(!s.equals("!INVALID!")) if(!s.equals("!INVALID!"))
lore.add(Component.text() lore.add(LegacyComponent.parse(s));
.append(LegacyComponent.parse(s))
.decoration(TextDecoration.ITALIC, false)
.build());
} }
item.setLoreComponents(lore); item.setLoreComponents(lore);
} }

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmoitems.api.util; package net.Indyuce.mmoitems.api.util;
import io.lumine.mythic.lib.api.item.NBTItem; 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 io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
@ -25,7 +24,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -39,8 +37,8 @@ public class ItemModInstance {
// Not initialized at first for performance reasons // Not initialized at first for performance reasons
private MMOItem mmoItem; private MMOItem mmoItem;
private String cachedName; private Component cachedName;
private List<String> cachedLore; private List<Component> cachedLore;
private Map<Enchantment, Integer> cachedEnchants; private Map<Enchantment, Integer> cachedEnchants;
private StatData cachedSoulbound; private StatData cachedSoulbound;
@ -73,9 +71,9 @@ public class ItemModInstance {
ItemMeta meta = nbtItem.getItem().getItemMeta(); ItemMeta meta = nbtItem.getItem().getItemMeta();
if (options.shouldKeepName() && meta.hasDisplayName()) if (options.shouldKeepName() && meta.hasDisplayName())
cachedName = meta.getDisplayName(); cachedName = nbtItem.getDisplayNameComponent();
if (options.shouldKeepLore() && meta.hasLore()) if (options.shouldKeepLore() && meta.hasLore())
cachedLore = meta.getLore(); cachedLore = nbtItem.getLoreComponents();
if (options.shouldKeepEnchantments()) if (options.shouldKeepEnchantments())
cachedEnchants = nbtItem.getItem().getEnchantments(); cachedEnchants = nbtItem.getItem().getEnchantments();
@ -133,11 +131,9 @@ public class ItemModInstance {
NBTItem nbtItem = NBTItem.get(stack); NBTItem nbtItem = NBTItem.get(stack);
if (cachedName != null) if (cachedName != null)
nbtItem.setDisplayNameComponent(LegacyComponent.parse(cachedName)); nbtItem.setDisplayNameComponent(cachedName);
if (cachedLore != null) { if (cachedLore != null) {
List<Component> componentLore = new ArrayList<>(); nbtItem.setLoreComponents(cachedLore);
cachedLore.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
} }
return nbtItem.toItem(); return nbtItem.toItem();

View File

@ -53,7 +53,8 @@ public abstract class EditionInventory extends PluginInventory {
this.template = template; this.template = template;
this.configFile = template.getType().getConfigFile(); this.configFile = template.getType().getConfigFile();
if (player.getOpenInventory() != null && player.getOpenInventory().getTopInventory().getHolder() instanceof EditionInventory) player.getOpenInventory();
if (player.getOpenInventory().getTopInventory().getHolder() instanceof EditionInventory)
this.cachedItem = ((EditionInventory) player.getOpenInventory().getTopInventory().getHolder()).cachedItem; this.cachedItem = ((EditionInventory) player.getOpenInventory().getTopInventory().getHolder()).cachedItem;
} }