kangarko / Foundation

Foundation™ helps you create highly customized Minecraft plugins (based on Spigot/Paper API) that support multiple MC versions.
https://mineacademy.org
305 stars 63 forks source link

1.20.4: SimpleSettings saves multi-line strings incorrectly #278

Closed Kanin closed 4 months ago

Kanin commented 4 months ago

Here's the YAML docs on block strings

Steps to reproduce

  1. Add a multi-line string to your settings file, e.g:

    Scythes:
    - name: "&fBasic Scythe"
    lore: |-
      &7A basic scythe
    
      &f&lCOMMON
    tier: 1
    material: "WOODEN_HOE"
    glowing: true
  2. Start your server
  3. Check your settings.yml file
  4. Notice the multi-line string has been changed to:

    Scythes:
    - name: "&fBasic Scythe"
    lore: |-
    &7A basic scythe
    
    &f&lCOMMON
    tier: 1
    material: "WOODEN_HOE"
    glowing: true
  5. Attempt to restart your server and see that the plugin can no longer load settings.yml because it saved this to an un-parseable state.

SimpleSettings class & settings.yml

Relevant Files

kangarko commented 4 months ago

This is a rare edge case with our comments library which we use from https://github.com/tchristofferson/Config-Updater. Unfortunately I am not able to fix their parser. I recommend you convert lore into a list or find another storage design.

Kanin commented 4 months ago

This is a rare edge case with our comments library which we use from https://github.com/tchristofferson/Config-Updater. Unfortunately I am not able to fix their parser. I recommend you convert lore into a list or find another storage design.

Changing it to a list seems to cause issues?

    lore:
      - "&7A basic scythe"
      - "Right click to harvest crops"
      - ""
      - "&f&lCOMMON"
[11:25:22 INFO]:     ___                  _
[11:25:22 INFO]:    / _ \  ___  _ __  ___| |
[11:25:22 INFO]:   | | | |/ _ \| '_ \/ __| |
[11:25:22 INFO]:   | |_| | (_) | |_) \__ \_|
[11:25:22 INFO]:    \___/ \___/| .__/|___(_)
[11:25:22 INFO]:              |_|
[11:25:22 INFO]: !-----------------------------------------------------!
[11:25:22 INFO]: Error loading Scythes v1.0-SNAPSHOT, plugin is disabled!
[11:25:22 INFO]: Running on 1.20.4-R0.1-SNAPSHOT & Java 18.0.2.1
[11:25:22 INFO]: !-----------------------------------------------------!
[11:25:22 INFO]: Error: while scanning an anchor
[11:25:22 INFO]: in 'string', line 25, column 9:
[11:25:22 INFO]: - COMMON
[11:25:22 INFO]: ^
[11:25:22 INFO]: unexpected character found &(38)
[11:25:22 INFO]: in 'string', line 25, column 11:
[11:25:22 INFO]: - COMMON
[11:25:22 INFO]: ^
[11:25:22 INFO]: !-----------------------------------------------------!
kangarko commented 3 months ago

Doesn't seem to be a valid YAML construct in YAML 1.1, sorry. You can either disable comments by overriding the likenamed method, or use bukkit's 1.16+ yaml implementation with comments support to workaround this temporarily. I don't have the time right now to rewrite the third party parser, I apology.

Kanin commented 3 months ago

Doesn't seem to be a valid YAML construct in YAML 1.1, sorry. You can either disable comments by overriding the likenamed method, or use bukkit's 1.16+ yaml implementation with comments support to workaround this temporarily. I don't have the time right now to rewrite the third party parser, I apology.

Do you plan to do so eventually? I feel like this is a rather large issue for the config management being the fact that even if we don't use these strings in our default configs, we cannot prevent server owners from doing so... and in turn corrupting their config.

Kanin commented 3 months ago

Also, just found out... even setting lore to lore: "&7A basic scythe\nRight click to harvest crops\n\n&f&lCOMMON" in my default settings.yml, deleting my plugins folder, restarting the server... it sets lore to

  lore: |-
  &7A basic scythe
  Right click to harvest crops

  &f&lCOMMON

This is a big issue, it literally does not let me write anything that works?

kangarko commented 3 months ago

Can you please open a ticket at https://github.com/tchristofferson/Config-Updater? He's the maintainer of that config class

broken1arrow commented 3 months ago

Can you please open a ticket at https://github.com/tchristofferson/Config-Updater? He's the maintainer of that config class

Could you not just replace it with a better one?

kangarko commented 3 months ago

Feel free to suggest 1.7.10-1.20.6 compatible alternative. The bukkit's one only supports 1.16+

Kanin commented 3 months ago

Can you please open a ticket at https://github.com/tchristofferson/Config-Updater? He's the maintainer of that config class

What are the odds it gets seen? You've had an issue there open for over a year, and it's been nearly that long since the project has even had a proper update.

In my opinion it's a rather large flaw in the library, being configuration is the center of everything.

broken1arrow commented 3 months ago

Feel free to suggest 1.7.10-1.20.6 compatible alternative. The bukkit's one only supports 1.16+

Alright https://github.com/Carleslc/Simple-YAML, https://github.com/Osiris-Team/Dyml and https://github.com/Exlll/ConfigLib . I think on one other library (but not sure), but fail to find it.

broken1arrow commented 3 months ago

Can you please open a ticket at https://github.com/tchristofferson/Config-Updater? He's the maintainer of that config class

What are the odds it gets seen? You've had an issue there open for over a year, and it's been nearly that long since the project has even had a proper update.

In my opinion it's a rather large flaw in the library, being configuration is the center of everything.

Don't know how active he is today. But he did fix some critical bugs last time. Even if he is not so active. It is little fun he has not yet approved to master branch the javaDoc I added to all methods still.

kangarko commented 3 months ago

I'll ping him. I can't update to his latest version due to that ticket :/ I don't have the capacity to manage 100% of a large scale library, but since it's open source you can make a pull request. Or revert to Bukkit config or these libs above broken1arrow suggested. Hope you understand.