1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Enchants

Discussion in 'Plugin Help' started by AppleDevelops, Jan 25, 2017.

  1. I have a plugin I'm working on and I have a method to add certain enchants by tapping an enchant table, but I've heard there is a method where I can add enchants with more ease, but I'm not sure if I know the method.
    I've heard that I can add enchants to an item in my inventory but I'm not sure if I know this method. Yes I am using PMMP if you were wondering.

    My current code:
    Code:
    $lapis = Item::get(351, 4, 3);
            if ($event->getPlayer()->getInventory()->getItemInHand()->hasEnchantments() === false) {
                if ($event->getBlock()->getId() === 116) {
                    if ($event->getPlayer()->getInventory()->contains($lapis)) {
                        if ($event->getPlayer()->getInventory()->getItemInHand()->getId() == 276) {
                            $config = $this->getConfig()->get("Weapon-Enchants");
                            $key = array_rand($config);
                            $leet = $config[$key];
                            $item = Item::get(Item::DIAMOND_SWORD, 0, 1);
                            $level = mt_rand(1, 5);
                            $item->addEnchantment(Enchantment::getEnchantment($leet)->setLevel($level));
    
                            $event->getPlayer()->getInventory()->removeItem($lapis);
                            //$event->getPlayer()->getInventory()->removeItem($event->getPlayer()->getInventory()->getItemInHand());
                            $event->getPlayer()->getInventory()->setItemInHand($item);
                            $event->getPlayer()->sendTip("Recieved enchantment " . $leet . " lvl " . $level);
     
  2. Never mind I have figured it out
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Can u tell? So people can learn? Me at least
     
  4. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Why that question ?
     
  5. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Is there something which is bugging you?
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    to solve the question itself? obviously...
     
    Marabou likes this.
  7. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Yes your question.
     
  8. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I dont see anything wrong in it
     
  9. LargeArt7338551

    LargeArt7338551 Silverfish

    Messages:
    23
    GitHub:
    largeart7338551
    This is getting pretty weird... And off topic.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.