Solved Value of items!

Discussion in 'Plugin Development' started by Cryices, Feb 13, 2014.

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

    Cryices

    I'm using this Map<ItemStack, Integer> poop = new HashMap<ItemStack, Integer>();
    to value my items, I add them with poop.put(ItemStack, value); then what I'm trying to do it get the value of all the items in the list added together. Any help?
     
  2. Offline

    Acer_Mortem

    Cryices

    Okay, here's what I would do:

    Code:
            int total = 0;
            for(Integer whatever : poop.values()){
                total = whatever + total;
            }
    What we're doing here, is we're defining an integer called 'total'. Then, we're looping through all of the values (Integers) within the HashMap poop, and we're adding the values to total. In the end, total should be all of the Integers within poop added up :)

    Good luck with your plugin!
     
  3. Offline

    Maurdekye

    Cryices
    Code:java
    1. int total = 0;
    2. for (ItemStack key : poop.keySet())
    3. total += poop.get(key);

    Your total should be equal to the variable 'total'.
     
Thread Status:
Not open for further replies.

Share This Page