Solved Config reload

Discussion in 'Plugin Help/Development/Requests' started by 2008Choco, Mar 20, 2015.

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

    2008Choco

    Hey, I've recently been having issues with a reload command. Config reloads are a lot harder than I thought. So I'm sure you know what I'm asking help for, but if you don't, I would like to know how to load a config file once it's had a change. For example, counter is set to 1 in the config file, and I change it to 7 while the server is online. I want to be able to run /awolchat reload and reload that number 7 without restarting my server completely.

    So here's the code I currently have, and when I run the /awolchat reload command, it seems to reset my change in my config back to the number it was previously.
    Code:
    if (commandLabel.equalsIgnoreCase("awolchat")){
                if (args.length >= 1){
                    if (args[0].equalsIgnoreCase("reload")){
                        if (player.hasPermission("awolchat.reload")){
                            config.options().copyDefaults(true);
                            saveConfig();
                            player.sendMessage(ChatColor.GOLD + "AWOL " + ChatColor.YELLOW + ">> " + ChatColor.GRAY + "Config has been reloaded");
                            return true;
                        }//Close Permission == true if statement
                        if (!player.hasPermission("awolchat.reload")){
                            player.sendMessage(ChatColor.RED + "You do not have the proper permissions to run this command");
                            return true;
                        }//Close Permission == false if statement
                    }//Close reload sub-command
    (There's more to that code, I just want to show you the reload portion of it)

    I know there are ways to shorten my code such as with formatting messages with %s's, but that's not my point. I need some help with the reload command in specific please :3 That would be fantastic. Thank you <3
     
  2. Offline

    nverdier

    @2008Choco First, you don't need to check if the player doesn't have the permission after you've checked if they have it. Just use an else statement. Also, to reload the config, just use reloadConfig() if it's in the class extending JavaPlugin. Otherwise, get an instance of the class extending JavaPlugin an use #reloadConfig().
     
    2008Choco likes this.
  3. Offline

    2008Choco

    Is it seriously that simple of a fix? And thanks for the else statement btw
     
  4. Offline

    nverdier

    2008Choco likes this.
Thread Status:
Not open for further replies.

Share This Page