EnchantCommand no longer accepts numeric enchantment IDs

This commit is contained in:
Dylan K. Taylor 2020-10-24 17:33:17 +01:00
parent 3b632a8deb
commit 2e1239f77a

View File

@ -25,13 +25,11 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
use function count; use function count;
use function is_numeric;
class EnchantCommand extends VanillaCommand{ class EnchantCommand extends VanillaCommand{
@ -67,19 +65,11 @@ class EnchantCommand extends VanillaCommand{
return true; return true;
} }
if(is_numeric($args[1])){ try{
$enchantment = VanillaEnchantments::byMcpeId((int) $args[1]); $enchantment = VanillaEnchantments::fromString($args[1]);
if(!($enchantment instanceof Enchantment)){ }catch(\InvalidArgumentException $e){
$sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$args[1]])); $sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$args[1]]));
return true; return true;
}
}else{
try{
$enchantment = VanillaEnchantments::fromString($args[1]);
}catch(\InvalidArgumentException $e){
$sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$args[1]]));
return true;
}
} }
$level = 1; $level = 1;