Loading a hashmap from a file

Discussion in 'Plugin Development' started by benzimmer123, Aug 20, 2015.

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

    benzimmer123

    I have been trying to load a hashmap from a file but every time it returns null. The hashmap isn't null as it contains this...
    Code:
    EFFECTS:
        FIRE_RESISTANCE: 2
    
    After inserting a check to see if the configuration section is equal to null, the hashmap just seems to reset itself so it only adds the value I just entered.

    Any help would be much appreciated. :)

    Code:
    public HashMap<String, Integer> effects = new HashMap<String, Integer>();
    Loading...
    Code:
            if (plugin.settings.getConfig().getConfigurationSection("CLASSES." + classname.toUpperCase() + ".EFFECTS") != null) {
                for (String key : plugin.settings.getConfig().getConfigurationSection("CLASSES." + classname.toUpperCase() + ".EFFECTS").getKeys(true)) {
                    effects.put(key, plugin.settings.getConfig().getInt("CLASSES." + classname.toUpperCase() + ".EFFECTS." + key));
                }
            }
    Setting...
    Code:
            plugin.settings.getConfig().set("CLASSES." + classname.toUpperCase() + ".EFFECTS", effects);
            plugin.settings.saveConfig();
     
  2. Offline

    au2001

    @benzimmer123
    You're getting the values from "CLASSES.<classname>.EFFECTS" but your config says it's just "EFFECTS".
    Also, you can do that, it's way for efficient especially for large amount of values:
    Code:
    effect = getConfig().getConfigurationSection("EFFECTS").getValues(false);[/code
     
Thread Status:
Not open for further replies.

Share This Page