Skip to content

Commit

Permalink
fix(util): force check id when both have id (SlimefunGuguProject#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jul 5, 2024
1 parent 4390b5e commit fe1a0c7
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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()) {
Expand Down Expand Up @@ -462,20 +466,24 @@ 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();
boolean hasSfItemMetaLore = sfitemMeta.hasLore();

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;
}
}
Expand All @@ -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;
}

Expand Down

0 comments on commit fe1a0c7

Please sign in to comment.