1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
private FileConfiguration config; saveDefaultConfig();//创建config.yml文件 this.config = getConfig(); this.config.set("version", getDescription().getVersion());//设置版本号 Map<String, Object> options = new HashMap();//建立默认参数数组 options.put("disable-all", Boolean.valueOf(false));//4个默认参数 options.put("timeout", Integer.valueOf(60)); options.put("max-devices", Integer.valueOf(20)); options.put("worlds", Arrays.asList(new String[] { "plotworld" }));//带数组的默认参数 boolean set = false;//保存设置初始阀值 for (Map.Entry<String, Object> node : options.entrySet()) { if (!this.config.contains((String)node.getKey())) {//循环检查是否每个配置参数齐全, 任何一个不齐全, 则采用默认参数. set = true; this.config.set((String)node.getKey(), node.getValue()); } } if (set) {//只要有set=true,就进行config文件保存 saveConfig(); } this.maxDevices = this.config.getInt("max-devices"); this.timeout = this.config.getInt("timeout"); this.disableAll = this.config.getBoolean("disable-all"); this.enabledWorlds = new HashSet(this.config.getStringList("worlds")); |