Configs | Adding: # | :(:(:(:(:(

Discussion in 'Spigot Plugin Development' started by UnthinkableR, May 17, 2015.

  1. Hello! I Was Wondering How Come Whenever I Add A '#Hello There' or a 'blank line' in the config it just removes the '#Hello There' and removes the 'blank line' :( i've seen other plugins use # ands blanks, so why can't i!
     
  2. The YML parser that is used sees the # and thinks, that's a comment. Lets stop reading that line and moves in (it then errors from an open string). Not sure how others use it, but I'd assume some sort of YML parser that won't think it's a comment if it's part of an open string.
     
    • Optimistic Optimistic x 1
  3. Bukkit skips those empty lines while saving the config to the file. If you have a copy of your config.yml in your jar, you can copy the recourse to your plugins directory in which case it will stay exactly the same. But whenever you call #saveConfig() they will be removed.
     
  4. I Don't need to know why i need to know how :/
     
  5. You can't add comments with Bukkit's YAML reader (there's another word for it not reader, I forget what it is). However you can add as many comments as you want use getConfig().options().header(String);

    Use \n when you want to create a new line.
     
    • Optimistic Optimistic x 1
  6. SnakeYAML? https://code.google.com/p/snakeyaml/
     
  7. But What if i want to use a comment right before a string and then repeat
     
  8. Put it like this: "#hashtag"
     
  9. I KNOW! but it removes that line!
     
  10. Chillex. We're trying to help ffs. //unwatched
     
    • Optimistic Optimistic x 1
  11. OMG HELP! NOW I CAN'T EVEN LOAD THE CONF*G NO MATTER WHAT I DO! WHAT WONG!
    PHP:
    [17:35:07 INFO]: [KitPvp] Enabling KitPvp v1.2
    [17:35:07 ERROR]: [KitPvp] Cannot load configuration from jar
    org.bukkit.configuration.InvalidConfigurationException: while scanning a simple
    key
    in 'string', line 12, column 1:
        LeaveMessage:'&c[-]&3%player%'
        ^
    could not found expected ':'
    in 'string', line 13, column 1:
        LaunchSpeed: 4
        ^

            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:57) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:214) [
    spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:162) [spi
    got.jar:git-Spigot-26dfd01-5cb9b70]
            at be.UnthinkableR.KitPvP.Main.Main.onEnable(Main.java:566) [KitPvp.jar:
    ?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) [sp
    igot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:335) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:405) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.craftbukkit.v1_8_R2.CraftServer.loadPlugin(CraftServer.jav
    a:356) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.craftbukkit.v1_8_R2.CraftServer.enablePlugins(CraftServer.
    java:316) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.craftbukkit.v1_8_R2.CraftServer.reload(CraftServer.java:74
    6) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot.jar:git-Spigot-26df
    d01-5cb9b70]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    25) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServe
    r.java:646) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchServerCommand(Craf
    tServer.java:632) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at net.minecraft.server.v1_8_R2.DedicatedServer.aN(DedicatedServer.java:
    405) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:3
    69) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:6
    51) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java
    :554) [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple
    key
    in 'string', line 12, column 1:
        LeaveMessage:'&c[-]&3%player%'
        ^
    could not found expected ':'
    in 'string', line 13, column 1:
        LaunchSpeed: 4
        ^

            at org.yaml.snakeyaml.scanner.ScannerImpl.stalePossibleSimpleKeys(Scanne
    rImpl.java:465) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.scanner.ScannerImpl.needMoreTokens(ScannerImpl.jav
    a:280) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:22
    5) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(Par
    serImpl.java:558) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~
    [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143)
    ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :226) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~
    [spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    2) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
    ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor.java:120) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:481) ~[spigot.jar:gi
    t-Spigot-26dfd01-5cb9b70]
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:400) ~[spigot.jar:git-Spigot-2
    6dfd01-5cb9b70]
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:55) ~[spigot.jar:git-Spigot-26dfd01-5cb9b70]
     
  12. PHP:
            File configFile = new File(this.getDataFolder() + File.separator + "config.yml");
            if (!(configFile.exists())) {
                Bukkit.getServer().getLogger().info("[" + this + "] config file not found, will attempt to create a default!");
                new File(this.getDataFolder().toString()).mkdir();
                try {
                    configFile.createNewFile();
                    FileWriter out = new FileWriter(configFile);
                    out.write("---\r\n");
                    out.write("# Your message\r\n");
                    out.write("line: How are you?\r\n");
                    out.write("\r\n");
                    out.write("otherLine: test message\r\n");
                    out.write("\r\n");
                    out.close();
                } catch (IOException ex) {
                    Bukkit.getServer().getLogger().severe("[" + this + "] error: config file does not exist and could not be created");
                }
            }
     
    • Like Like x 1
  13. whats
    \r\n
     
  14. Not sure what \r does but \n creates a new line

    Example:
    "This is line 1 \nThis is line 2"

    Output:
    This is line 1
    This is line 2

    EDIT: Ninja'd
     
  15. Whats wrong with this ^^^^
     
  16. Okay now how do i run some getString() or getInt()
     
  17. Like run if(getwhatever.getString("Line").equalsIgnoreCase("true"))
     
  18. When i use this method:

    Code (Text):
    File configFile = new File(this.getDataFolder() + File.separator + "config.yml");
            if (!(configFile.exists())) {
                Bukkit.getServer().getLogger().info("[" + this + "] config file not found, will attempt to create a default!");
                new File(this.getDataFolder().toString()).mkdir();
                try {
                    configFile.createNewFile();
                    FileWriter out = new FileWriter(configFile);
                    out.write("---\r\n");
                    out.write("# Your message\r\n");
                    out.write("line: How are you?\r\n");
                    out.write("\r\n");
                    out.write("otherLine: test message\r\n");
                    out.write("\r\n");
                    out.close();
                } catch (IOException ex) {
                    Bukkit.getServer().getLogger().severe("[" + this + "] error: config file does not exist and could not be created");
                }
            }
    I can no longer use my getConfig() Methods
     
  19. W hat should i do
     
  20. I will think about it.