Solved Creating default configuration issue

Discussion in 'Spigot Plugin Development' started by SoyDrex, Feb 9, 2020.

  1. So I have a HUGE problem with my configuration files, basically when I'm trying to make a default config the plugin throw this big error:

    Code (Java):
    [19:16:33] [Server thread/INFO]: [Glint] Enabling Glint v0.0.1
    [19:16:33] [Server thread/ERROR]: Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: unacceptable code point ' ' (0x0) special characters are not allowed
    in "'string'", position 2
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:56) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:160) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:212) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:164) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:133) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at code.isorp.glint.Glint.firstRun(Glint.java:14) [Glint.jar:?]
            at code.isorp.glint.Glint.onEnable(Glint.java:28) [Glint.jar:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:432) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:464) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:378) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:457) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:274) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at java.lang.Thread.run(Thread.java:834) [?:?]
    Caused by: org.yaml.snakeyaml.reader.ReaderException: special characters are not allowed
            at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:211) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:176) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:171) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.reader.StreamReader.peek(StreamReader.java:126) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.scanner.ScannerImpl.scanToNextToken(ScannerImpl.java:1177) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:287) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:227) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:195) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:107) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:141) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:525) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:438) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:54) ~[spigot-1.15.2.jar:git-Spigot-c574e08-708be69]
            ... 15 more
    I have no idea about why is this happening and i didn't find any solution...

    [​IMG]

    Also, I don't have anything on my config file, it's only a boolean and it doesn't do anything right now


    [​IMG]


    Code (Java):
    package code.isorp.glint.utils;

    import code.isorp.glint.Glint;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.Plugin;

    import java.io.File;
    import java.io.IOException;

    public class ConfigurationManager {

        private Plugin plugin = Glint.getPlugin(Glint.class);

        public FileConfiguration messagesFile;
        public File messages;

        @SuppressWarnings("ResultOfMethodCallIgnored")
        public void setup(){
            if(!plugin.getDataFolder().exists()){plugin.getDataFolder().mkdirs();}
            messages = new File(plugin.getDataFolder(), "messages.yml");

            if(!messages.exists()){
                plugin.getLogger().info("Creating files...");
                try {
                    messages.createNewFile();
                    plugin.getLogger().info("Files created successfully.");
                }catch (IOException e){
                    plugin.getLogger().severe("Couldn't create configuration files.");
                }
            }
            messagesFile = YamlConfiguration.loadConfiguration(messages);
        }

        public void saveConfig(){
            try {
                messagesFile.save(messages);
            }catch (IOException e){
                plugin.getLogger().severe("Couldn't save files");
            }
        }

        public void reloadConfig(){
            messagesFile = YamlConfiguration.loadConfiguration(messages);
            plugin.getLogger().info("Configuration files reloaded successfully");
        }

        public FileConfiguration getMessagesFile(){
            return messagesFile;
        }
    }
     

    (also I'm pretty fresh with java so be nice pls)
     
    #1 SoyDrex, Feb 9, 2020
    Last edited: Feb 9, 2020
  2. ? its exactly as the stack trace tells you. Dont use the ' character in your strings or maybe use html outlining
     
    • Agree Agree x 1
  3. Google yaml validator, I use the lint one i believe, paste in your file hit validate and it will tell you where your error is, use it enough and you will learn how to spot them yourself :)
     
    • Useful Useful x 1
  4. I already did that, returns "Valid YAML"
     
  5. I don't have any character on the file, it's only a boolean and it doesn't do anything for now
     
  6. Don’t have access to the configmanager code so I have no idea how to help you
     
  7. its a boolean? your not doing 'true' or "true" are you? booleans dont have quotes of any sort

    make sure you are saving the file in utf-8 and you are not using a word processing program like word to edit with
     
  8. I'm using the default text editor of IntelliJ, how can i save the file in utf-8?

    [​IMG]
     
  9. Code (Java):
    package code.isorp.glint.utils;

    import code.isorp.glint.Glint;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.Plugin;

    import java.io.File;
    import java.io.IOException;

    public class ConfigurationManager {

        private Plugin plugin = Glint.getPlugin(Glint.class);

        public FileConfiguration messagesFile;
        public File messages;

        @SuppressWarnings("ResultOfMethodCallIgnored")
        public void setup(){
            if(!plugin.getDataFolder().exists()){plugin.getDataFolder().mkdirs();}
            messages = new File(plugin.getDataFolder(), "messages.yml");

            if(!messages.exists()){
                plugin.getLogger().info("Creating files...");
                try {
                    messages.createNewFile();
                    plugin.getLogger().info("Files created successfully.");
                }catch (IOException e){
                    plugin.getLogger().severe("Couldn't create configuration files.");
                }
            }
            messagesFile = YamlConfiguration.loadConfiguration(messages);
        }

        public void saveConfig(){
            try {
                messagesFile.save(messages);
            }catch (IOException e){
                plugin.getLogger().severe("Couldn't save files");
            }
        }

        public void reloadConfig(){
            messagesFile = YamlConfiguration.loadConfiguration(messages);
            plugin.getLogger().info("Configuration files reloaded successfully");
        }

        public FileConfiguration getMessagesFile(){
            return messagesFile;
        }
    }
     

    EDIT: I'm pretty sure the problem it's not on the ConfigurationManager anyways
     
    #9 SoyDrex, Feb 9, 2020
    Last edited: Feb 9, 2020
  10. Can you paste your whole config.yml?
     
  11. [​IMG]

    i already posted it 3 times...
     
  12. Well your code says message.yml not config.yml
     
  13. The problem its on the creation of the config.yml, I'm trying to make my config.yml by the default way.

    I checked the plugin without the "copyDefaults" method and it runs like it should do
     
  14. so you have a config.yml in the top level of your jar and you use saveDefaultConfig(); ?
     
  15. i think
     
  16. Ok so, I solved the issue by changing the method "copyDefaults" to this one:

    Code (Java):
    File defaultConfigFile = new File(getDataFolder(), "config.yml");

    if (!defaultConfigFile.exists()){
                saveResource("config.yml", false);
                this.saveDefaultConfig();
            }
    I don't know why the other one didn't work, but thanks to the people who tried to help me ;)
     
  17. saveDefaultConfig() does the file check for you. Basically if the file doesn't exist it copies it to the data directory. Its all built in for you already.
     
    • Useful Useful x 1