Prevent exception when retrieving enchantments (#4297)

This commit is contained in:
triagonal 2021-07-02 05:18:05 +10:00 committed by GitHub
parent 5c08a0e72c
commit 94c509b1e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -282,7 +282,11 @@ public final class Enchantments {
}
Enchantment enchantment = null;
if (isFlat) { // 1.13+ only
enchantment = Enchantment.getByKey(NamespacedKey.minecraft(name.toLowerCase()));
try {
enchantment = Enchantment.getByKey(NamespacedKey.minecraft(name.toLowerCase()));
} catch (IllegalArgumentException ignored) {
// NamespacedKey throws IAE if key does not match regex
}
}
if (enchantment == null) {