licrafter
本帖最后由 licrafter 于 2018-9-28 01:26 编辑

ConfigParser
ConfigParser API 是一个用 kotlin 编写的基于注解的配置文件系统, 它允许开发者使用 API 提供的 saveConfig and loadConfig 方法来读取和保存配置文件.源码地址:https://github.com/licraft-club/ConfigParser
如何使用
  1. public class ParserSample extends JavaPlugin {

  2.     public TestConfig config = new TestConfig();

  3.     @Override
  4.     public void onEnable() {
  5.         File file = new File(getDataFolder(), "config.yml");
  6.         if (!file.exists()) {
  7.             getConfig().options().copyDefaults(true);
  8.             saveDefaultConfig();
  9.             reloadConfig();
  10.         }
  11.         //开启 debug
  12.         ParserAPI.INSTANCE.setDebug(true);
  13.                 //加载配置文件
  14.         ParserAPI.INSTANCE.loadConfig(this, config);
  15.     }

  16.     @Override
  17.     public void onDisable() {
  18.             //保存配置文件
  19.         ParserAPI.INSTANCE.saveConfig(this, config);
  20.     }
复制代码
@ConfigBean
@ConfigBean 用来配置 classes 去加载哪个配置文件. 我们可以通过 file 参数指定配置文件的具体路径 (config.yml 是 file 的默认值):
  1. @ConfigBean
  2. public class TestConfig {
  3. }
复制代码
当然,我们也可以在代码里动态指定配置文件的路径
  1. public class TestConfig {
  2. }

  3. @Override
  4. public void onEnable() {
  5.         ParserAPI.INSTANCE.loadConfig(this,"config.yml",config);
  6. }
复制代码
@ConfigValue
@ConfigValue 是可以被 FileConfiguration 直接读写的字段的注解. 比如 Java 基本类型,List,和 ItemStack. For example:
  1. /**
  2. * data:
  3. *   name: configParser
  4. */
  5. @ConfigValue(path = "data.name",colorChar = '&')
  6. public String name;
复制代码
@ConfigSection
@ConfigSection 是只有在运行时才能确定准确路径的字段的注解. 比如在代码里动态添加记录的玩家名字和点数的键值对:
  1. /**
  2. *   points:
  3. *     notch: 39
  4. *     md_5: 92
  5. *     dinnerbone: 45
  6. */
  7. @ConfigValue(path = "data.points")
  8. public Map<String, Integer> pointsMap;
复制代码
你也可以查看更详细的使用方法sample project.

捐赠地址[http://paypal.me/licrafter]
  1. 本插件所用所有代码均为原创,不存在借用/抄袭等行为
复制代码
  1. 例如本插件为非盈利性插件,免费发布,严禁销售和转卖
复制代码


NoName德里奇
良心原创作品,支持了!