Java Code Examples for net.minecraftforge.common.config.Configuration#get()

The following examples show how to use net.minecraftforge.common.config.Configuration#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigManager.java    From GardenCollection with MIT License 6 votes vote down vote up
public ConfigManager (File file) {
    config = new Configuration(file);

    Property propEnableCompostBonemeal = config.get(Configuration.CATEGORY_GENERAL, "enableCompostBonemeal", true);
    propEnableCompostBonemeal.comment = "Allows compost trigger plant growth like bonemeal.";
    enableCompostBonemeal = propEnableCompostBonemeal.getBoolean();

    Property propCompostBonemealStrength = config.get(Configuration.CATEGORY_GENERAL, "compostBonemealStrength", 0.5);
    propCompostBonemealStrength.comment = "The probability that compost will succeed when used as bonemeal relative to bonemeal.";
    compostBonemealStrength = propCompostBonemealStrength.getDouble();

    Property propEnableTilledSoilGrowthBonus = config.get(Configuration.CATEGORY_GENERAL, "enableTilledSoilGrowthBonus", true).setRequiresMcRestart(true);
    propEnableTilledSoilGrowthBonus.comment = "Allows tilled garden soil to advance crop growth more quickly.  Enables random ticks.";
    enableTilledSoilGrowthBonus = propEnableTilledSoilGrowthBonus.getBoolean();

    config.save();
}
 
Example 2
Source File: ForgeMetrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ForgeMetrics(final String modName, final String modVersion) throws IOException {
    if (modName == null || modVersion == null) {
        throw new IllegalArgumentException("modName and modVersion cannot be null");
    }

    this.modName = modName;
    this.modVersion = modVersion;

    // load the config
    configurationFile = getConfigFile();
    configuration = new Configuration(configurationFile);

    // Get values, and add some defaults, if needed
    configuration.get(Configuration.CATEGORY_GENERAL, "opt-out", false, "Set to true to disable all reporting");
    guid = configuration.get(Configuration.CATEGORY_GENERAL, "guid", UUID.randomUUID().toString(), "Server unique ID").getString();
    debug = configuration.get(Configuration.CATEGORY_GENERAL, "debug", false, "Set to true for verbose debug").getBoolean(false);
    configuration.save();
}
 
Example 3
Source File: ForgeMetrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ForgeMetrics(final String modName, final String modVersion) throws IOException {
    if (modName == null || modVersion == null) {
        throw new IllegalArgumentException("modName and modVersion cannot be null");
    }

    this.modName = modName;
    this.modVersion = modVersion;

    // load the config
    configurationFile = getConfigFile();
    configuration = new Configuration(configurationFile);

    // Get values, and add some defaults, if needed
    configuration.get(Configuration.CATEGORY_GENERAL, "opt-out", false, "Set to true to disable all reporting");
    guid = configuration.get(Configuration.CATEGORY_GENERAL, "guid", UUID.randomUUID().toString(), "Server unique ID").getString();
    debug = configuration.get(Configuration.CATEGORY_GENERAL, "debug", false, "Set to true for verbose debug").getBoolean(false);
    configuration.save();
}
 
Example 4
Source File: ForgeMetrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ForgeMetrics(final String modName, final String modVersion) throws IOException {
    if (modName == null || modVersion == null) {
        throw new IllegalArgumentException("modName and modVersion cannot be null");
    }

    this.modName = modName;
    this.modVersion = modVersion;

    // load the config
    configurationFile = getConfigFile();
    configuration = new Configuration(configurationFile);

    // Get values, and add some defaults, if needed
    configuration.get(Configuration.CATEGORY_GENERAL, "opt-out", false, "Set to true to disable all reporting");
    guid = configuration.get(Configuration.CATEGORY_GENERAL, "guid", UUID.randomUUID().toString(), "Server unique ID").getString();
    debug = configuration.get(Configuration.CATEGORY_GENERAL, "debug", false, "Set to true for verbose debug").getBoolean(false);
    configuration.save();
}
 
