How to get inventory contents.

Discussion in 'Plugin Development' started by joaogl, Apr 27, 2013.

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

    joaogl

    Hello,


    Code:
    for (ItemStack item : player.getInventory().getContents()) {
    player.sendMessage(ChatColor.RED + "ID: " + item.getTypeId() + " Amount: " + item.getAmount());
     
    }
    this code gets the inventory the inventory slot by slot, if have two packs of dirt on my inv. how can I sendMessage 128 dirt instead of the current 64 dirt and 64 dirt?

    Thanks joaogl.
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    If you want to do that, you will need to read the entire inventory, and sum similar item stacks, before you start printing anything.
     
  3. Offline

    joaogl

    I know that I just dont know how to do it...
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    Do you know how you would go through a toy box and count up all the legos by color?

    The idea is no different.
     
  5. Offline

    joaogl

    I think this works... but my questions is, if two player do the command at the same time it will screw everything up no?

    code:

    Code:
    int[] amount = new int[5000];
                for (ItemStack item : inventory) {
                    amount[item.getTypeId()] += item.getAmount();
                }
     
Thread Status:
Not open for further replies.

Share This Page