From 0099a415faa73f0c31c5c9ee2eda6c35f3188b5a Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 26 Aug 2024 22:05:22 -0700 Subject: [PATCH] Fixed revid-ed items not stacking --- .../mmoitems/api/item/build/ItemStackBuilder.java | 10 ++++------ .../Indyuce/mmoitems/stat/data/EnchantListData.java | 9 ++------- .../net/Indyuce/mmoitems/stat/type/StatHistory.java | 6 ++++++ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/build/ItemStackBuilder.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/build/ItemStackBuilder.java index a3e584b2..55e239e8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/build/ItemStackBuilder.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/build/ItemStackBuilder.java @@ -130,9 +130,8 @@ public class ItemStackBuilder { * Enchantment data must never be clear and lack history. This is * the basis for when an item is 'old' */ - if (!builtMMOItem.hasData(ItemStats.ENCHANTS)) { - builtMMOItem.setData(ItemStats.ENCHANTS, ItemStats.ENCHANTS.getClearStatData()); - } + builtMMOItem.computeData(ItemStats.ENCHANTS); + builtMMOItem.computeStatHistory(ItemStats.ENCHANTS); //GEM// else {MMOItems.log("\u00a73 -?- \u00a77Apparently found enchantment data \u00a7b" + (mmoitem.getData(ItemStats.ENCHANTS) == null ? "null" : ((EnchantListData) mmoitem.getData(ItemStats.ENCHANTS)).getEnchants().size())); } /* @@ -140,9 +139,8 @@ public class ItemStackBuilder { * through non-MMOItems supported sources, the name can be changed in * an anvil, so the very original name must be saved. */ - if (!builtMMOItem.hasData(ItemStats.NAME)) - builtMMOItem.setData(ItemStats.NAME, ItemStats.NAME.getClearStatData()); - builtMMOItem.computeStatHistory(ItemStats.NAME); // Ignore result + builtMMOItem.computeData(ItemStats.NAME); + builtMMOItem.computeStatHistory(ItemStats.NAME); // For every stat within this item for (ItemStat stat : builtMMOItem.getStats()) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/EnchantListData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/EnchantListData.java index 1c1fc319..549cd4b4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/EnchantListData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/EnchantListData.java @@ -4,7 +4,6 @@ import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.stat.data.type.Mergeable; import net.Indyuce.mmoitems.stat.data.type.StatData; -import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; @@ -89,7 +88,7 @@ public class EnchantListData implements StatData, Mergeable { final AtomicBoolean check = new AtomicBoolean(); enchants.forEach((enchant, lvl) -> { if (check.get()) builder.append(","); - builder.append(enchant + "=" + lvl); + builder.append(enchant).append("=").append(lvl); check.set(true); }); builder.append("}"); @@ -138,11 +137,7 @@ public class EnchantListData implements StatData, Mergeable { return; } - if (!mmoItem.hasData(ItemStats.ENCHANTS)) { - mmoItem.setData(ItemStats.ENCHANTS, new EnchantListData()); - } - - EnchantListData mmoData = (EnchantListData) mmoItem.getData(ItemStats.ENCHANTS); + EnchantListData mmoData = (EnchantListData) mmoItem.computeData(ItemStats.ENCHANTS); // 2: If it has data (It always has) and the amount of enchants is zero, the cached are Extraneous if (mmoData.getEnchants().size() == 0) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java index a0af1cf0..17d615ee 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/StatHistory.java @@ -141,6 +141,8 @@ public class StatHistory { public void registerModifierBonus(@NotNull UUID of, @NotNull StatData data) { Validate.notNull(of, "Modifier UUID cannot be null"); Validate.notNull(data, "Stat data cannot be null"); + if (data.isEmpty()) return; + perModifierBonus.put(of, data); } @@ -205,6 +207,8 @@ public class StatHistory { public void registerGemstoneData(@NotNull UUID of, @NotNull StatData data) { Validate.notNull(of, "Gemstone ID cannot be null"); Validate.notNull(data, "Stat data cannot be null"); + if (data.isEmpty()) return; + perGemstoneData.put(of, data); } @@ -255,6 +259,8 @@ public class StatHistory { */ public void registerExternalData(@NotNull StatData data) { Validate.notNull(data, "Stat data cannot be null"); + if (data.isEmpty()) return; + perExternalData.add(data); }