Example 5
Source File: ForgeMetrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ForgeMetrics(final String modName, final String modVersion) throws IOException {
    if (modName == null || modVersion == null) {
        throw new IllegalArgumentException("modName and modVersion cannot be null");
    }

    this.modName = modName;
    this.modVersion = modVersion;

    // load the config
    configurationFile = getConfigFile();
    configuration = new Configuration(configurationFile);

    // Get values, and add some defaults, if needed
    configuration.get(Configuration.CATEGORY_GENERAL, "opt-out", false, "Set to true to disable all reporting");
    guid = configuration.get(Configuration.CATEGORY_GENERAL, "guid", UUID.randomUUID().toString(), "Server unique ID").getString();
    debug = configuration.get(Configuration.CATEGORY_GENERAL, "debug", false, "Set to true for verbose debug").getBoolean(false);
    configuration.save();
}
 
Example 6
Source File: ForgeMetrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ForgeMetrics(final String modName, final String modVersion) throws IOException {
    if (modName == null || modVersion == null) {
        throw new IllegalArgumentException("modName and modVersion cannot be null");
    }

    this.modName = modName;
    this.modVersion = modVersion;

    // load the config
    configurationFile = getConfigFile();
    configuration = new Configuration(configurationFile);

    // Get values, and add some defaults, if needed
    configuration.get(Configuration.CATEGORY_GENERAL, "opt-out", false, "Set to true to disable all reporting");
    guid = configuration.get(Configuration.CATEGORY_GENERAL, "guid", UUID.randomUUID().toString(), "Server unique ID").getString();
    debug = configuration.get(Configuration.CATEGORY_GENERAL, "debug", false, "Set to true for verbose debug").getBoolean(false);
    configuration.save();
}
 
Example 7
Source File: TFCOptions.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
public static double getDoubleFor(Configuration config,String heading, String item, double value, String comment)
{
	if (config == null)
		return value;
	try
	{
		Property prop = config.get(heading, item, value);
		prop.setComment(comment);
		return prop.getDouble(value);
	}
	catch (Exception e)
	{
		System.out.println("[TFC2] Error while trying to add Double, config wasn't loaded properly!");
	}
	return value;
}
 
Example 8
Source File: TFCOptions.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
public static int getIntFor(Configuration config,String heading, String item, int value, String comment)
{
	if (config == null)
		return value;
	try
	{
		Property prop = config.get(heading, item, value);
		prop.setComment(comment);
		return prop.getInt(value);
	}
	catch (Exception e)
	{
		System.out.println("[TFC2] Error while trying to add Integer, config wasn't loaded properly!");
	}
	return value;
}
 
Example 9
Source File: TFCOptions.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static boolean getBooleanFor(Configuration config,String heading, String item, boolean value)
{
	if (config == null)
		return value;
	try
	{
		Property prop = config.get(heading, item, value);
		return prop.getBoolean(value);
	}
	catch (Exception e)
	{
		System.out.println("[TFC2] Error while trying to add Integer, config wasn't loaded properly!");
	}
	return value;
}
 
