Skip to content

Commit

Permalink
Fix price restrictions not detecting enchantments in enchanted books (Q…
Browse files Browse the repository at this point in the history
  • Loading branch information
TauCubed authored Jul 13, 2024
1 parent f597f99 commit 9c841c7
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -62,12 +63,23 @@ public boolean match(ItemStack stack, String expression) {
return false;
}

int finalMinLevel = minLevel;
int level = stack.getEnchantmentLevel(enchantment);
int level = 0;
// This is required for enchantment books as they store enchantments differently for some reason.
// We'll check both stored enchantments and regular enchantments, as it is possible to "enchant"
// an enchanted book with an enchantment, rather than adding a stored enchantment.
// Some plugins may do this by accident.
if (stack.getItemMeta() instanceof EnchantmentStorageMeta meta) {
level = meta.getStoredEnchantLevel(enchantment);
}
if (level == 0) {
level = stack.getEnchantmentLevel(enchantment);
}

if (level == 0) {
return false;
}
if (finalMinLevel != -1 && level < finalMinLevel) {

if (minLevel != -1 && level < minLevel) {
return false;
}
//noinspection RedundantIfStatement
Expand Down

0 comments on commit 9c841c7

Please sign in to comment.