Skip to content

Commit

Permalink
Add vanilla values to all config option comments
Browse files Browse the repository at this point in the history
 * Closes #82
  • Loading branch information
squeek502 committed Apr 25, 2015
1 parent aefbe9e commit eee1f19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
22 changes: 14 additions & 8 deletions src/main/java/iguanaman/hungeroverhaul/config/ConfigOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ public ConfigOption(String category, String name, T defaultValue, T minValue, T
this.defaultValue = defaultValue;
this.blankSlate = blankSlate;
this.comment = comment;
this.minValue = minValue != null ? minValue : getDefaultMinValue(defaultValue);
this.maxValue = maxValue != null ? maxValue : getDefaultMaxValue(defaultValue);
this.minValue = minValue != null ? minValue : getDefaultMinValue();
this.maxValue = maxValue != null ? maxValue : getDefaultMaxValue();
}

public String getComment()
{
String commentSuffix = "vanilla: " + blankSlate;
return comment + " [" + commentSuffix + "]";
}

@SuppressWarnings("unchecked")
private T getDefaultMinValue(T defaultValue)
private T getDefaultMinValue()
{
if (defaultValue instanceof Integer)
return (T) Integer.valueOf(Integer.MIN_VALUE);
Expand All @@ -43,7 +49,7 @@ else if (defaultValue instanceof Double)
}

@SuppressWarnings("unchecked")
private T getDefaultMaxValue(T defaultValue)
private T getDefaultMaxValue()
{
if (defaultValue instanceof Integer)
return (T) Integer.valueOf(Integer.MAX_VALUE);
Expand All @@ -59,15 +65,15 @@ else if (defaultValue instanceof Double)
public T get(Configuration config)
{
if (defaultValue instanceof Boolean)
return (T) Boolean.valueOf(config.getBoolean(name, category, (Boolean) defaultValue, comment));
return (T) Boolean.valueOf(config.getBoolean(name, category, (Boolean) defaultValue, getComment()));
else if (defaultValue instanceof Integer)
return (T) Integer.valueOf(config.getInt(name, category, (Integer) defaultValue, (Integer) minValue, (Integer) maxValue, comment));
return (T) Integer.valueOf(config.getInt(name, category, (Integer) defaultValue, (Integer) minValue, (Integer) maxValue, getComment()));
else if (defaultValue instanceof Float)
return (T) Float.valueOf((float) config.getFloat(name, category, (Float) defaultValue, (Float) minValue, (Float) maxValue, comment));
return (T) Float.valueOf((float) config.getFloat(name, category, (Float) defaultValue, (Float) minValue, (Float) maxValue, getComment()));
else if (defaultValue instanceof Double)
return (T) Double.valueOf(Math.min((Double) maxValue, Math.max((Double) minValue, getProperty(config).getDouble())));
else if (defaultValue instanceof String)
return (T) config.getString(name, category, (String) defaultValue, comment);
return (T) config.getString(name, category, (String) defaultValue, getComment());
else
throw new RuntimeException("Unknown ConfigOption type for '" + category + ":" + name + "': " + defaultValue.getClass().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ public static <T> ConfigOption<T> putOptionInList(ConfigCategory category, Strin
// hunger
public static final ConfigOption<Boolean> constantHungerLossOption = addOption(CATEGORY_HUNGER, "constantHungerLoss", true, false, "You lose hunger (very slowly) at all times");
public static boolean constantHungerLoss;
public static final ConfigOption<Integer> damageOnStarveOption = addOption(CATEGORY_HUNGER, "damageOnStarve", 200, 2, "Amount of damage you take when hunger hits zero (vanilla default 2)");
public static final ConfigOption<Integer> damageOnStarveOption = addOption(CATEGORY_HUNGER, "damageOnStarve", 200, 2, "Amount of damage you take when hunger hits zero");
public static int damageOnStarve;
public static final ConfigOption<Integer> respawnHungerValueOption = addOption(CATEGORY_HUNGER, "respawnHungerValue", 20, 0, null, 20, "hunger value set after respawning for peaceful/easy difficulty (vanilla default is 20)");
public static final ConfigOption<Integer> respawnHungerValueOption = addOption(CATEGORY_HUNGER, "respawnHungerValue", 20, 0, null, 20, "hunger value set after respawning for peaceful/easy difficulty");
public static int respawnHungerValue;
public static final ConfigOption<Integer> respawnHungerDifficultyModifierOption = addOption(CATEGORY_HUNGER, "respawnHungerDifficultyModifier", 4, 0, null, 4, "The amount difficulty modifies the hunger value set after respawning ('difficultyScaling' and 'difficultyScalingRespawnHunger' must be true)");
public static int respawnHungerDifficultyModifier;
Expand All @@ -243,7 +243,7 @@ public static <T> ConfigOption<T> putOptionInList(ConfigCategory category, Strin
public static boolean addLowStatMiningSlowdown;

// health
public static final ConfigOption<Integer> minHungerToHealOption = addOption(CATEGORY_HEALTH, "minHungerToHeal", 7, 0, null, 18, "Minimum hunger level before healing starts (vanilla default is 18)");
public static final ConfigOption<Integer> minHungerToHealOption = addOption(CATEGORY_HEALTH, "minHungerToHeal", 7, 0, null, 18, "Minimum hunger level before healing starts");
public static int minHungerToHeal;
public static final ConfigOption<Boolean> foodRegensHealthOption = addOption(CATEGORY_HEALTH, "foodRegensHealth", false, false, "Eating food regenerates health");
public static boolean foodRegensHealth;
Expand Down

0 comments on commit eee1f19

Please sign in to comment.