Example 10
Source File: ConfigManager.java    From GardenCollection with MIT License 5 votes vote down vote up
public ConfigManager (File file) {
    config = new Configuration(file);

    Property propStrangePlantDrops = config.get(Configuration.CATEGORY_GENERAL, "strangePlantDrops", new String[0]);
    propStrangePlantDrops.comment = "A list of zero or more item IDs.  Breaking the plant will drop an item picked at random from the list.  Ex: minecraft:coal:1";

    Property propStrangePlantDropChance = config.get(Configuration.CATEGORY_GENERAL, "strangePlantDropChance", 1.0);
    propStrangePlantDropChance.comment = "The probability from 0.0 - 1.0 that breaking a strange plant will drop its contents.";
    strangePlantDropChance = propStrangePlantDropChance.getDouble();

    Property propStrangePlantDropMin = config.get(Configuration.CATEGORY_GENERAL, "strangePlantDropMin", 1);
    propStrangePlantDropMin.comment = "The minimum number of items dropped when breaking a strange plant.";
    strangePlantDropMin = propStrangePlantDropMin.getInt();

    Property propStrangePlantDropMax = config.get(Configuration.CATEGORY_GENERAL, "strangePlantDropMax", 1);
    propStrangePlantDropMax.comment = "The maximum number of items dropped when breaking a strange plant.";
    strangePlantDropMax = propStrangePlantDropMax.getInt();

    Property propCompostGrowsOrnamentalTrees = config.get(Configuration.CATEGORY_GENERAL, "compostGrowsOrnamentalTrees", true);
    propCompostGrowsOrnamentalTrees.comment = "Using compost on saplings will grow ornamental (miniature) trees instead of normal trees.";
    compostGrowsOrnamentalTrees = propCompostGrowsOrnamentalTrees.getBoolean();

    Property propGenerateCandelilla = config.get(Configuration.CATEGORY_GENERAL, "generateCandelilla", true);
    propGenerateCandelilla.comment = "Generates clusters of candelilla shrub in warm, sandy biomes.";
    generateCandelilla = propGenerateCandelilla.getBoolean();

    config.save();
}
 
Example 11
Source File: TFCOptions.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static String getStringFor(Configuration config, String heading, String item, String value, String comment)
{
	if (config == null)
		return value;
	try
	{
		Property prop = config.get(heading, item, value);
		prop.setComment(comment);
		return prop.getString();
	} catch (Exception e)
	{
		System.out.println("[TFC2] Error while trying to add String, config wasn't loaded properly!");
	}
	return value;
}
 
Example 12
Source File: TFCOptions.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static String getStringFor(Configuration config, String heading, String item, String value)
{
	if (config == null)
		return value;
	try
	{
		Property prop = config.get(heading, item, value);
		return prop.getString();
	} catch (Exception e)
	{
		System.out.println("[TFC2] Error while trying to add String, config wasn't loaded properly!");
	}
	return value;
}
 
Example 13
Source File: TFCOptions.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static int getIntFor(Configuration config, String heading, String item, int value)
{
	if (config == null)
		return value;
	try
	{
		Property prop = config.get(heading, item, value);
		return prop.getInt(value);
	}
	catch (Exception e)
	{
		System.out.println("[TFC2] Error while trying to add Integer, config wasn't loaded properly!");
	}
	return value;
}
 
Example 14
Source File: ModConfigs.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static void loadConfigs(Configuration config) {
	Property off = config.get(CATAGORY_SERVER, "disabled", disabled);
	off.comment = "On the client this disables other world renders entirely, preventing world requests. On the server this disables sending world info to all clients.";
	disabled = off.getBoolean(disabled);

	Property d = config.get(CATAGORY_SERVER, "datarate", dataRate);
	d.comment = "The number of bytes to send per tick before the server cuts off sending. Only applies to other-world chunks. Default: " + dataRate;
	dataRate = d.getInt(dataRate);

	if (dataRate <= 0) disabled = true;

	if (config.hasChanged()) config.save();
}
 
Example 15
Source File: SettingSingleValue.java    From WearableBackpacks with MIT License 4 votes vote down vote up
/** Returns the Property object from the Forge Configuration. */
protected Property getPropertyFromConfig(Configuration config) {
	return config.get(getCategory(), getName(),
		String.valueOf(getDefault()), getComment(), getPropertyType());
}
 
