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

Inventory Selector

Discussion in 'Development' started by RoyalMCPE, Nov 18, 2016.

  1. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    I want to know how would I use the InventoryTransactionEvent on a customchest
     
  2. imYannic

    imYannic Baby Zombie

    Messages:
    113
    This is how I use it on my plugin:
    PHP:
    public function onInvTrans(InventoryTransactionEvent $event){

    $chest null;
    $player null;

    $transa $event->getTransaction()->getTransactions();
    $int $event->getTransaction()->getInventories();


            foreach (
    $transa as $t) {
                foreach (
    $int as $inst) {


                    
    $inst $inst->getHolder();
                    if (
    $inst instanceof Player) {
                        
    $player $inst;
                   
                }
               
         
                   

               
                    if (
    $inst instanceof Chest) {
                        
    $chest $inst;
                    }
    }
    $trans $t;

    }
               
    if(
    $chest == null || $player == null) return;

    }

    That's how you get the player and the chest of the event.
    To get the item which was transfered:
    PHP:
    $item $event->getTargetItem();
    More API functions you can look up here:
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/inventory/Transaction.php
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/inventory/TransactionGroup.php
     
  3. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Code formatting looks awesome (ironic)
     
    HimbeersaftLP likes this.
  4. imYannic

    imYannic Baby Zombie

    Messages:
    113
    What is your problem?
    I don't use an IDE, that's why it doesn't look common...
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    I'm not using an IDE too, but that's no excuse for bad code formatting. You should always have proper formatted code, it can save you days of searching for errors
     
    HimbeersaftLP likes this.
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And it can gain you more people willing to read your code. JuStLiKeNoBoDyWaNtStOrEaDtExTwRiTtEnLiKeThIs.
     
    Last edited: Nov 21, 2016
  7. imYannic

    imYannic Baby Zombie

    Messages:
    113
    How should I format my code? It takes long to format it by hand
     
  8. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    So somthing like this?

    PHP:
    public function onTrans(InventoryTransactionEvent $ev){
        
    $chest null;
        
    $player null;
        
    $trans $ev->getTransaction()->getTransactions();
        
    $int $ev->getTransatctions()->getInventorys();
         foreach(
    $trans as $t){{
                foreach(
    $int as $inst){
                       
    $inst $inst->getHolder();
                       if(
    $inst instanceof Player){
                         
    $player $inst;
                       }
                       if(
    $inst instanceof Hopper){
                         
    $hopper $inst;
                       }
                }
                
    $trans $t;
                
    $item $ev->getTargetItem();
                if(
    $item->getId() == 377){
                  
    $player->sendMessage(c::BOLD.c::DARK_PURPLE."(!)".c::RESET.c::DARK_AQUA." Comming soon");
                }
         }
      }
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    What editor are you using? Proper ones help you with formating, and some can even format it for you, while not being an IDE.
    Formatting is totally simple: Always add one level of indentation in one scope. When the scope ends, go one level back.
     
    SOFe and HimbeersaftLP like this.
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Can we stop talking about code style in every single Development thread?
     
    HimbeersaftLP and Thunder33345 like this.
  11. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    We have to. We should not spread unformatted and or bad practis-ed code.
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Go here. Stop debating about it in plugin development threads whose topics are not code style.
     
    HimbeersaftLP likes this.
  13. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    i disagree there no issue with unformatted code
    but ununified indents/inconsistent code style
    not everyone have the luxury to have an IDE

    but i agree to correct bad practice on term of code
     
  14. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    This happens evertime I open the inventory

    [05:21:24] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\inventory\InventoryTransactionEvent' to 'BuyCraft_Addon v0.1': Call to undefined method pocketmine\event\inventory\InventoryTransactionEvent::getTransatctions() on RoyalMCPE\BuyCraftAddon\Main
    [05:21:24] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\event\inventory\InventoryTransactionEvent::getTransatctions()" (EXCEPTION) in "/plugins/BuyCraftAddon_v0.1/src/RoyalMCPE/BuyCraftAddon/Main" at line 69
     
  15. TrixZSlow

    TrixZSlow Spider Ban Evader

    Messages:
    9
    getTransatctions ??????
    it's getTransactions()
     
  16. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Please learn to read error messages yourself.
     
  17. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    facepalm
     
    OnTheVerge and Thunder33345 like this.
  18. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Just in case you're unaware, there was a typo in InventoryTransactionEvent::getTransatctions(). It should be InventoryTransactionEvent::getTransactions().
     
    OnTheVerge 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.