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

Prevent someone from taking something from your chest

Discussion in 'Development' started by McpeBooster, Mar 24, 2017.

  1. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    How exactly I prevent with the transaction event, that someone can take something from a Chest?
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    set the event to be cancelled...
     
  3. Shockskill

    Shockskill Silverfish

    Messages:
    15
    GitHub:
    Shockskill
    $event->setCancelled(TRUE);
     
  4. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    When I do this:
    PHP:
    public function onTransaction(InventoryTransactionEvent $event){
          
    $trans $event->getTransaction()->getTransactions();
          foreach(
    $trans as $t){
            
    $inv $event->getTransaction()->getInventories();
            foreach(
    $inv as $i){
              
    $chest $i->getHolder();
              if(
    $chest instanceof Chest){
                
    $event->setCancelled(true);
              }
              if(
    $chest instanceof Player){
                
    $event->setCancelled(true);
              }
            }
          }
      }
    About every third click you still get the item into the inventory
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Might it just be a client-side illusion?
     
    Muqsit likes this.
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    What is Chest? \pocketmine\block\Chest or \pocketmine\tile\Chest?
     
  7. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Flavius12 of EvolSoft has created a nice plugin called ChestLocker.

    Its not updated to the latest api as of now, but i have access to the repo and i will update and submit to poggit.!
     
    Bagoschwago 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.