From 11b18f74ae811cd2b6d5a57cd3dba7791b89f6c1 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 26 Nov 2023 21:53:28 +0100 Subject: [PATCH] Fixed repair and upgrade reference --- .../Indyuce/mmoitems/stat/UpgradeStat.java | 2 +- .../mmoitems/stat/data/UpgradeData.java | 4 ++- .../net/Indyuce/mmoitems/util/MMOUtils.java | 28 +++++++++---------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java index 397999f7..21e50fb5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java @@ -209,7 +209,7 @@ public class UpgradeStat extends ItemStat implements C } UpgradeData consumableSharpening = (UpgradeData) mmoitem.getData(ItemStats.UPGRADE); - if (!consumableSharpening.matchesReference(targetSharpening)) { + if (!MMOUtils.checkReference(consumableSharpening.getReference(), targetSharpening.getReference())) { Message.WRONG_UPGRADE_REFERENCE.format(ChatColor.RED).send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); return false; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/UpgradeData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/UpgradeData.java index 3d2e7f4e..71d7a15f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/UpgradeData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/data/UpgradeData.java @@ -7,6 +7,7 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.configuration.ConfigurationSection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -145,8 +146,9 @@ public class UpgradeData implements StatData, RandomStatData { return success == 0 ? 1 : success; } + @Deprecated public boolean matchesReference(UpgradeData data) { - return reference == null || data.reference == null || reference.isEmpty() || data.reference.isEmpty() || reference.equals(data.reference); + return MMOUtils.checkReference(reference, data.reference); } @Override diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java index 70064b43..b4740292 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java @@ -67,14 +67,12 @@ public class MMOUtils { /** * References are helpful to classify items that can interact together. - * They are a piece of text stored as an NBTTag for instance. Items can - * interact (in a certain way) only if the corresponding reference match. + * They are a piece of text stored as an NBTTag for instance. Items are + * only able to interact with items with the same reference, or with + * the universal reference stored in variable {@link #UNIVERSAL_REFERENCE} *

- * Any item can interact with an item with the universal reference 'all'. - * A null/empty reference is considered like the universal reference. - *

- * This is a simple symmetrical computation. Used for: - * - for item upgrading TODO + * At the moment, it is being used for: + * - for item upgrading * - item repairing * * @param ref1 First reference @@ -82,7 +80,9 @@ public class MMOUtils { * @return If items can interact */ public static boolean checkReference(@Nullable String ref1, @Nullable String ref2) { - return ref1 == null || ref1.isEmpty() || ref2 == null || ref2.isEmpty() || ref1.equals(UNIVERSAL_REFERENCE) || ref2.equals(UNIVERSAL_REFERENCE) || ref1.equals(ref2); + if (ref1 != null && ref1.equals(UNIVERSAL_REFERENCE)) return true; + if (ref2 != null && ref2.equals(UNIVERSAL_REFERENCE)) return true; + return Objects.equals(ref1, ref2); } /** @@ -262,7 +262,7 @@ public class MMOUtils { * * @param type Potion effect type * @return The duration that MMOItems should be using to give player - * "permanent" potion effects, depending on the potion effect type + * "permanent" potion effects, depending on the potion effect type */ public static int getEffectDuration(PotionEffectType type) { return type.equals(PotionEffectType.NIGHT_VISION) || type.equals(PotionEffectType.CONFUSION) ? 260 : type.equals(PotionEffectType.BLINDNESS) ? 140 : 80; @@ -285,7 +285,7 @@ public class MMOUtils { * @param item The item to check * @param lore Whether or not MI should check for an item lore * @return If the item is not null, has an itemMeta and has a display name. - * If 'lore' is true, also checks if the itemMeta has a lore. + * If 'lore' is true, also checks if the itemMeta has a lore. */ public static boolean isMetaItem(ItemStack item, boolean lore) { return item != null && item.getType() != Material.AIR && item.getItemMeta() != null && item.getItemMeta().getDisplayName() != null && (!lore || item.getItemMeta().getLore() != null); @@ -419,10 +419,10 @@ public class MMOUtils { /** * @param loc Where we are looking for nearby entities * @return List of all entities surrounding a location. This method loops - * through the 9 surrounding chunks and collect all entities from - * them. This list can be cached and used multiple times in the same - * tick for projectile based spells which need to run entity - * checkups + * through the 9 surrounding chunks and collect all entities from + * them. This list can be cached and used multiple times in the same + * tick for projectile based spells which need to run entity + * checkups */ public static List getNearbyChunkEntities(Location loc) { List entities = new ArrayList<>();