PiggyCustomEnchants

Welcome to PiggyCustomEnchants' Documentation! You can find here:

API Documentation

    addEnchantment()

      Description
        addEnchantment() adds an enchantment to an item
      Usage
        
            $ce->addEnchantment($item, $enchants, $levels, $check);
                                            
      Parameters
        Item
        • Item to be enchanted
        Enchant(s)
        • Enchantments to be added to the item
        • Can be an array of enchantment names, ids, or classes
        • Can be a single enchantment name, id, or class
        Level(s)
        • The level of the enchantments to be added to the item
        • Can be an array of integers
        • Can be a single integer
        Checks
        • Check enchantments before adding
        • Default value is true
        • Must be a boolean
      Example
        
            $item = $player->getInventory()->getItemInHand();
            $ce = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants");
            $ce->addEnchantment($item, ["Porkified", "Grappling"], [3, 1], true);
            $player->getInventory()->setItemInHand($item);
                                            

    removeEnchantment()

      Description
        removeEnchantment() removes an enchantment from an item
      Usage
        
            $ce->removeEnchantment($item, $enchant, $level);
                                            
      Parameters
        Item
        • Item to remove enchantment from
        Enchant
        • Enchantments to be removed from the item
        • Must be an instanceof EnchantmentInstance or Enchantment
        Level
        • Check for a specific level
        • Set to -1 to disable checks
      Example
        
            $item = $player->getInventory()->getItemInHand();
            $ce = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants");
            $ce->removeEnchantment($item, CustomEnchantsIds::PORKIFIED, 3);
            $player->getInventory()->setItemInHand($item);
                                            

    getEnchantment()

      Description
        getEnchantment() gets the current enchantments on an item
      Usage
        
            $item->getEnchantment($id);
                                            
      Parameters
        ID
        • The id of the enchantment
      Example
        
            $item = $player->getInventory()->getItemInHand();
            $enchantment = $item->getEnchantment(CustomEnchantsIds::PORKIFIED);
            if ($enchantment !== null) {
                switch($enchantment->getLevel()) {
                    case 1:
                    case 2:
                    case 3:
                        $player->sendMessage(TextFormat::GREEN . "You are holding an item enchanted with level " . $enchantment->getLevel() . " Porkified.");
                        break;
                    default:
                        $player->sendMessage(TextFormat::GREEN . "You are holding an item enchanted with level " . $enchantment->getLevel() . " Porkified. How did you get this enchantment with such a high level?");
                        break;
                }
            }
                                            

    canBeEnchanted()

      Description
        canBeEnchanted() checks if an enchantment can be applied to an item
      Usage
        
            $ce->canBeEnchanted($item, $enchant, $level);
                                            
      Parameters
        Item
        • The item for the enchantment to be checked on
        Enchantment
        • Enchantment to be checked
        • Must be an instanceof EnchantmentInstance or Enchantment
        Level
        • Enchantment level to be checked
      Example
        
            $item = $player->getInventory()->getItemInHand();
            $ce = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants");
            if($ce->canBeEnchanted($item, CustomEnchantsIds::PORKIFIED, 3)) {
                $player->sendMessage("You can enchant your item with level 3 Porkified.");
            } else {
                $player->sendMessage("You can not enchant your item with level 3 Porkified.");
            }
                                            

    registerEnchantment()

      Description
        registerEnchantment() registers an enchant
      Usage
        
            $ce->registerEnchantment($id, $name, $type, $trigger, $rarity, $maxlevel, $description);
                                            
      Parameters
        ID
        • ID of enchantment to be registered
        Name
        • Name of enchantment to be registered
        Type
        • Type of enchantment to be registered
        • Options
          • Global
          • Weapons
          • Bow
          • Tools
          • Pickaxe
          • Axe
          • Shovel
          • Hoe
          • Armor
          • Helmets
          • Chestplate
          • Leggings
          • Boots
          • Compass
        Trigger
        • Trigger of enchantment to be registered
        Rarity
        • Rarity of enchantment to be registered
        • Options:
          • Common
          • Uncommon
          • Rare
          • Mythic
        Max Level
        • Max level of enchantment to be registered
        Description (optional)
        • Description of enchantment to be registered
      Example
        
            $ce = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants");
            $ce->registerEnchantment(302, "Fireworks", "Bow", "Projectile_Hit", "Uncommon", 1, "Launches fireworks on hit");
                                            

    unregisterEnchantment()

      Description
        unregisterEnchantment() unregisters an enchant
      Usage
        
            $ce->unregisterEnchantment($id);
                                            
      Parameters
        ID
        • ID of enchantment to be unregistered
      Example
        
            $ce = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants");
            $ce->unregisterEnchantment(302);
                                            

Last Updated: June 14, 2018.