How to give player multiple dynamic reward via the config files

Discussion in 'Plugin Development' started by quaz3l, Jan 4, 2012.

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

    quaz3l

    I have a config.yml file setup like this:
    Code:
    '0':
        rewards:
            '0':
                type: item
                object:
                    id: 264
                    name: Diamond
                amount: 5
            '1':
                type: item
                object:
                    id: 3
                    name: Dirt
                amount: 64
    '1':
        rewards:
            '0':
                type: item
                object:
                    id: 24
                    name: Sandstone
                amount: 30
            '1':
                type: item
                object:
                    id: 1
                    name: Stone
                amount: 64
                
    I want to get all the data for each reward in one of the reward nodes, so I can give the player the amount of the item defined.

    I know i can do this with a lot of iteration and .get() functions from the config but this is EXTREMELY inefficient.
     
  2. Offline

    skore87

    It may be faster if you do all the loading into a hashmap<integer,customclass> and pull out exactly the information you want, rather than scanning through the whole thing every time.
     
  3. Offline

    quaz3l

    How would I put this into a hashmap?

    getValues()?
     
  4. Offline

    skore87

    Here is some pseudo code since I don't have an editor on this laptop (i'm in class).
    Code:
    public hashmap<string,customclass> myhashmap = new hashmap<string,customclass>();
    
    for string id : getconfig.getkeys(false){
        for string rewardid : getconfig.getconfigurationsection(id + ".rewards").getkeys(false){
            
            // use .get* to retrieve the value you want
            
            customclass rewardinfo = new customclass(type,objectid, objectname, amount);
            myhashmap.put(id,rewardinfo);
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page