Solved unable to load edited config.yml

Discussion in 'Plugin Development' started by Korotaxx, Mar 6, 2020.

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

    Korotaxx

    I'm currently experimenting with plugins.
    I want to use the config file so that I don't always have to hard code little changes I want to make like changing a number. But every time I want to use data from the file it uses the default, hard coded data.
    After I changed the config.yml I use the "/reload" command or restart the server and even though the file hasn't changed it still uses the default settings, not the ones I edited.
     
  2. Online

    timtower Administrator Administrator Moderator

    @Korotaxx Then please post your code so we can see how your plugin handles everything.
     
  3. Offline

    Korotaxx

    Code:
    public class Main extends JavaPlugin {
    
        public void onEnable() {
            saveDefaultConfig();
            new JoinListener(this);
        }
    
    }
    
    -------------------------------------------------------------
    
    public class JoinListener implements Listener {
    
        private Main plugin;
    
        public JoinListener(Main plugin) {
            this.plugin = plugin;
    
            Bukkit.getPluginManager().registerEvents(this, plugin);
        }
    
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            e.setJoinMessage(null);
           
            Player p = e.getPlayer();
    
            if (!p.hasPlayedBefore()) {
                Bukkit.broadcastMessage(
                        Utils.chat(plugin.getConfig().getString("firstjoin_message").replace("<player>", p.getName())));
            } else {
    
                Bukkit.broadcastMessage(
                        Utils.chat(plugin.getConfig().getString("join_message").replace("<player>", p.getName())));
            }
        }
    
    }
    this is the code I use.
    (Note: Utils.chat is just a method for translating color codes)
     
  4. Offline

    caderapee

    @Korotaxx How do you load the file ? how do you save it when you do a change if u do it ingame ?
     
  5. Offline

    Korotaxx

    I use Notepad++ to change the file and save it, then i use "/reload" ingame or restart the server to reload the plugins.
     
  6. Online

    KarimAKL

    @Korotaxx What does the config.yml file contain, and what is the output? You haven't hardcoded any messages, so it shouldn't be able to get any other message.

    Also, you can just use "e.setJoinMessage(/*your message*/)" instead of "Bukkit.broadcastMessage(/*your message*/)".
     
  7. Offline

    Korotaxx

    this is my config.yml in the Java project:
    Code:
    firstjoin_message: 'Hello &a<player>!'
    join_message: 'Hello again &a<player>!'
    When i start the server the first time it generates the config.yml file in the plugins/myPlugin/ folder. But when i change the config file and reload all plugins it still uses the config data from the Java prioject(code above).
     
  8. Offline

    caderapee

  9. Online

    timtower Administrator Administrator Moderator

    Third post in the thread.
     
  10. Offline

    caderapee

    Oh ok. I dun see any reason , except if u save the file when u disable the plugin.
     
  11. Offline

    Korotaxx

    ¯\_(ツ)_/¯ ok...
     
  12. Offline

    bowlerguy66

    Doesn't saveDefaultConfig() only save what you have already defined? Try saveConfig() instead.
     
  13. Offline

    Korotaxx

    thank you! it worked :D
     
    bowlerguy66 likes this.
Thread Status:
Not open for further replies.

Share This Page