當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。