Solved Config isn't read on reload/restart

Discussion in 'Plugin Development' started by xDeeKay, Aug 17, 2014.

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

    xDeeKay

    I'm storing some simple player data in the config like so:
    Code:
    Players:
      xdeekay:
        Team: blue
    However, when I run /reload or stop and start the server again, the server doesn't read xdeekay as being on the blue team. For example I have a chat listener which sets the players chat format based on what team the player is on, and the player has no format on the reload/restart.

    Here's my main:
    Code:java
    1. package net.dkcraft.mineside;
    2.  
    3. import java.io.File;
    4.  
    5. import net.dkcraft.mineside.commands.Class;
    6. import net.dkcraft.mineside.commands.Loadout;
    7. import net.dkcraft.mineside.commands.Redeploy;
    8. import net.dkcraft.mineside.commands.SetSpawn;
    9. import net.dkcraft.mineside.commands.Team;
    10. import net.dkcraft.mineside.listeners.ChatListener;
    11. import net.dkcraft.mineside.listeners.DamageListener;
    12. import net.dkcraft.mineside.listeners.PlayerListener;
    13. import net.dkcraft.mineside.listeners.WeaponListener;
    14. import net.dkcraft.mineside.util.ListStore;
    15.  
    16. import org.bukkit.Bukkit;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class Main extends JavaPlugin {
    20.  
    21. public static ListStore teamBlue;
    22. public static ListStore teamRed;
    23. public static ListStore teamPurple;
    24.  
    25. public void loadConfiguration() {
    26. this.getConfig().options().copyDefaults(true);
    27. saveDefaultConfig();
    28. }
    29.  
    30. public void onEnable() {
    31.  
    32. String pluginFolder = this.getDataFolder().getAbsolutePath();
    33.  
    34. File directory = new File(Bukkit.getPluginManager().getPlugin("MineSide").getDataFolder(), "teams");
    35. directory.mkdirs();
    36.  
    37. (new File(pluginFolder)).mkdirs();
    38.  
    39. Main.teamBlue = new ListStore(new File(pluginFolder + File.separator + "teams" + File.separator + "teamblue.yml"));
    40. Main.teamRed = new ListStore(new File(pluginFolder + File.separator + "teams" + File.separator + "teamred.yml"));
    41. Main.teamPurple = new ListStore(new File(pluginFolder + File.separator + "teams" + File.separator + "teampurple.yml"));
    42.  
    43. Main.teamBlue.load();
    44. Main.teamRed.load();
    45. Main.teamPurple.load();
    46.  
    47. loadConfiguration();
    48. reloadConfig();
    49.  
    50. this.getServer().getPluginManager().registerEvents(new ChatListener(this), this);
    51. this.getServer().getPluginManager().registerEvents(new DamageListener(this), this);
    52. this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
    53. this.getServer().getPluginManager().registerEvents(new WeaponListener(this), this);
    54.  
    55. this.getCommand("loadout").setExecutor(new Loadout(this));
    56. this.getCommand("class").setExecutor(new Class(this));
    57. this.getCommand("redeploy").setExecutor(new Redeploy(this));
    58. this.getCommand("setspawn").setExecutor(new SetSpawn(this));
    59. this.getCommand("team").setExecutor(new Team(this));
    60.  
    61. }
    62.  
    63. public void onDisable() {
    64. Main.teamBlue.save();
    65. Main.teamRed.save();
    66. Main.teamPurple.save();
    67. }
    68. }


    A little more information:
    The config isn't being wiped or set back to the defaults when I run /reload or restart the server, all the contents of the config are fine on the reload/restart. But for some reason, none of my classes can get the string of any part of my config, for example I can't get what team xdeekay is in. It's almost as if the config was wiped, but isn't. Any help would be appreciated.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    xDeeKay

    For anyone who stumbles across this thread in the future, I have solved this.
    It's not an issue with my config at all, but rather my .getConfig() method. I had this:
    Code:java
    1. if (plugin.getConfig().getString("Players." + player.getName() + ".Team") == "blue") {
    2. event.setFormat(ChatColor.WHITE + "[" + ChatColor.BLUE + "Blue" + ChatColor.WHITE + "] " + player.getDisplayName() + ChatColor.WHITE + ": " + ChatColor.WHITE + event.getMessage());
    3. }

    Instead of using == "blue", I changed it to .equals("blue"), so it now looks like this:
    Code:java
    1. if (plugin.getConfig().getString("Players." + player.getName() + ".Team") .equals("blue")) {
    2. event.setFormat(ChatColor.WHITE + "[" + ChatColor.BLUE + "Blue" + ChatColor.WHITE + "] " + player.getDisplayName() + ChatColor.WHITE + ": " + ChatColor.WHITE + event.getMessage());
    3. }

    Hope this helps anyone else having this issue.
     
Thread Status:
Not open for further replies.

Share This Page