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

Solved Take from chest

Discussion in 'Development' started by KHAV, Sep 11, 2017.

  1. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    How i can make if player take item from chest do something?:)
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    If you want to check when player take item from chest, take a look at InventoryTransactionEvent
     
  3. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    public function onTransaction(InventoryTransactionEvent $event){
      
    $transactions $event->getTransaction()->getActions();
      
    $player $event->getTransaction()->getSource();
      
    $action null;
      foreach(
    $transactions as $transaction){
        
    $action $transaction;
        break;
      }
      if(
    $action === null) return;
      if(
    $action instanceof ItemDropAction) return; // don't copy paste ;)
      
    $itemTaken $action->getSourceItem(); //item a player took from the inventory
      
    $itemGiven $action->getTargetItem(); //item a player placed in the inventory
     //code
    }
    NOTE: Use this code only if you are using the 1.2 branch!
     
    jasonwynn10 likes this.
  4. xXiKhalediXx

    xXiKhalediXx Spider

    Messages:
    8
    GitHub:
    Khaled098
    Theres no code for 1.1.5?
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    There is, but it's more complex. Maybe look into a Player Vaults plugin on github. It can be very helpful for understanding how to track inventory transactions
     
  6. xXiKhalediXx

    xXiKhalediXx Spider

    Messages:
    8
    GitHub:
    Khaled098
    ok thanks!
     
  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.