Java 类net.minecraftforge.common.ConfigCategory 实例源码

项目:UrbanCraft-CommandForwarder    文件:CommandForwarder.java   
@PreInit
public void preInit(FMLPreInitializationEvent event) {
    logger = Logger.getLogger(ID);
    logger.setParent(FMLLog.getLogger());

    Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    config.load();
    // post_url = config.get(config.CATEGORY_GENERAL, "post_url",
    // "http://localhost/post/",
    // "This is the url of which the mod posts updates to.").value;
    identifier = config.get(config.CATEGORY_GENERAL, "identifier", "commandforwarder", "This string determines the value of the id field in the post request.").value;
    debug = config.get(Configuration.CATEGORY_GENERAL, "debug", false, "Enable debuging?").getBoolean(true);

    ConfigCategory cmdcat = config.getCategory("commands");
    cmdcat.setComment("This is a list of command=url.");
    Map<String, Property> cmdmap = cmdcat.getValues();

    if (cmdmap.isEmpty()) {
        config.get("commands", "example", "http://localhost/post/");
    }
    for (Map.Entry i : cmdmap.entrySet()) {
        String k = (String) i.getKey();
        Property v = (Property) i.getValue();
        Command cmd = new Command(k, v.value);
        this.commands.add(cmd);
    }
    // public Map<String,Property> getValues()

    config.save();

    logger.info("debug: " + debug);
    logger.info("identifier: " + identifier);
    // logger.info("post_url: " + post_url);
}
项目:PlaceholderBlocks    文件:PlaceholderBlocks.java   
@PreInit
public void preInit(FMLPreInitializationEvent event) {
    Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());

    FMLLog.log(Level.FINE, "PlaceholderBlocks loading config");

    try {
        cfg.load();

        ConfigCategory category = cfg.getCategory("Blocks");

        for (Map.Entry<String, Property> entry : category.entrySet()) {
            String key = entry.getKey();
            Property property = entry.getValue();

            if (property.getString().length() == 0) {
                // not set
                continue;
            }

            // parse configuration entry
            AbstractBlock abstractBlock = new AbstractBlock(key, property.getString());

            // add to list keyed by block ID
            List<AbstractBlock> list;
            if (abstractBlocks.containsKey(abstractBlock.id)) {
                list = abstractBlocks.get(abstractBlock.id);
            } else {
                list = new ArrayList<AbstractBlock>();
            }
            list.add(abstractBlock);

            abstractBlocks.put(abstractBlock.id, list);
        }
    } catch (Exception e) {
        FMLLog.log(Level.SEVERE, e, "PlaceholderBlocks had a problem loading it's configuration");
    } finally {
        cfg.save();
    }
}
项目:OreDupeFix    文件:OreDupeFix.java   
@PreInit
public static void preInit(FMLPreInitializationEvent event) {
    oreName2PreferredMod = new HashMap<String, String>();

    Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());

    FMLLog.log(Level.FINE, "OreDupeFix loading config");

    try {
        cfg.load();

        if (cfg.getCategoryNames().size() == 0) {
            loadDefaults(cfg);
        }

        ConfigCategory category = cfg.getCategory("PreferredOres");

        for (Map.Entry<String, Property> entry : category.entrySet()) {
            String name = entry.getKey();
            Property property = entry.getValue();

            if (property.getString().length() == 0) {
                // not set
                continue;
            }

            oreName2PreferredMod.put(name, property.getString());
        }

        shouldDumpOreDict = cfg.get(Configuration.CATEGORY_GENERAL, "dumpOreDict", true).getBoolean(true);
        verbose = cfg.get(Configuration.CATEGORY_GENERAL, "verbose", true).getBoolean(true);

        // TODO: refactor
        replaceCrafting = cfg.get(Configuration.CATEGORY_GENERAL, "replaceCrafting", true).getBoolean(true);
        replaceFurnace = cfg.get(Configuration.CATEGORY_GENERAL, "replaceFurnace", true).getBoolean(true);
        replaceFurnaceInsensitive = cfg.get(Configuration.CATEGORY_GENERAL, "replaceFurnaceInsensitive", true).getBoolean(true);
        replaceDungeonLoot = cfg.get(Configuration.CATEGORY_GENERAL, "replaceDungeonLoot", true).getBoolean(true);
        replaceIC2Compressor = cfg.get(Configuration.CATEGORY_GENERAL, "replaceIC2Compressor", true).getBoolean(true);
        replaceIC2Extractor = cfg.get(Configuration.CATEGORY_GENERAL, "replaceIC2Extractor", true).getBoolean(true);
        replaceIC2Macerator = cfg.get(Configuration.CATEGORY_GENERAL, "replaceIC2Macerator", true).getBoolean(true);
        replaceIC2Scrapbox = cfg.get(Configuration.CATEGORY_GENERAL, "replaceIC2Scrapbox", true).getBoolean(true);
    } catch (Exception e) {
        FMLLog.log(Level.SEVERE, e, "OreDupeFix had a problem loading it's configuration");
    } finally {
        cfg.save();
    }
}
项目:Bubblegum-Mod    文件:ConfigurationHandler.java   
public static void preConfig(File file){
    config = new Configuration(file);

    try{
        config.load();

        IDs.PINK_GUM1 = config.getTerrainBlock(ConfigCategory.getQualifiedName("Dimension Blocks", null), Strings.PG1 + "ID", IDs.PG1_ID_DEFAULT, Strings.COMMENTDIMCONFIG).getInt(IDs.PG1_ID_DEFAULT);
        IDs.RED_GUM2 = config.getTerrainBlock(ConfigCategory.getQualifiedName("Dimension Blocks", null), Strings.RG2 + "ID", IDs.RG2_ID_DEFAULT, Strings.COMMENTDIMCONFIG).getInt(IDs.RG2_ID_DEFAULT);
        IDs.RED_GUM3 = config.getTerrainBlock(ConfigCategory.getQualifiedName("Dimension Blocks", null), Strings.RG3 + "ID", IDs.RG3_ID_DEFAULT, Strings.COMMENTDIMCONFIG).getInt(IDs.RG3_ID_DEFAULT);
        IDs.PINK_GUM2 = config.getBlock(Strings.PG2 + "ID", IDs.PG2_ID_DEFAULT).getInt(IDs.PG2_ID_DEFAULT);
        IDs.RED_GUM1 = config.getBlock(Strings.RG1 + "ID", IDs.RG1_ID_DEFAULT).getInt(IDs.RG1_ID_DEFAULT);
        IDs.PINK_GUM3 = config.getBlock(Strings.PG3 + "ID", IDs.PG3_ID_DEFAULT).getInt(IDs.PG3_ID_DEFAULT);
        IDs.PINK_GUM4 = config.getBlock(Strings.PG4 + "ID", IDs.PG4_ID_DEFAULT).getInt(IDs.PG4_ID_DEFAULT);
        IDs.RED_GUM4 = config.getBlock(Strings.RG4 + "ID", IDs.RG4_ID_DEFAULT).getInt(IDs.RG4_ID_DEFAULT);
        IDs.RAWGUM = config.getBlock(Strings.RAWG + "ID", IDs.RAWGUM_DEFAULT).getInt(IDs.RAWGUM_DEFAULT);
        IDs.BLUE_GUM1 = config.getTerrainBlock(ConfigCategory.getQualifiedName("Dimension Blocks", null), Strings.BG1 + "ID", IDs.BG1_ID_DEFAULT, Strings.COMMENTDIMCONFIG).getInt(IDs.BG1_ID_DEFAULT);
        IDs.BLUE_GUM2 = config.getBlock(Strings.BG2 + "ID", IDs.BG2_ID_DEFAULT).getInt(IDs.BG2_ID_DEFAULT);
        IDs.BGMPORTAL = config.getBlock(Strings.BGMP + "ID", IDs.BGMPORTAL_DEFAULT_ID).getInt(IDs.BGMPORTAL_DEFAULT_ID);
        IDs.BGMFIRE = config.getBlock(Strings.BGMF + "ID", IDs.BGMFIRE_DEFAULT_ID).getInt(IDs.BGMFIRE_DEFAULT_ID);
        IDs.BLACK_GUM1 = config.getTerrainBlock(ConfigCategory.getQualifiedName("Dimension Blocks", null), Strings.BG + "ID", IDs.BG_ID_DEFAULT, Strings.COMMENTDIMCONFIG).getInt(IDs.BG_ID_DEFAULT);

        IDs.PGPLAINS = config.get(ConfigCategory.getQualifiedName("BiomeID", null), Strings.PGP + "ID", IDs.PGPLAINS_DEFAULT_ID).getInt(IDs.PGPLAINS_DEFAULT_ID);
        biomeBubblegumGen = config.get("Biome To Generate", "BiomeStrawberryBubblegum", true).getBoolean(false);
        addToDefault = config.get("Biome Settings", "Add Biomes To Overworld", false).getBoolean(false);
        IDs.RGFOREST = config.get(ConfigCategory.getQualifiedName("BiomeID", null), Strings.RGF + "ID", IDs.RGFOREST_DEFAULT_ID).getInt(IDs.RGFOREST_DEFAULT_ID);
        biomeBubblegumGen2 = config.get("Biome To Generate", "BiomeGreenAppleBubblegumForest", true).getBoolean(false);
        addToDefault = config.get("Biome Settings", "Add Biomes To Overworld", false).getBoolean(false);

        IDs.BUBBLE_IGNITOR = config.getItem(Strings.BGI  + "ID", IDs.BUBBLE_IGNITOR_DEFAULT_ID).getInt(IDs.BUBBLE_IGNITOR_DEFAULT_ID);
        IDs.PORTAL_PLACER = config.getItem(Strings.PP  + "ID", IDs.PORTAL_PLACER_DEFAULT_ID).getInt(IDs.PORTAL_PLACER_DEFAULT_ID);
        IDs.MGC = config.getItem(Strings.MGC  + " ID", IDs.MGC_DEFAULT).getInt(IDs.MGC_DEFAULT);
        IDs.BGC = config.getItem(Strings.BGC  + " ID", IDs.BGC_DEFAULT).getInt(IDs.BGC_DEFAULT);
        IDs.YGC = config.getItem(Strings.YGC  + " ID", IDs.YGC_DEFAULT).getInt(IDs.YGC_DEFAULT);
        IDs.RAWGUMCHUNK = config.getItem(Strings.RawBG  + " ID", IDs.RAWGUMCHUNK_DEFAULT).getInt(IDs.RAWGUMCHUNK_DEFAULT);
    }
    catch(Exception e){
        FMLLog.log(Level.SEVERE, e, Reference.MOD_ID + "Has a problem loading the config file");
    }
    finally{
        config.save();
    }
}