bukkit: Improve failure handling in EnchantmentArgument

This commit is contained in:
Jason Penilla 2021-08-02 18:24:54 -07:00 committed by Jason
parent 9c85db386f
commit 3b2f2edb60

View file

@ -144,11 +144,15 @@ public class EnchantmentArgument<C> extends CommandArgument<C, Enchantment> {
} }
final NamespacedKey key; final NamespacedKey key;
if (input.contains(":")) { try {
final String[] splitInput = input.split(":"); if (input.contains(":")) {
key = new NamespacedKey(splitInput[0], splitInput[1]); final String[] splitInput = input.split(":");
} else { key = new NamespacedKey(splitInput[0], splitInput[1]);
key = NamespacedKey.minecraft(input); } else {
key = NamespacedKey.minecraft(input);
}
} catch (final Exception ex) {
return ArgumentParseResult.failure(new EnchantmentParseException(input, commandContext));
} }
final Enchantment enchantment = Enchantment.getByKey(key); final Enchantment enchantment = Enchantment.getByKey(key);