Solved Config.yml Comments being erased from SaveConfig()

Discussion in 'Spigot Plugin Development' started by FenderZS, Jan 21, 2022.

  1. Hello Forums, this Thing has been baffling me for ages.
    So I tried to do everything from deleting SaveConfig() to implementing SimpleConfig and it realy doesnt work.

    First of the details, I am not using addDefault(), I'm editing the config.yml Directly
    and when using SimpleConfig, It's nuts considering I use alot of complicating methods like this one before implementing SimpleConfig.

    Code (Java):
    public ConfigurationSection getConfigSection(String name, ConfigurationSection section){
            if(section.isConfigurationSection(name)){
                return section.getConfigurationSection(name);
            }else{
                return section.createSection(name);
            }
        }
    (Note: This Method is used if there is a section or not because sometimes when using createSection and reloading the server, the data in the config.yml would be reset to it's default values, you can solve and tell the solution of this if you have the time).

    Thanks for Helping and please make this quick cause I'm answering my School Modules.
     
  2. This topic has been discussed here a million times.

    There are only two ways to save a config with comments:
    A) Custom saving to the file
    B) Custom saving to the file

    EDIT:
    We have created our own YAML file manager for this case, but it will be useless in the case of YamlConfiguration.
    https://github.com/TheDevTec/TheAPI...c/theapi/utils/datakeeper/SectionBuilder.java
     
  3. Well I have tried many things such as
    Code (Java):
    if (!getDataFolder().exists())
                getDataFolder().mkdir();

            File file = new File(getDataFolder(), "config.yml");

            if (!file.exists()) {
                try (InputStream in = getClass().getResourceAsStream("config.yml")) {
                    Files.copy(in, file.toPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            saveDefaultConfig();
    and
    Code (Text):
    saveDefaultConfig();
    //The config needs to exist before using the updater
    File configFile = new File(getDataFolder(), "config.yml");

    try {
      ConfigUpdater.update(plugin, "config.yml", configFile, Arrays.asList(...));
    } catch (IOException e) {
      e.printStackTrace();
    }

    reloadConfig();
    and all of them still doesn't work!

    Is Bukkit ever gonna fix this? I have tried like a million times in one day and everything would STILL NOT WORK!
    Please Help Me!
     
  4. If you read the post that @mrfloris sent, you would find that comment support has been added in 1.18.

    If you need to save comments for older versions, then you will need a custom solution. Why? Because, IIRC, @md_5 stated somewhere that the changes won't be backported to older versions, which IMO is dumb, but hey I don't make the rules.
     
  5. Yeah but when I try
    Code (Java):
    getConfig().setComments("gui_items", Arrays.asList("Yes Test"))
    It throws a java.lang.NoSuchMethodError.

    Here is the Stacktrace
    Code (Text):
    java.lang.NoSuchMethodError: 'void org.bukkit.configuration.file.FileConfiguration.setComments(java.lang.String, java.util.List)'
            at mc.fenderas.arrowroyale.ArrowRoyale.onEnable(ArrowRoyale.java:58) ~[arrowroyale-1.0-SNAPSHOT.jar:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugin(CraftServer.java:564) ~[paper-1.18.1.jar:git-Paper-101]
            at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugins(CraftServer.java:478) ~[paper-1.18.1.jar:git-Paper-101]
            at org.bukkit.craftbukkit.v1_18_R1.CraftServer.reload(CraftServer.java:1036) ~[paper-1.18.1.jar:git-Paper-101]
            at org.bukkit.Bukkit.reload(Bukkit.java:857) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:54) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_18_R1.CraftServer.dispatchCommand(CraftServer.java:897) ~[paper-1.18.1.jar:git-Paper-101]
            at org.bukkit.craftbukkit.v1_18_R1.CraftServer.dispatchServerCommand(CraftServer.java:860) ~[paper-1.18.1.jar:git-Paper-101]
            at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:507) ~[paper-1.18.1.jar:git-Paper-101]
            at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:481) ~[paper-1.18.1.jar:git-Paper-101]
            at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1470) ~[paper-1.18.1.jar:git-Paper-101]
            at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1264) ~[paper-1.18.1.jar:git-Paper-101]
            at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.1.jar:git-Paper-101]
            at java.lang.Thread.run(Thread.java:833) ~[?:?]
     
  6. The thread had 1.18-1.18.1 in the title, but maybe the support was only added in 1.18.1. I’d recommend trying that version since your are getting a NoSuchMethodError.
     
    #7 ShadowMasterG23, Jan 23, 2022
    Last edited: Jan 23, 2022
  7. But I'm in that version. 1.18.1

    Code (Text):

    <dependency>
          <groupId>org.spigotmc</groupId>
          <artifactId>spigot-api</artifactId>
          <version>1.18.1-R0.1-SNAPSHOT</version>
          <scope>provided</scope>
    </dependency>
     
  8. I think you are using Spigot 1.18 when testing.
     
  9. What do you mean, the server or the Minecraft Client?
     
  10. Your Server.
     
  11. It's 1.18.1 also
    Code (Text):
    {"currentVersion":"git-Paper-101 (MC: 1.18.1)"}
     
  12. try use Spigot.
     
  13. It's a risk, and I don't want to unless that's the only way then I'll do it. I purposely made this plugin for paper and spigot so I don't know what to do
     
  14. Also im busy at answering my school modules so don't try to tell me to do some hard task
     
  15. That api seems to be Spigot only.
     
  16. huh so that means that I have to turn the dependencies from spigot to paper?
     
  17. Updated your server software, paper build 101 does not have the comment support merged yet. It was added in build 120.
     
  18. Oh my gosh thanks DerFrZocker, I just updated to build 170 and it saved it, turns out my server was an old test server in build 101 and the comment update build was 134 (33 builds later). Thanks so much. I guess updating the server was the solution.