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

Solved Armor can't be remove

Discussion in 'Development' started by Dadoue, Aug 22, 2020.

  1. Dadoue

    Dadoue Spider

    Messages:
    7
    Hello,
    I'm looking for a code that prevents players from removing their armor.
    Thanks.
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    onTransActionEvent check if $inventiry instanceof ArmorInventory, setCancelled();
     
    Dadoue likes this.
  3. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    or you can use:
    PHP:
    public function onDrop(PlayerDropItemEvent $event) {
        if (
    $event->getItem() instanceof ArmorInventory) {
            
    $event->setCancelled(true);
        }
    }
     
    Dadoue likes this.
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Won't work. For this you need to use InventoryTransactionEvent
     
    Dadoue likes this.
  5. Dadoue

    Dadoue Spider

    Messages:
    7
    I tried that but it don't worked
    PHP:
    public function onTransActionEvent(InventoryTransactionEvent $event) {
        if (
    $event->getItem() instanceof ArmorInventory) {
            
    $event->setCancelled(true);
        }
    }
     }
     
    Last edited: Aug 22, 2020
  6. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    open your eyes, i said that in the second post in thread.
    also its working but its a glitch in w10 edition, players can drop with ctrl+click but in transactioninv they can drop armor anyway.
     
    Dadoue likes this.
  7. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You didn't say anything about that o_O
     
    Dadoue, RicardoMilos384 and Diduhless like this.
  8. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    public function onTransaction(\pocketmine\event\inventory\InventoryTransactionEvent $event) {
        foreach (
    $event->getTransaction()->getInventories() as $inventory) {
            if(
    $inventory instanceof \pocketmine\inventory\ArmorInventory) {
                
    $event->setCancelled();
                break;
            }
        }
    }
    Don't forget to register listener

    The code will block setting armor too.
     
    Dadoue likes this.
  9. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    you should use statment, register events like:
    its worrking fine in my kitpvp plugin for my server
     
    Dadoue likes this.
  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.