diff --git a/src/pocketmine/command/defaults/EnchantCommand.php b/src/pocketmine/command/defaults/EnchantCommand.php index 67697f31d..40fcf6fdf 100644 --- a/src/pocketmine/command/defaults/EnchantCommand.php +++ b/src/pocketmine/command/defaults/EnchantCommand.php @@ -56,17 +56,6 @@ class EnchantCommand extends VanillaCommand{ return true; } - $enchantId = (int) $args[1]; - $enchantLevel = isset($args[2]) ? (int) $args[2] : 1; - - $enchantment = Enchantment::getEnchantment($enchantId); - if(!($enchantment instanceof Enchantment)){ - $sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$enchantId])); - return true; - } - - $enchantment->setLevel($enchantLevel); - $item = $player->getInventory()->getItemInHand(); if($item->getId() <= 0){ @@ -74,6 +63,19 @@ class EnchantCommand extends VanillaCommand{ return true; } + if(is_numeric($args[1])){ + $enchantment = Enchantment::getEnchantment((int) $args[1]); + }else{ + $enchantment = Enchantment::getEnchantmentByName($args[1]); + } + + if(!($enchantment instanceof Enchantment)){ + $sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$args[1]])); + return true; + } + + $enchantment->setLevel((int) ($args[2] ?? 1)); + $item->addEnchantment($enchantment); $player->getInventory()->setItemInHand($item);