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

[Solved] Getting a player on InventoryTransactionEvent

Discussion in 'Development' started by RoyalMCPE, Jan 25, 2017.

  1. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    On the InventoryTransactionEvent you can't get the player who calls the event. How would I be able to get the player?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Read source.
    PHP:
    /** @var InventoryTransactionEvent $event */
    $inventories $event->getTransaction()->getInventories();
    $player null;
    foreach(
    $inventories as $inv){
        foreach(
    $inv->getViewers() as $unknown){
            if(
    $unknown instanceof Player){
                
    $player $unknown;
                break 
    2;
            }
        }
    }
    //If no players, $player = null.
    $player->sendMessage("hey stop transactioning");
    The gfork has a better implementation tho. You can get it easily in the gfork without bulk code.
    Hope it gets merged into pmmp.
     
    Last edited: Jan 26, 2017
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Please don't mention the genesis fork if it doesn't have anything to do with the OP's question
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I didn't, you did tho.
     
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    He didn't, too, look how he spelled it :p
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    We have already made it way too obvious now xD
     
    HimbeersaftLP likes this.
  7. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Yeah xD
     
  8. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  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.