Fixed EnchantCommand being retarded, close #1012

This commit is contained in:
Dylan K. Taylor 2017-05-06 14:08:18 +01:00
parent 3b7fc21839
commit 5f6dc25c9f

View File

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