From 3b632a8deb0ba0df325d2b57b2a4bd1ef50bc496 Mon Sep 17 00:00:00 2001 From: Muqsit Rayyan Date: Sat, 24 Oct 2020 10:43:14 +0500 Subject: [PATCH] Handle InvalidArgumentException thrown by VanillaEnchantments::fromString (#3878) --- src/command/defaults/EnchantCommand.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/command/defaults/EnchantCommand.php b/src/command/defaults/EnchantCommand.php index 05cec32ee..89a252fcb 100644 --- a/src/command/defaults/EnchantCommand.php +++ b/src/command/defaults/EnchantCommand.php @@ -69,13 +69,17 @@ class EnchantCommand extends VanillaCommand{ if(is_numeric($args[1])){ $enchantment = VanillaEnchantments::byMcpeId((int) $args[1]); + if(!($enchantment instanceof Enchantment)){ + $sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$args[1]])); + return true; + } }else{ - $enchantment = VanillaEnchantments::fromString($args[1]); - } - - if(!($enchantment instanceof Enchantment)){ - $sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$args[1]])); - return true; + try{ + $enchantment = VanillaEnchantments::fromString($args[1]); + }catch(\InvalidArgumentException $e){ + $sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$args[1]])); + return true; + } } $level = 1;