pocketmine\item\enchantment\Enchantment::getEnchantAbility PHP Method

getEnchantAbility() public static method

public static getEnchantAbility ( Item $item )
$item pocketmine\item\Item
    public static function getEnchantAbility(Item $item)
    {
        switch ($item->getId()) {
            case Item::BOOK:
            case Item::BOW:
            case Item::FISHING_ROD:
                return 4;
        }
        if ($item->isArmor()) {
            if ($item instanceof ChainBoots or $item instanceof ChainChestplate or $item instanceof ChainHelmet or $item instanceof ChainLeggings) {
                return 12;
            }
            if ($item instanceof IronBoots or $item instanceof IronChestplate or $item instanceof IronHelmet or $item instanceof IronLeggings) {
                return 9;
            }
            if ($item instanceof DiamondBoots or $item instanceof DiamondChestplate or $item instanceof DiamondHelmet or $item instanceof DiamondLeggings) {
                return 10;
            }
            if ($item instanceof LeatherBoots or $item instanceof LeatherTunic or $item instanceof LeatherCap or $item instanceof LeatherPants) {
                return 15;
            }
            if ($item instanceof GoldBoots or $item instanceof GoldChestplate or $item instanceof GoldHelmet or $item instanceof GoldLeggings) {
                return 25;
            }
        }
        if ($item->isTool()) {
            if ($item instanceof WoodenAxe or $item instanceof WoodenHoe or $item instanceof WoodenPickaxe or $item instanceof WoodenShovel or $item instanceof WoodenSword) {
                return 15;
            }
            if ($item instanceof StoneAxe or $item instanceof StoneHoe or $item instanceof StonePickaxe or $item instanceof StoneShovel or $item instanceof StoneSword) {
                return 5;
            }
            if ($item instanceof DiamondAxe or $item instanceof DiamondHoe or $item instanceof DiamondPickaxe or $item instanceof DiamondShovel or $item instanceof DiamondSword) {
                return 10;
            }
            if ($item instanceof IronAxe or $item instanceof IronHoe or $item instanceof IronPickaxe or $item instanceof IronShovel or $item instanceof IronSword) {
                return 14;
            }
            if ($item instanceof GoldAxe or $item instanceof GoldHoe or $item instanceof GoldPickaxe or $item instanceof GoldShovel or $item instanceof GoldSword) {
                return 22;
            }
        }
        return 0;
    }

Usage Example

示例#1
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) < 2) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return true;
     }
     $player = $sender->getServer()->getPlayer($args[0]);
     if ($player === null) {
         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
         return true;
     }
     $enchantId = $args[1];
     $enchantLevel = isset($args[2]) ? (int) $args[2] : 1;
     $enchantment = Enchantment::getEnchantment($enchantId);
     if ($enchantment->getId() === Enchantment::TYPE_INVALID) {
         $enchantment = Enchantment::getEnchantmentByName($enchantId);
         if ($enchantment->getId() === Enchantment::TYPE_INVALID) {
             $sender->sendMessage(new TranslationContainer("commands.enchant.notFound", [$enchantment->getId()]));
             return true;
         }
     }
     $id = $enchantment->getId();
     $maxLevel = Enchantment::getEnchantMaxLevel($id);
     if ($enchantLevel > $maxLevel or $enchantLevel <= 0) {
         $sender->sendMessage(new TranslationContainer("commands.enchant.maxLevel", [$maxLevel]));
         return true;
     }
     $enchantment->setLevel($enchantLevel);
     $item = $player->getInventory()->getItemInHand();
     if ($item->getId() <= 0) {
         $sender->sendMessage(new TranslationContainer("commands.enchant.noItem"));
         return true;
     }
     if (Enchantment::getEnchantAbility($item) === 0) {
         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.enchant.cantEnchant"));
         return true;
     }
     $item->addEnchantment($enchantment);
     $player->getInventory()->setItemInHand($item);
     self::broadcastCommandMessage($sender, new TranslationContainer("%commands.enchant.success"));
     return true;
 }
All Usage Examples Of pocketmine\item\enchantment\Enchantment::getEnchantAbility