Config not setting?

Discussion in 'Plugin Development' started by CandyCranium, Jul 18, 2014.

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

    CandyCranium

    So I have a command to set the spawns of the arena that they specify, and the messages work and everything, but the only thing that isn't working is the setting of the config.
    Code:java
    1.  
    2. if(args[1].equalsIgnoreCase("one")) {
    3. FFA.getInstance().getConfig().set("Arena." + args[0] + ".RandomSpawn.One.X", p.getLocation().getX());
    4. FFA.getInstance().getConfig().set("Arena." + args[0] + ".RandomSpawn.One.Y", p.getLocation().getY());
    5. FFA.getInstance().getConfig().set("Arena." + args[0] + ".RandomSpawn.One.Z", p.getLocation().getZ());
    6. FFA.getInstance().saveConfig();
    7. p.sendMessage(FFA.pre + ChatColor.BLUE + "Random Spawn One set!");
    8. return true;
    9. }
    10.  

    I checked the args.length, and I made it so that the args[0] is the arena name. Here's where I set the arena:
    Code:java
    1.  
    2. FFA.getInstance().getConfig().addDefault("Arena." + args + ".RandomSpawn.One.X", 0);
    3. FFA.getInstance().getConfig().addDefault("Arena." + args + ".RandomSpawn.One.Y", 0);
    4. FFA.getInstance().getConfig().addDefault("Arena." + args + ".RandomSpawn.One.Z", 0);
    5. FFA.getInstance().saveConfig();
    6.  
     
  2. Offline

    Giraffeknee

    Save and reload the config (in that order).
     
  3. Offline

    CandyCranium

    Giraffeknee
    No see the thing is, it's not saving at all. Right after I set it, I check to see if it saved in the config, but it didn't :/
     
  4. Offline

    Giraffeknee

    You need to reload it after you save it
     
  5. No you don't... The reloadConfig() method just re-loads the data from the file. Since you're using getConfig().set(), the config's already updated. Only time reloadConfig() should be called is if the actual file is modified, and not the config, or when the config is null.
     
  6. Offline

    negative_codezZ

    CandyCranium, I usually make a separate file for arenas, don't save them in the config. Here:

    Code:java
    1. public class ArenaFile {
    2.  
    3. private static File file;
    4. private static FileConfiguration arenaFile;
    5.  
    6. private static void reload() {
    7. if(arenaFile == null) {
    8. file = new File(new File(MagicWars.get().getDataFolder(), "Data"), "ArenaFile.yml");
    9. arenaFile = YamlConfiguration.loadConfiguration(file);
    10. }
    11. }
    12.  
    13. public static FileConfiguration get() {
    14. reload();
    15. return arenaFile;
    16. }
    17.  
    18. public static void save() {
    19. if(file != null && arenaFile != null) {
    20. try {
    21. get().save(file);
    22. } catch (IOException exception) {
    23. Bukkit.getLogger().log(Level.SEVERE, "Encountered error whilst saving arena file...");
    24. }
    25. }
    26. }
    27.  
    28. }
     
Thread Status:
Not open for further replies.

Share This Page