Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用api插口/bukkit在config.yml中保存注释_Api_Config_Bukkit - Fatal编程技术网

使用api插口/bukkit在config.yml中保存注释

使用api插口/bukkit在config.yml中保存注释,api,config,bukkit,Api,Config,Bukkit,我有一个config.yml文件,其中有一些注释,如: #Thats the message when someone joins to the server Message: Hello User 但是当我保存config.yml文件并再次打开时,它会消失并且无法保存 我试图搜索一些api来解决这个问题,但是找不到我不想使用的api saveDefaultConfig(); 或 因为我不想保存这个抛出的代码,所以我想用api保存它。 我应该使用什么api?我建议您使用插口api,我认为它是

我有一个config.yml文件,其中有一些注释,如:

#Thats the message when someone joins to the server
Message: Hello User
但是当我保存config.yml文件并再次打开时,它会消失并且无法保存 我试图搜索一些api来解决这个问题,但是找不到我不想使用的api

saveDefaultConfig();

因为我不想保存这个抛出的代码,所以我想用api保存它。
我应该使用什么api?我建议您使用插口api,我认为它是最好的

这两个API在配置的头部分中只支持一条注释。如果要保存多条注释,应编写自己的YAMLConfiguration

要保存此标题,您应该尝试

getConfig().options().header("Your Comment");
getConfig().options().copyHeader(true)

您可以将注释与\n分隔成多行

您可以在src文件夹中创建config.yml,该文件夹将包含在jar中。通过在IDE中编辑此文件,可以设置默认值和任何注释。在主类中,只需调用
saveDefaultConfig()onEnable()中的code>
。之后,您可以使用
getConfig()
访问您的配置。

遗憾的是,在使用给定的工具时,这是不可能的

您需要手动编写自己的ConfigManager,您可以在其中执行此操作

以下是我得到的:


不过,它可能有一些bug:D

我不确定,但我相信只有第一行的注释会被删除。你能验证一下吗?我试过了,当我按save时,所有的评论都被删除了问题是我保存文件后,它不会保存评论,也不会运行插件。我在帖子中说过,我不想使用这个命令,因为它不起作用
getConfig().options().header("Your Comment");
getConfig().options().copyHeader(true)