Solved Plugin Not Reading The Right Config?

Discussion in 'Spigot Plugin Development' started by Joedon, Jun 15, 2016.

Thread Status:
Not open for further replies.
  1. Hi there in a config for one of my plugins I have a section where you can put certain words that a bot in chat will respond to (TalkingBot). For some reason, when you remove a sentence it should detect and reload the plugin, it still reads it as if it were there. Even on restarts! it reads as if it were the default config when the config in the folder shows it without it. I'm using normal getConfig().get... methods to retrieve the config, and when they reload it I use this:
    Code (Text):
    getConfig().options().copyDefaults(false);
    reloadConfig();
    Any ideas?

    Thanks for any help this is very strange to me :3
     
  2. If you have a command that removes a sentence that'd be okay. You can't delete a line manually and not reload it though. You have to have some sort of command to complete the reloadConfig() method.
     
  3. Yes it is in a command method that, when ran, runs that part I showed you. It has been working on all my other plugins fine.
     
  4. Is the configuration file being created?
     
  5. Because it is pulling the config from the compiled .jar.
     
  6. Yes that is what I am thinking but I don't understand how. This is how it loads it (onEnable):

    Code (Text):
        public File loadResource(Plugin plugin, String resource) {
           
            File folder = plugin.getDataFolder();
            if (!folder.exists())
                folder.mkdir();
                File resourceFile = new File(folder, resource);
                try {
                    if (!resourceFile.exists() && resourceFile.createNewFile()) {
                try (InputStream in = plugin.getResource(resource);
                      OutputStream out = new FileOutputStream(resourceFile)) {
                     ByteStreams.copy(in, out);
                 }
             }
         } catch (Exception ignored) {
             ignored.printStackTrace();
         }
         return resourceFile;
    }
    and I get it like a normal config. I don't see where it's going wrong.
     
  7. Yes everything works except it's somehow reading from the default config
     
  8. 1) If your plugin jar contains a default config.yml file use saveDefaultConfig() instead of that copyDefaults() crap. (you'll even get to keep your comments this way too :eek:)

    2) Dont just delete (nullify) a default key thats in your default config.yml - Bukkit is designed to read from memory first, then from jar if the key is not found or has nullified value.


    So, you can leave a key empty (not nullified) and it will be read as empty just fine how you expect.

    Code (Text):

    key: []
     
    of even


    Code (Text):

    key: ""
     
     
    #8 BillyGalbreath, Jun 15, 2016
    Last edited: Jun 15, 2016
    • Agree Agree x 1
    • Winner Winner x 1
    • Informative Informative x 1
  9. Haha once I saw that Mr. Galbreath replied I knew this would be solved xD. Thanks for your help and informing me of how that all works :) It is fixed now :D! Thanks!
     
    • Friendly Friendly x 1
Thread Status:
Not open for further replies.