Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

InventoryTransactionEvent :c

Comments in 'Plugin Development' started by Cristalix, Aug 26, 2016.

  1. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    I update my server from 14.x to 15.x and now InventoryTransactionEvent work's not correct.
    Early i use:
    PHP:
         public function ChestTrans(InventoryTransactionEvent $event){
             
    $transactions $event->getTransaction()->getTransactions();
             foreach(
    $transactions as $tr){
                 if(
    $tr->getInventory() instanceof ChestInventory){
                     
    $chestTran $tr;
                 }elseif (
    $tr->getInventory() instanceof PlayerInventory){
                     
    $player $tr->getInventory()->getHolder();
                 }
             };
    But now when i transfer item from chest to player, server write in console:
    Undefined variable: chestTran and player.
    Why?
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Is that full code? I don't see anywhere you use those variables.
  3. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function ChestTrans(InventoryTransactionEvent $event){
             
    $transactions $event->getTransaction()->getTransactions();
             
    $chestTran null;
             
    $player null;
             foreach(
    $transactions as $tr){
                 if(
    $tr->getInventory() instanceof ChestInventory){
                     
    $chestTran $tr;
                 }elseif (
    $tr->getInventory() instanceof PlayerInventory){
                     
    $player $tr->getInventory()->getHolder();
                 }
                 if(
    $chestTran and $player) {
                     if (isset(
    $this->OnChest[$player->getName()])){
                         
    $event->setCancelled();
                         
    $item $chestTran->getSourceItem();
                         
    # ...
                      
    }
                 }
             }
    Last edited: Aug 26, 2016
  5. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    It's strange.

    PHP:
    $chestTran $tr;
    if (isset(
    $this->OnChest[$player->getName()])){
    We dont't have $player :3
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Edited.
    Cristalix likes this.
  7. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    I think, our's code same :'c
  8. dktapps
    Offline

    dktapps Active Member

    Joined:
    Jul 25, 2016
    Posts:
    101
    Well, I guess this also depends on whether you're actually using PM or one of its spoons. Ge****s made some changes to inventory behaviour to support Windows 10 Edition which may have caused similar issues. This is of course just speculation.
    Muqsit and Cristalix like this.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Not really, my code checks if they are assigned with necessary values but yours not.
    Let me correct you: I made some changes to inventory behaviour...
  10. dktapps
    Offline

    dktapps Active Member

    Joined:
    Jul 25, 2016
    Posts:
    101
    I'm trying to keep a low profile a little :p
    Primus likes this.
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Good luck at it :D
    dktapps likes this.

Share This Page

Advertisement