当前位置: 首页>>代码示例>>Java>>正文


Java FileConfiguration.getList方法代码示例

本文整理汇总了Java中org.bukkit.configuration.file.FileConfiguration.getList方法的典型用法代码示例。如果您正苦于以下问题:Java FileConfiguration.getList方法的具体用法?Java FileConfiguration.getList怎么用?Java FileConfiguration.getList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.configuration.file.FileConfiguration的用法示例。


在下文中一共展示了FileConfiguration.getList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCrafts

import org.bukkit.configuration.file.FileConfiguration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public ArrayList<CraftArray> getCrafts(){
   	ArrayList<CraftArray> craftlist = new ArrayList<CraftArray>();
   	try {
    	File craftfile = new File(plugin.getDataFolder(), "crafts.yml");
		craftfile.createNewFile();
		FileConfiguration craftconfig = YamlConfiguration.loadConfiguration(craftfile);
		if(craftconfig.isSet("Crafts")) {
			for(String craftpath : craftconfig.getConfigurationSection("Crafts").getKeys(false)) {
				craftpath = "Crafts." + craftpath;
				ArrayList<ItemStack> config_craft = (ArrayList<ItemStack>) craftconfig.getList(craftpath + ".craft");
				ArrayList<ItemStack> config_resultitems = (ArrayList<ItemStack>) craftconfig.getList(craftpath + ".result.items");
				ArrayList<Integer> config_resultprobs = (ArrayList<Integer>) craftconfig.getIntegerList(craftpath + ".result.probs");
				HashMap<ItemStack,Integer> config_result = new HashMap<ItemStack, Integer>();
				for(ItemStack resultitem : config_resultitems) {
					config_result.put(resultitem, config_resultprobs.get(config_resultitems.indexOf(resultitem)));
				}
				ArrayList<String> config_cmds = (ArrayList<String>) craftconfig.getStringList(craftpath + ".cmds");
				boolean config_redstonepower = craftconfig.getBoolean(craftpath + ".redstonepower");
				int config_experience = craftconfig.getInt(craftpath + ".experience");
				CraftArray specraft = new CraftArray(config_craft, config_result, config_cmds, config_redstonepower, config_experience);
				craftlist.add(specraft);
			}
			return craftlist;
		} else {
			return craftlist;
		}
   	} catch (Exception e) {
   		e.printStackTrace();
   		return craftlist;
   	}
   }
 
开发者ID:Slaymd,项目名称:CaulCrafting,代码行数:33,代码来源:CraftStorage.java

示例2: loadConfig

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<String, Object> map = (Map<String, Object>) 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;
}
 
开发者ID:andylizi,项目名称:ColorMOTD,代码行数:51,代码来源:BukkitMain.java


注:本文中的org.bukkit.configuration.file.FileConfiguration.getList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。