YAML bug

Discussion in 'Spigot Plugin Development' started by Sirenum, Apr 22, 2017.

  1. A little back story, about 5 months I had this working perfectly with no issues, however, I lost all my backups and didn't push to Git like I should've, so I'm stuck recreating this from memory.


    Code (Text):
          place: false
          break: false
          drop: true
            chat-enabled: true
          interact: true
          explosion: false

    Code (Text):
    public void writeWorld(Player player)
            String path = instance.getWConfig().getWorldConfig().getString("World-Management.saved-worlds.");
            String world = player.getWorld().getName();
            String author = player.getName();
            UUID uuid = player.getUniqueId();
            Timestamp ts = getStamp();
            Location location = player.getWorld().getSpawnLocation();

            if(instance.getWConfig().getWorldConfig().getConfigurationSection("World-Management.saved-worlds."+world) == null){
    //            write(path+""+world+".uuid",uuid);
                write(path+""+world+".permission", "Build.worlds."+world);
    //            write(path+""+world+".world-location",location.toString());
                write(path+""+world+".place", false);
                write(path+""+world+".break", false);
                write(path+""+world+".drop", true);
                write(path+""+world+".pickup", true);
                write(path+""+world+".chat.chat-enabled", true);
                write(path+""+world+".chat.chat-format", color("&8&l> &b[&7%world%&b] &a%name% &7%msg%").toString());
                write(path+""+world+".interact", true);
                write(path+""+world+".explosion", false);
                log(Debug.pluginLog() + "&a&lThe world, &n" + world + "&a&l has been added.");
                player.sendMessage(color( "&a&lThe world, &n" + world + "&a&l has been added."));
                log("&cError, this world has already been created or exists.");
  2. Too tired to look into your issue (even though i clearly see it but don't have any power to explain it), but why are you saving time-created as a Date string? It's better to save it as Java milliseconds (long) timestamp and convert that to a date when you want to display it. And follow the key naming conventions (don't know if there is one but), use time_created or timeCreated :p
  3. There's no conventions, and in OPs defense I find using dashes in the keys to separate words the most user-friendly option.
    #3 megamichiel, Apr 23, 2017
    Last edited: Apr 23, 2017
    • Agree Agree x 2
  4. Code (Java):
    String path = instance.getWConfig().getWorldConfig().getString("World-Management.saved-worlds.");
    Why are you ending the path with a .? Also that doesn't return a path that returns string at that path[/CODE]
  5. The empty string is redundant.

    I'm not sure what your issue is. Please don't be lazy and explain in full.
  6. You should read and pay attention before you give advice. Those are YAML path tags and it's completely normal to have the "-" character as such.

    As far as the method of saving the timestamp, there is a specific reason for why I'm doing that.
  7. No, it is necessary to properly concatenate the to variables. Otherwise it will not work.

    My issue is how the formatting is displaying after this code is executed. Please see the spoiler titled issue.
  8. I am ending it like that so I do not have to type it repeatedly when I add the rest of the path in.
  9. What did you call them? Path tags? What is a path tag? The yaml document is made up of keys and values. A path of keys is separated by the use of a dot, not a dash. You're using a dash in your key, where I see most people using a underscore (_) or camelCase.

    No. It is actually redundant. You can call toString() on your path of it doesn't work using the variable only.

    Now jump off your high horse or no one wants to help you.
    • Agree Agree x 1
  10. You know what they meant, don't be that guy. Your suggestion to follow the conventions was a little too strong, turning this into an argument. Some people prefer to name their keys one way, others another. No need to force somebody into it.
    • Like Like x 1
  11. You really need to read lmao. If you are to tired to get all of the information on a thread then do everyone else a favor - don't comment.

    Taken straight from the documentation

    Using the naming conventions that I use in my very configuration file.

    I know how YAML works. Stop confusing YAML's implementation with Java's naming conventions. The two are not synonymous.
  12. Your problem is in this string, You are asking for the String in there. Change this to
    Code (Text):
    String path = "World-Management.saved-worlds.";
  13. Yeah you aren't saving the path ur saving that valid at a path that isnt valid itself....
  14. Not forcing anyone. I usually work with json, and find it much more elegant. In JSON, you'd use the underscores or camelcase (you could use the dash as well, however it would be looked at as odd), hence why I made the suggestion.
  15. Awesome. But this isn't Json, it's YAML.
  16. I know, but if you look back at your initial post it was more of an order than a suggestion.
    • Agree Agree x 1
    • Informative Informative x 1