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

Get item taken from chest (TransactionEvent)

Comments in 'Plugin Development' started by thebigsmileXD, Sep 8, 2016.

  1. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Hello fellas.
    Sure, i already wrote a plugin once, VillagerTrade, that "handeled" transactions, but in 0.15 it stopped working. I actually simply want to create a plugin that detects when an item of a chest was tapped, and give the player for example stone if he tapped cobblestone in the chest (took out/windows 10 edition item at mouse).

    Would be lovely to know how to do it, and best thing would be if it works with the latest Genisys inventory rewrite, because it supports windows 10 edition. Thanks!
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    I am also looking for this, my GUI shop stopped working after the latest update :(
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    This is the PocketMine forums, not Genisys.. If they change the event, it's not always changed in PocketMine. Since it isn't, this would still work.
  4. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Really "helpful" reply, many thanks. Please increase your post count somewhere else.
    ImagicalGamer likes this.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You cannot expect PocketMine Devs to know the Genisys API.
    PocketKiller likes this.
  6. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    But i can espect PocketMine devs to know the PocketMine API.
    "WOULD", didn't say it has to be written with that API. And just because PM is stuck in 0.11?
    4 Totally useless posts extra in this thread.
    ImagicalGamer likes this.
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PocketMine didn't change the event, Genisys did. This is basically a question about Genisys.
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I use Genisys too and have a code for InventoryTransactionEvent for my BedWars plugin which works well on 15.0.

    Here is the whole code for the event, edit it:
    PHP:
    public function onInvTrans(InventoryTransactionEvent $event){
    $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(!
    $this->inBedWars($player)) return;

    $inv $chest->getInventory();
    if(
    $chest->namedtag->getName() == "Hub"){
    $event->setCancelled();
    $categories = [243032742832612605427346];         

    switch(
    $trans->getTargetItem()->getId()){



    case 
    24// sandstone
    $chest->getInventory()->clearAll();
    $chest->namedtag->setName("1");
    $inv->setItem(0Item::get(24016));
    $inv->addItem(Item::get(33604));
    $inv->setItem(26Item::get(35141));

    break;


    }


    }else{
    // villager trading

    $event->setCancelled();
    $i $trans->getTargetItem();
    if(
    $i->getId() == 336) return;



    if(
    $i->getId() == 35 && $i->getDamage() == 14){
    $categories = [243032742832612605427346];         
    $chest->getInventory()->clearAll();
    foreach(
    $categories as $item){

    $chest->getInventory()->addItem(Item::get($item01));

    }

    }


    $slot = -1;
    foreach(
    $chest->getInventory()->getContents() as $sloti => $it){
    if(
    $it->getId() == $i->getId()){
    $slot $sloti 1;
    }}








    $priceitem $chest->getInventory()->getItem($slot);
    $id $i->getId();
    $cost $priceitem->getCount();
    $get $i->getCount();


    // check amount of bricks in player inv

    $amount 0;
    foreach(
    $player->getInventory()->all(Item::get($priceitem->getId())) as $item){
    $amount += $item->getCount();
    }



    if(
    $amount $cost || $amount == $cost){
    $player->getInventory()->removeItem(Item::get($priceitem->getId(), 0$cost));

    $item Item::get($id0$chest->getInventory()->getItem($slot 1)->getCount());

    if(
    $item->getId() == 280){
    $item->addEnchantment(Enchantment::getEnchantment(Enchantment::TYPE_WEAPON_KNOCKBACK));
    }

    $player->getInventory()->addItem($item);
    }else{

    $player->sendMessage($this->PREFIX."You don't have enough ingredients to buy this item.");
    }}
    }


    I hope I was able to help you!
    Skullex and thebigsmileXD like this.
  9. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Great.. do you use the BLUEPLAYZ bedwars? is so this fits perfectly :D
    Last edited by a moderator: Sep 12, 2016
  10. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    No, its my own plugin :D
  11. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    interesting, added it, fixed variables. shop works, shop villagers are gone and round doesn't start xd
    MyNameIsTriXz likes this.
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    [​IMG]
    Please stop. @thebigsmileXD can you chill for a bit?
    [​IMG]
    Sorry for these memes, but the problem is on the code, not on some American precooked meat. So are you guys working with Genisys or Pocketmine itself? I'll assume it is Genisys. Can you at least show some of your 'not-working' code?
    ImagicalGamer likes this.
  13. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Well, not sure what magic you included to let these things happen
  14. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Oh, spamming even more shit into this thread? i hate this forums.
    I talked with Blueplayz in teamspeak yesterday.. well he is rewriting the whole bedwars thing, but not for the public.
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I did ask for some of your code.
    CraftYourBukkit likes this.
  16. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    xD WHERE in your spam of memes?
    And the code is exactly what
    posted.
  17. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I heard about the failure, 3000 lines of code, and then it doesnt work, thats hard
    ImagicalGamer likes this.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    No. Look at my last sentence in my meme post.
  19. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Actually its only that long because he merged several classes into one file. you could easily split the classes.
  20. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Back to this. Villager trade is open source.
    It didn't work anymore in 0.15, used pocketmine before and after
    The link: https://github.com/thebigsmileXD/VillagerTrade
    Fun fact: first time i created and uploaded a repo using the git shell only
    Legoboy0215 likes this.

Share This Page

Advertisement