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

Best Wy To Do This

Discussion in 'Development' started by Junkdude, Apr 3, 2017.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    So I'm trying to clear a chest inventory on transaction, aka when the player brings it to there inventory, but since the its PlayerInventory it clears the players inventory itself. Is there anyway i can lear the chest inventory but not the player inventory
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Can you show us what you have been trying? I suppose you could do a check of whether or not the inventory is an instanceof pocketmine\tile\Chest.
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    PHP:
    ublic function onTransaction(InventoryTransactionEvent $event){
            
    $transactions $event->getTransaction()->getTransactions();
            
    $player null;
            
    $chestinv null;
            
    $action null;

            foreach(
    $transactions as $transaction){
                
    $inv1 $transaction->getInventory();
                
                if(
    $inv1 instanceof PlayerInventory)
                {
                    foreach(
    $inv1->getViewers() as $assumed)
                        if(
    $assumed instanceof Player) {
                            
    $item Item::get(Item::PAPER);
                            
    $player $assumed;
                            if(
    $transaction->getTargetItem()->getCustomName() === TF::GREEN.TF::BOLD."Level I Book")
                            {
                                
    $inv1->clearAll();
                                
    $this->plugin->utils->sendLevel1BookMenu($assumed);
                            }
     
  4. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    PHP:
    if($inv1 instanceof ChestInventory){
       
    //code
    }
    [/QUOTE]
     
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    [/QUOTE]
    TYeah buts if its from the playerinventory to chest im doing it vice versa
     
  6. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  7. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Have you tried it and are sure? As far as I can tell, his suggestion would work. It also appears to be that way considering how Muqsit used it in ChestShop.
     
    Last edited: Apr 6, 2017
  9. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Have you tried it and are sure? As far as I can tell, his suggestion would work. It also appears to be that way considering how Muqsit used it in Chest
    yes but his checks to see if its has certian data,i just want to clear the inventory but cant since the inventory holder is Player
     
  10. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  11. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  12. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  13. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Not tested, but try this out.
    PHP:
        public function onTransaction(InventoryTransactionEvent $event){
            
    $transactions $event->getTransaction()->getTransactions();
            
    $player null;
            
    $chest null;
            
    $item null;
            foreach(
    $transactions as $transaction){
                
    $item $transaction->getTargetItem();
                
    $holder $transaction->getInventory()->getHolder();
                if(
    $holder instanceof Player){
                    
    $player $holder;
                } else if(
    $holder instanceof Chest){ //pocketmine\tile\Chest not pocketmine\block\Chest :P
                    
    $chest $holder;
                }
            }
            if(
    $player !== null and $chest !== null){
                
    $event->setCancelled();
                if(
    $item->getId() == Item::PAPER and $item->getCustomName() === TextFormat::GREEN.TextFormat::BOLD."Level I Book"){
                    
    $player->getInventory()->clearAll();
                    
    //call whatever else you need :P
                
    }
            }

        }
     
  14. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  15. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
  16. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    ?
     
  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.