Solved Config file resetting on server reload

Discussion in 'Plugin Development' started by srspore, May 21, 2016.

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


    I tried to make a simple plugin basically to keep track of a player's balance, which is just a double. I can set a get the balance just fine, but when I reload the server the balance gets set back to 0.0. I'm very new to config files and I've probably done something wrong, but I can't figure out what. Thank you!

    This is the code that deals with the config file.
    // Followed pogostick29dev tutorial on settings managers.
    public class BankManager {
        private BankManager() {
        static BankManager instance = new BankManager();
        public static BankManager getInstance() {
            return instance;
        private Plugin p;
        private FileConfiguration config;
        private File cfile;
        public void setup(Plugin p) {
            config = p.getConfig();
            cfile = new File(p.getDataFolder(), "bank.yml");
        public FileConfiguration getConfig() {
            return config;
        public void saveConfig() {
            try {
            } catch (IOException e) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not creat bank.yml!");
        public void reloadConfig() {
            config = YamlConfiguration.loadConfiguration(cfile);
        public void setBalance(String player, double amount) {
            player = player.toLowerCase();
            config.set(player, amount);
        public double getBalance(String player) {
            if (!config.contains(player)) {
                config.set(player, 0.0);
            return config.getDouble(player);
    This is the code that deals with the commands
    public class Main extends JavaPlugin {
        BankManager bank;
        public void onEnable() {
            bank = BankManager.getInstance();
        public void onDisable() {
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (commandLabel.equalsIgnoreCase("setBal")) {
                bank.setBalance(sender.getName(), Double.parseDouble(args[0]));
                sender.sendMessage("Balance set to: " + bank.getBalance(sender.getName()));
            } else if (commandLabel.equalsIgnoreCase("getBal")) {
                sender.sendMessage("" + bank.getBalance(sender.getName()));
            return true;
    Thanks again!

    I figured it out, I just needed to add "p.saveConfig()" to the saveConfig() method in the Bank Manager class...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 21, 2016
Thread Status:
Not open for further replies.

Share This Page