Solved Quick question on how to fix chest shop

Discussion in 'Plugin Development' started by plisov, Dec 9, 2017.

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

    plisov

    So I'm trying to create a chest shop and I have the basics down however there's one issue. When I add items to the shop, it works until the first slot of the chest clears. It doesn't check the other slots for items. Meaning it I put signs in the first and second slot of the chest and buy out, it will say that the chest is out of signs when there are still signs in the second slot. Here is the current code.
    Code:
    
                            for (int i = 0; i <= chest.getInventory().getSize(); i++) {
                                player.sendMessage("1 " + i);
                                if (chest.getInventory().getItem(i).getType().equals(item)) {
                                    player.sendMessage("2");
                                    chest.getInventory().getItem(i)
                                            .setAmount(chest.getInventory().getItem(i).getAmount() - amount);
                                    player.sendMessage("3");
    
                                    player.getInventory().addItem(new ItemStack(item, amount));
                                    player.sendMessage("4");
    
                                    chest.update();
                                    break;
                                }
                            }
    Any suggestions?
    plisov
     
  2. Offline

    Caderape2

    @plisov yea
    - Check if the chest contains the item with the method inventory.containsAtLeast(item, item.getAmount())
    - If yes, use the method inventory.removeItem(item) and add it to the player inventory.
     
  3. Offline

    plisov

    Thanks a lot!
    Got it to work.
    Cheers!
     
Thread Status:
Not open for further replies.

Share This Page