Example 16
Source File: Settings.java    From MediaMod with GNU General Public License v3.0 4 votes vote down vote up
private static void updateConfig(Configuration configuration, boolean load) {
    Property enabledProperty = configuration.get("General", "enabled", true);
    Property showPlayerProperty = configuration.get("General", "showPlayer", true);
    Property modernPlayerProperty = configuration.get("Player", "modernPlayer", true);
    Property albumArtProperty = configuration.get("Player", "showAlbumArt", true);
    Property autoColorProperty = configuration.get("Player", "automaticColorSelection", true);
    Property saveSpotifyTokenProperty = configuration.get("General", "saveSpotifyToken", true);
    Property announceTracksProperty = configuration.get("Player", "announceTracks", true);
    Property playerXProperty = configuration.get("Player", "playerX", 5.0);
    Property playerYProperty = configuration.get("Player", "playerY", 5.0);
    Property playerZoomProperty = configuration.get("Player", "playerZoom", 1.0);
    Property browserExtProperty = configuration.get("Player", "useBrowserExtension", true);
    Property progressStyleProperty = configuration.get("Player", "progressStyle", ProgressStyle.BAR_AND_NUMBERS_NEW.name());
    Property refreshTokenProperty = configuration.get("Spotify", "refreshToken", "");

    if (load) SAVE_SPOTIFY_TOKEN = saveSpotifyTokenProperty.getBoolean();
    else saveSpotifyTokenProperty.setValue(SAVE_SPOTIFY_TOKEN);

    if (load) REFRESH_TOKEN = refreshTokenProperty.getString();
    else {
        if(SAVE_SPOTIFY_TOKEN) {
            refreshTokenProperty.setValue(REFRESH_TOKEN);
        } else {
            refreshTokenProperty.setValue("");
        }
    }

    if (load) ENABLED = enabledProperty.getBoolean();
    else enabledProperty.setValue(ENABLED);

    if (load) ANNOUNCE_TRACKS = announceTracksProperty.getBoolean();
    else announceTracksProperty.setValue(ANNOUNCE_TRACKS);

    if (load) PROGRESS_STYLE = ProgressStyle.valueOf(progressStyleProperty.getString());
    else progressStyleProperty.setValue(PROGRESS_STYLE.name());

    if (load) SHOW_PLAYER = showPlayerProperty.getBoolean();
    else showPlayerProperty.setValue(SHOW_PLAYER);

    if (load) MODERN_PLAYER_STYLE = modernPlayerProperty.getBoolean();
    else modernPlayerProperty.setValue(MODERN_PLAYER_STYLE);

    if (load) SHOW_ALBUM_ART = albumArtProperty.getBoolean();
    else albumArtProperty.setValue(SHOW_ALBUM_ART);

    if (load) AUTO_COLOR_SELECTION = autoColorProperty.getBoolean();
    else autoColorProperty.setValue(AUTO_COLOR_SELECTION);

    if (load) PLAYER_X = playerXProperty.getDouble();
    else playerXProperty.setValue(PLAYER_X);

    if (load) PLAYER_Y = playerYProperty.getDouble();
    else playerYProperty.setValue(PLAYER_Y);

    if (load) PLAYER_ZOOM = playerZoomProperty.getDouble();
    else playerZoomProperty.setValue(PLAYER_ZOOM);

    if (load) EXTENSION_ENABLED = browserExtProperty.getBoolean();
    else browserExtProperty.setValue(EXTENSION_ENABLED);
}
 
Example 17
Source File: OpenPeripheralIntegration.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
private static boolean checkConfig(Configuration config, String value) {
	final Property property = config.get(CATEGORY_MODULES, value, true);
	property.setRequiresMcRestart(true);
	return property.getBoolean();
}
 
Example 18
Source File: ConfigPropertyMeta.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
protected Property getProperty(Configuration configFile, Type expectedType, Object defaultValue) {
	final String[] defaultStrings = convertToStringArray(defaultValue);
	return configFile.get(category, name, defaultStrings, comment, expectedType);
}
 
Example 19
Source File: SettingPercent.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@Override
protected Property getPropertyFromConfig(Configuration config) {
	return config.get(getCategory(), getName(),
		String.valueOf(getDefault()), getComment(), Property.Type.STRING);
}
 
Example 20
Source File: ConfigPropertyMeta.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
protected Property getProperty(Configuration configFile, Type expectedType, Object defaultValue) {
	final String defaultString = defaultValue.toString();
	return configFile.get(category, name, defaultString, comment, expectedType);
}