Question Items in Inventory

Discussion in 'Plugin Help/Development/Requests' started by 2008Choco, Mar 28, 2015.

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

    2008Choco

    Okay so I already know about the event.getPlayer().getInventory().contains(args0) method. But the only issue I have with using this method, is that it's inefficient for what I want to use it for. Basically, I want to test if a player has NO items in their inventory at all. If the player has no items in their inventory, it will run a bunch of other code. If they do have items, it will simply tell them, "Yo. You have items!".

    Is there any way I could get a method that tests if a player has no items in their inventory at all without having to type every single block and item type into blah.blah.blah.contains()? That would help a lot :p Thanks
     
  2. Offline

    pie_flavor

    @2008Choco
    Code:
    boolean b = true;
    for (ItemStack stack : e.getPlayer().getInventory().getContents()) {
        if (stack != null) b = false;
    }
    if (b) {
    //code goes here
     
Thread Status:
Not open for further replies.

Share This Page