java config getlist,Java FileConfiguration.getList方法代碼示例

import org.bukkit.configuration.file.FileConfiguration; //導入方法依賴的package包/類

public BukkitMotdConfig loadConfig() {

saveDefaultConfig();

reloadConfig();

FileConfiguration config = getConfig();

// check for ColorMOTD 1.x

if (!config.contains("version")) {

logger.info("ColorMOTD 1.x detected, renaming 'config.yml' to 'config.old.yml' ...");

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

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

newLocation.delete();

if (!oldLocation.renameTo(newLocation)) {

throw new RuntimeException("Unable to rename 'config.yml' to 'config.old.yml'!");

}

saveDefaultConfig();

reloadConfig();

}

BukkitMotdConfig r = new BukkitMotdConfig();

for (Object motdObj : config.getList("motds")) {

if (motdObj instanceof String) {

r.addMotd(((String) motdObj).replace("\\n", "\n"));

} else if (motdObj instanceof Map) {

@SuppressWarnings("unchecked")

Map map = (Map) motdObj;

String line1 = map.getOrDefault("line1", "").toString();

String line2 = map.get("line2").toString();

r.addMotd(line1 + (line2 == null ? "" : "\n" + line2));

} else {

throw new RuntimeException("Unknown motd type: " + motdObj.getClass().getCanonicalName());

}

}

File iconFolder = new File(getDataFolder(), "favicons/");

if(!iconFolder.isDirectory()) iconFolder.mkdirs();

//noinspection ConstantConditions

for(File file : iconFolder.listFiles((dir, name) ->

SUPPORTED_IMAGE_FORMAT.stream().anyMatch(name::endsWith))) {

try {

BufferedImage image = ImageIO.read(file);

r.addServerIcon(new BukkitMotdServerIcon(image));

} catch (IOException e) {

throw new UncheckedIOException("Unable to load " + file.getName(), e);

}

}

return r;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值