Problem with config.getKeys()

Discussion in 'Plugin Development' started by jetp250, Jun 3, 2016.

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

    jetp250

    Hi there. I'm trying to make a 'reload' for my plugin config, so there wouldn't be a need for /reload. E.g. /myplugin reload. Anyway, when I use this code
    Code:
    public static void display(Player p) {
            Main.reload();
            config = Main.weapons;
            Set<String> w = config.getKeys(false);
            List<String> weapons = new ArrayList<String>();
            weapons.addAll(w);
           
            p.sendMessage("Weapons Size: " + weapons.size() + ", w size: " + w.size());
            for (int i = 0; i < weapons.size(); i++) {
                p.sendMessage(ChatColor.RED + weapons.get(i));
            }
    }
    with the following config:
    Code:
    Weapon_1:
      Name: '&aTest weapon'
      // Other variables
    it shows there's 1 weapon- Which is right. But, when I change the Weapon_1 name to like Weapon_2, instead of making a new one, and reloading the config with
    Code:
    reload();
    which just executes the loadYaml for all yaml files:
    Code:
    loadYaml(weaponsFile, weapons);
    where the loadYaml is
    Code:
    public static void loadYaml(File file, FileConfiguration configuration) {
            try {
                configuration.load(file);
            } catch (Exception e) {
            }
        }
    ( The weaponsFile is the file I use for the config, and weapons is the config, like
    Code:
    static File weaponsFile;
    public static FileConfiguration weapons;
    )
    it shows there's 2 weapons, when there's only one, with a changed name though.
    Whenever I change the weapon_1 name to something else instead of making a new one, and then using /myplugin reload, it still thinks the old weapon is there, when it isn't. I'm compiling against java 6 with bukkit 1.8, when I normally use java 8 and bukkit 1.9, but I didn't think there would be a difference..?
    Any help? Sorry for the messy thread. Btw, I know, the Name variable and such don't work with that code, I didn't see it necessary to include it on this..
     
Thread Status:
Not open for further replies.

Share This Page