Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Take off armor and put it back

Comments in 'Plugin Development' started by Primus, Jul 20, 2015.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    How can i unequip and equip armor?
  2. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    setArmorContents() ;)
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I need to keep that armour in player inventory so plugin could set that armour back not making new armour set
  4. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    PHP:
    public $armor = [];

    foreach(
    $inv->getArmorContents() as $slot => $item{
         
    $this->armor[$slot] = $item;
    }
  5. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    code from keepInventory
    PHP:
    public function PlayerDeath(PlayerDeathEvent $event){
            
    $player $event->getEntity();
            
    $this->drops[$player->getName()][1] = $player->getInventory()->getArmorContents();
            
    $this->drops[$player->getName()][0] = $player->getInventory()->getContents();
            
    $event->setDrops(array());
            
    $player->teleport($player->getLevel()->getSpawn());
        }
       
        public function 
    PlayerRespawn(PlayerRespawnEvent $event){
            
    $player $event->getPlayer();
            if (isset(
    $this->drops[$player->getName()])) {
                
    $player->getInventory()->setContents($this->drops[$player->getName()][0]);
                
    $player->getInventory()->setArmorContents($this->drops[$player->getName()][1]);
                unset(
    $this->drops[$player->getName()]);
            }
        }
  6. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    For check/get armor you can use getArmorContents()
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ik that but does it put armor in inventory?
  8. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Get armor contents save to array set armor contents to none and add the array of items to players inventory

Share This Page

Advertisement