more verbose logging for alchemy potion lookups

This commit is contained in:
nossr50 2024-05-17 11:59:24 -07:00
parent fc66c9f3fd
commit e6ff219a5c
4 changed files with 27 additions and 11 deletions

View File

@ -1,3 +1,10 @@
Version 2.2.011
Improved logging for Alchemy potion look up (see notes)
NOTES:
Added detailed logging when multiple configured potions match an ItemStack.
This will help identify issues with potion configuration.
Version 2.2.010
Fixed being unable to load REGEN potion type on new versions of Paper/Spigot 1.20.6
Fixed some potions not gaining XP when brewed (Level 2 potions, etc)

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.010</version>
<version>2.2.011-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>

View File

@ -342,7 +342,11 @@ public class PotionConfig extends LegacyConfigLoader {
.filter(potion -> potion.isSimilarPotion(item))
.toList();
if(potionList.size() > 1) {
mcMMO.p.getLogger().severe("Multiple child potions matched for item, when there should only be one: " + item);
mcMMO.p.getLogger().severe("Multiple potions defined in config have match this potion, for mcMMO to behave" +
" properly there should only be one match found.");
mcMMO.p.getLogger().severe("Potion ItemStack:" + item.toString());
mcMMO.p.getLogger().severe("Alchemy Potions from config matching this item: "
+ potionList.stream().map(AlchemyPotion::toString).collect(Collectors.joining(", ")));
}
return potionList.isEmpty() ? null : potionList.get(0);

View File

@ -19,11 +19,11 @@ public class AlchemyPotion {
private final @NotNull ItemStack potionItemStack;
private final @NotNull Map<ItemStack, String> alchemyPotionChildren;
public AlchemyPotion(@NotNull String potionConfigName, @NotNull ItemStack potionItemStack, @NotNull Map<ItemStack, String> alchemyPotionChildren) {
public AlchemyPotion(@NotNull String potionConfigName, @NotNull ItemStack potionItemStack,
@NotNull Map<ItemStack, String> alchemyPotionChildren) {
this.potionConfigName = requireNonNull(potionConfigName, "potionConfigName cannot be null");
this.potionItemStack = requireNonNull(potionItemStack, "potionItemStack cannot be null");
this.alchemyPotionChildren = requireNonNull(alchemyPotionChildren, "alchemyPotionChildren cannot be null");
// mcMMO.p.getLogger().info("AlchemyPotion created: " + potionConfigName + ", with children: " + alchemyPotionChildren);
}
public @NotNull ItemStack toItemStack(int amount) {
@ -32,7 +32,7 @@ public class AlchemyPotion {
return clone;
}
public Map<ItemStack, String> getAlchemyPotionChildren() {
public @NotNull Map<ItemStack, String> getAlchemyPotionChildren() {
return alchemyPotionChildren;
}
@ -58,6 +58,10 @@ public class AlchemyPotion {
return false;
}
/*
* Compare custom effects on both potions.
*/
final PotionMeta otherPotionMeta = (PotionMeta) otherPotion.getItemMeta();
// compare custom effects on both potions, this has to be done in two traversals
// comparing thisPotionMeta -> otherPotionMeta and otherPotionMeta -> thisPotionMeta
@ -70,17 +74,18 @@ public class AlchemyPotion {
return false;
}
/*
* If one potion has lore and the other does not, then they are not the same potion.
* If both have lore, compare the lore.
* If neither have lore, they may be the same potion.
*/
if (!otherPotionMeta.hasLore() && getAlchemyPotionMeta().hasLore()
|| !getAlchemyPotionMeta().hasLore() && otherPotionMeta.hasLore()) {
return false;
}
if (otherPotionMeta.hasLore() && getAlchemyPotionMeta().hasLore()
&& !otherPotionMeta.getLore().equals(getAlchemyPotionMeta().getLore())) {
return false;
}
return true;
return !otherPotionMeta.hasLore() || !getAlchemyPotionMeta().hasLore()
|| otherPotionMeta.getLore().equals(getAlchemyPotionMeta().getLore());
}
private boolean hasDifferingCustomEffects(PotionMeta potionMeta, PotionMeta otherPotionMeta) {