Check for Inventory Changes

Discussion in 'Plugin Development' started by ursa_arcadius, Feb 12, 2011.

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

    ursa_arcadius

    I can not think of an efficient way to find what has changed in an inventory.
    The Scenario: I have an ItemStack[] oldVersion and ItemStack[] newVersion
    I want to find anything that has changed between the two. I was initially going to assume everything had changed and add create Hashmap<ItemID, Amount> and then go through newVersion, removing items from the Hashmap whenever I found ones that matched, or subtacting the amounts if the ItemID matched but the amounts did not. This obviously won't work I realized since you can not have duplicated Keys, it will just overwrite.

    Has anyone found a better way of accomplishing this task?
     
  2. Offline

    Valrix

    Currently, since inventory doesn't update once you've made changes and they just unveiled the updateInventory() command that doesn't currently work, you can't really tell. Inventory is something that they seem to be having the toughest time with.
     
  3. Offline

    Archelaus

    Valrix, he just wants to know how to check against them.
    Here:

    Code:
        public boolean invChanged(ItemStack[] oldV, ItemStack[] newV){
            boolean tf = false;
            int var = 0;
            if (oldV.length != newV.length) {
                tf = true;
            }else{
                for(ItemStack i : newV){
                    if(i.getTypeId() != oldV[var].getTypeId()){
                        tf=true;
                    }
                    var++;
                }
            }
            return tf;
    
        }
    then do

    Code:
    if(invChanged(oldVersion, newVersion)){
         //stuff
    }
     
  4. Offline

    ursa_arcadius

    Well I need to know what changed, but I realized that if there are multiple stacks of the same item I can just add their amounts and then subtract them later. I think I have it working. Thanks anyways.
     
Thread Status:
Not open for further replies.

Share This Page