Solved Check if player adds item to GUI inventory

Discussion in 'Plugin Development' started by Kakarot798, Apr 29, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Kakarot798

    I've been developing a plugin for custom merchants, but I want it where you put an item in the GUI and it closes the inventory and gives you money.
    I've made the inventory, and the villager for it, all that I need to get to work is the selling. I've looked around on the internet for days now, and I've tried multiple things after reading some of this things I could use for InventoryClickEvent, and nothing has worked. Any advice?
     
  2. Offline

    HungerCraftNL

    Show us the codes, and what's the problem "nothing has worked" is not really clear, you'll need the InventoryClickEvent for the selling himself and check the EVENT.currentItem()(.getType()). You need the EntityInteractEvent to open the inventory.
     
  3. Offline

    Kakarot798

    Code:
    @EventHandler(priority=EventPriority.HIGH)
        public void InventoryE(InventoryClickEvent event){
            Inventory inv = event.getInventory();
            Player player = (Player) event.getWhoClicked();
           
            if(inv.equals(MerchantInventory.ItemBuyer())){
                ItemStack sell = new ItemStack(event.getCurrentItem());
                    inv.remove(sell);
                    player.closeInventory();
                    player.sendMessage("§dWorking Progress...");   
            }
        }
     
  4. Offline

    sgavster

    @Kakarot798 Use Inventory name, not type: So
    if(inv.getName().equalsIgnoreCase(MerchantInventory.ItemBuyer().getName())) {
     
  5. Offline

    Kakarot798

    That kinda worked, it will close the inventory and then say the message, but it doesn't remove the item. And I also wanted to make it where they had to put it in the 9 slots of the GUI, not just click in it their own inventory whilst being in the GUI. Think you could help me with that?
     
  6. Offline

    sgavster

    Use item.setType(null) or something along the lines.

    If you wanted to do that:
    I would use InventoryCloseEvent, check if it has 9 slots filled, if it does, remove the items, do stuff to the player, if it doesn't, give the items back.
     
  7. Offline

    Kakarot798

    Thanks, that helped. I couldn't use (null); but I can probably figure it out on my own from this point! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page