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;
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.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.Type;
import net.Indyuce.mmoitems.api.UpgradeTemplate;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
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.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
@ -174,6 +169,7 @@ public class ItemStackBuilder {
array.add(s);
if (array.size() != 0)
tags.add(new ItemTag("MMOITEMS_DYNAMIC_LORE", array.toString()));
meta.setLore(list);
/*
* 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);
if (mmoitem.hasData(ItemStats.NAME) && meta.hasDisplayName()) {
meta.setDisplayName(getMeta().getDisplayName());
}
item.setItemMeta(meta);
NBTItem nbtItem = NBTItem.get(item);
nbtItem.addTag(tags);
if (meta.hasDisplayName())
if (mmoitem.hasData(ItemStats.NAME) && meta.hasDisplayName()) {
nbtItem.setDisplayNameComponent(LegacyComponent.parse(meta.getDisplayName()));
}
List<Component> componentLore = new ArrayList<>();
list.forEach(line -> componentLore.add(LegacyComponent.parse(line)));
nbtItem.setLoreComponents(componentLore);
return nbtItem;
return nbtItem.addTag(tags);
}
/**

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

View File

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

View File

@ -53,7 +53,8 @@ public abstract class EditionInventory extends PluginInventory {
this.template = template;
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;
}