Handle InvalidArgumentException thrown by VanillaEnchantments::fromString (#3878)

This commit is contained in:
Muqsit Rayyan 2020-10-24 10:43:14 +05:00 committed by GitHub
parent 9947e13121
commit 3b632a8deb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;