From fe1a0c7b29d69e29f2343d20a8b8958b77320b3c Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Fri, 5 Jul 2024 16:29:23 +0800 Subject: [PATCH] fix(util): force check id when both have id (#912) --- .../slimefun4/utils/SlimefunUtils.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index b16e0e8025..339a22c3c2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -361,9 +361,7 @@ public static boolean isItemSimilar( .getItemData(possibleSfItemMeta) .orElse(null); // Prioritize SlimefunItem id comparison over ItemMeta comparison - if (id != null && id.equals(possibleItemId)) { - Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!"); - + if (id != null && possibleItemId != null) { /* * PR #3417 * @@ -374,14 +372,20 @@ public static boolean isItemSimilar( if (optionalDistinctive.isPresent()) { return optionalDistinctive.get().canStack(possibleSfItemMeta, itemMeta); } - return true; + + var match = id.equals(possibleItemId); + + Debug.log(TestCase.CARGO_INPUT_TESTING, " Use Item ID match: {}", match); + + return match; } else { Debug.log( TestCase.CARGO_INPUT_TESTING, - " Item IDs don't match, checking meta {} == {} (lore: {})", + " one of item have no Slimefun ID, checking meta {} == {} (lore: {})", itemMeta, possibleSfItemMeta, checkLore); + return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore, checkCustomModelData); } } else if (sfitem.hasItemMeta()) { @@ -462,10 +466,12 @@ private static boolean equalsItemMeta( boolean checkLore, boolean checkCustomModelCheck) { if (itemMeta.hasDisplayName() != sfitemMeta.hasDisplayName()) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing has display name failed"); return false; } else if (itemMeta.hasDisplayName() && sfitemMeta.hasDisplayName() && !itemMeta.getDisplayName().equals(sfitemMeta.getDisplayName())) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing display name failed"); return false; } else if (checkLore) { boolean hasItemMetaLore = itemMeta.hasLore(); @@ -473,9 +479,11 @@ private static boolean equalsItemMeta( if (hasItemMetaLore && hasSfItemMetaLore) { if (!equalsLore(itemMeta.getLore(), sfitemMeta.getLore())) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing lore failed"); return false; } } else if (hasItemMetaLore != hasSfItemMetaLore) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing has lore failed"); return false; } } @@ -497,6 +505,8 @@ private static boolean equalsItemMeta( return ((PotionMeta) itemMeta).getBasePotionType().equals(((PotionMeta) sfitemMeta).getBasePotionType()); } + Debug.log(TestCase.CARGO_INPUT_TESTING, " All meta checked."); + return true; }