Fix API incompatibilities. Should mean mods will work with new config changes.

This commit is contained in:
cpw 2014-06-25 20:47:33 -04:00
parent bcda92e941
commit 6998e76d3f
2 changed files with 150 additions and 153 deletions

View file

@ -63,9 +63,9 @@ public class ConfigCategory implements Map<String, Property>
if (obj instanceof ConfigCategory)
{
ConfigCategory cat = (ConfigCategory)obj;
return name.equals(cat.name) && children.equals(cat.children);
return name.equals(cat.name) && children.equals(cat.children);
}
return false;
}
@ -107,30 +107,30 @@ public class ConfigCategory implements Map<String, Property>
for (String key : this.propertyOrder)
if (properties.containsKey(key))
set.add(properties.get(key));
return ImmutableList.copyOf(set);
}
else
return ImmutableList.copyOf(properties.values());
}
public ConfigCategory setConfigEntryClass(Class<? extends IConfigEntry> clazz)
{
this.customEntryClass = clazz;
return this;
}
public Class<? extends IConfigEntry> getConfigEntryClass()
{
return this.customEntryClass;
}
public ConfigCategory setLanguageKey(String languagekey)
{
this.languagekey = languagekey;
return this;
}
public String getLanguagekey()
{
if (this.languagekey != null)
@ -138,11 +138,10 @@ public class ConfigCategory implements Map<String, Property>
else
return getQualifiedName();
}
public ConfigCategory setComment(String comment)
public void setComment(String comment)
{
this.comment = comment;
return this;
}
public String getComment()
@ -152,7 +151,7 @@ public class ConfigCategory implements Map<String, Property>
/**
* Sets the flag for whether or not this category can be edited while a world is running. Care should be taken to ensure
* that only properties that are truly dynamic can be changed from the in-game options menu. Only set this flag to
* that only properties that are truly dynamic can be changed from the in-game options menu. Only set this flag to
* true if all child properties/categories are unable to be modified while a world is running.
*/
public ConfigCategory setRequiresWorldRestart(boolean requiresWorldRestart)
@ -169,7 +168,7 @@ public class ConfigCategory implements Map<String, Property>
{
return this.requiresWorldRestart;
}
/**
* Sets whether or not this ConfigCategory should be allowed to show on config GUIs.
* Defaults to true.
@ -179,7 +178,7 @@ public class ConfigCategory implements Map<String, Property>
this.showInGui = showInGui;
return this;
}
/**
* Gets whether or not this ConfigCategory should be allowed to show on config GUIs.
* Defaults to true unless set to false.
@ -188,7 +187,7 @@ public class ConfigCategory implements Map<String, Property>
{
return showInGui;
}
/**
* Sets whether or not this ConfigCategory requires Minecraft to be restarted when changed.
* Defaults to false. Only set this flag to true if ALL child properties/categories require
@ -200,7 +199,7 @@ public class ConfigCategory implements Map<String, Property>
this.requiresMcRestart = this.requiresWorldRestart = requiresMcRestart;
return this;
}
/**
* Gets whether or not this ConfigCategory requires Minecraft to be restarted when changed.
* Defaults to false unless set to true.
@ -209,7 +208,7 @@ public class ConfigCategory implements Map<String, Property>
{
return this.requiresMcRestart;
}
public ConfigCategory setPropertyOrder(List<String> propertyOrder)
{
this.propertyOrder = propertyOrder;
@ -218,7 +217,7 @@ public class ConfigCategory implements Map<String, Property>
propertyOrder.add(s);
return this;
}
public List<String> getPropertyOrder()
{
if (this.propertyOrder != null)
@ -226,7 +225,7 @@ public class ConfigCategory implements Map<String, Property>
else
return ImmutableList.copyOf(properties.keySet());
}
public boolean containsKey(String key)
{
return properties.containsKey(key);
@ -268,7 +267,7 @@ public class ConfigCategory implements Map<String, Property>
{
write(out, pad0, "# ", line);
}
write(out, pad0, COMMENT_SEPARATOR, NEW_LINE);
}
@ -309,7 +308,7 @@ public class ConfigCategory implements Map<String, Property>
if (prop.isList())
{
char type = prop.getType().getID();
write(out, pad1, String.valueOf(type), ":", propName, " <");
for (String line : prop.getStringList())
@ -332,7 +331,7 @@ public class ConfigCategory implements Map<String, Property>
if (children.size() > 0)
out.newLine();
for (ConfigCategory child : children)
{
child.write(out, indent + 1);
@ -413,14 +412,13 @@ public class ConfigCategory implements Map<String, Property>
}
public Set<ConfigCategory> getChildren(){ return ImmutableSet.copyOf(children); }
public ConfigCategory removeChild(ConfigCategory child)
public void removeChild(ConfigCategory child)
{
if (children.contains(child))
{
children.remove(child);
changed = true;
}
return this;
}
}

View file

@ -22,7 +22,7 @@ public class Property
DOUBLE,
COLOR,
MOD_ID;
public static Type tryParse(char id)
{
for (int x = 0; x < values().length; x++)
@ -52,10 +52,10 @@ public class Property
private String langKey;
private String minValue;
private String maxValue;
private Class<? extends IConfigEntry> configEntryClass = null;
private Class<? extends IArrayEntry> arrayEntryClass = null;
private boolean requiresWorldRestart = false;
private boolean showInGui = true;
private boolean requiresMcRestart = false;
@ -66,7 +66,7 @@ public class Property
private int maxListLength = -1;
private final Type type;
private boolean changed = false;
public Property(String name, String value, Type type)
{
this(name, value, type, false, new String[0], name);
@ -76,27 +76,27 @@ public class Property
{
this(name, value, type, read, new String[0], name);
}
public Property(String name, String value, Type type, String[] validValues)
{
this(name, value, type, false, validValues, name);
}
public Property(String name, String value, Type type, String langKey)
{
this(name, value, type, false, new String[0], langKey);
}
public Property(String name, String value, Type type, boolean read, String langKey)
{
this(name, value, type, read, new String[0], langKey);
}
public Property(String name, String value, Type type, String[] validValues, String langKey)
{
this(name, value, type, false, validValues, langKey);
}
Property(String name, String value, Type type, boolean read, String[] validValues, String langKey)
{
setName(name);
@ -125,17 +125,17 @@ public class Property
{
this(name, values, type, read, new String[0], name);
}
public Property(String name, String[] values, Type type, String langKey)
{
this(name, values, type, false, langKey);
}
Property(String name, String[] values, Type type, boolean read, String langKey)
{
this(name, values, type, read, new String[0], langKey);
}
Property(String name, String[] values, Type type, boolean read, String[] validValues, String langKey)
{
setName(name);
@ -160,7 +160,7 @@ public class Property
/**
* Returns whether or not this Property is defaulted.
*
*
* @return true if the current value(s) is(are) deeply equal to the default value(s)
*/
public boolean isDefault()
@ -172,13 +172,13 @@ public class Property
for (int i = 0; i < values.length; i++)
if (Boolean.parseBoolean(values[i]) != Boolean.parseBoolean(defaultValues[i]))
return false;
return true;
}
else
return false;
}
if (this.isIntList())
{
if (values.length == defaultValues.length)
@ -186,13 +186,13 @@ public class Property
for (int i = 0; i < values.length; i++)
if (Integer.parseInt(values[i]) != Integer.parseInt(defaultValues[i]))
return false;
return true;
}
else
return false;
}
if (this.isDoubleList())
{
if (values.length == defaultValues.length)
@ -200,13 +200,13 @@ public class Property
for (int i = 0; i < values.length; i++)
if (Double.parseDouble(values[i]) != Double.parseDouble(defaultValues[i]))
return false;
return true;
}
else
return false;
}
if (this.isList())
{
if (values.length == defaultValues.length)
@ -214,25 +214,25 @@ public class Property
for (int i = 0; i < values.length; i++)
if (!values[i].equals(defaultValues[i]))
return false;
return true;
}
else
return false;
}
if (this.type == Type.BOOLEAN && this.isBooleanValue())
return Boolean.parseBoolean(value) == Boolean.parseBoolean(defaultValue);
if (this.type == Type.INTEGER && this.isIntValue())
return Integer.parseInt(value) == Integer.parseInt(defaultValue);
if (this.type == Type.DOUBLE && this.isDoubleValue())
return Double.parseDouble(value) == Double.parseDouble(defaultValue);
return value.equals(defaultValue);
}
/**
* Sets the current value(s) of this Property to the default value(s).
*/
@ -242,27 +242,27 @@ public class Property
this.values = Arrays.copyOf(this.defaultValues, this.defaultValues.length);
return this;
}
/**
* Gets the raw String default value of this Property. Check for isList() == false first.
*
*
* @return the default value String
*/
public String getDefault()
{
return defaultValue;
}
/**
* Gets the raw String[] default values of this Property. Check for isList() == true first.
*
*
* @return the default values String[]
*/
public String[] getDefaults()
{
return Arrays.copyOf(this.defaultValues, this.defaultValues.length);
}
/**
* Sets the flag for whether or not this Property can be edited while a world is running. Care should be taken to ensure
* that only properties that are truly dynamic can be changed from the in-game options menu. When set to false the Property will be
@ -274,17 +274,17 @@ public class Property
this.requiresWorldRestart = requiresWorldRestart;
return this;
}
/**
* Returns whether or not this Property is able to be edited while a world is running using the in-game Mod Options screen
* as well as the Mods list screen, or only from the Mods list screen. Setting this flag to true will disable editing of
* as well as the Mods list screen, or only from the Mods list screen. Setting this flag to true will disable editing of
* this property while a world is running.
*/
public boolean requiresWorldRestart()
{
return this.requiresWorldRestart;
}
/**
* Sets whether or not this Property should be allowed to show on config GUIs.
* Defaults to true.
@ -294,7 +294,7 @@ public class Property
this.showInGui = showInGui;
return this;
}
/**
* Gets whether or not this Property should be allowed to show on config GUIs.
* Defaults to true unless set to false.
@ -303,10 +303,10 @@ public class Property
{
return showInGui;
}
/**
* Sets whether or not this Property requires Minecraft to be restarted when changed.
* Defaults to false. Setting this flag to true will also disable editing of
* Defaults to false. Setting this flag to true will also disable editing of
* this property while a world is running.
*/
public Property setRequiresMcRestart(boolean requiresMcRestart)
@ -314,7 +314,7 @@ public class Property
this.requiresMcRestart = this.requiresWorldRestart = requiresMcRestart;
return this;
}
/**
* Gets whether or not this Property requires Minecraft to be restarted when changed.
* Defaults to false unless set to true.
@ -323,7 +323,7 @@ public class Property
{
return this.requiresMcRestart;
}
/**
* Sets the maximum length of this list/array Property. Only important if isList() == true. If the current values array or default
* values array is longer than the new maximum it will be resized. If calling both this method and setIsListLengthFixed(true), this
@ -337,14 +337,14 @@ public class Property
if (values != null && values.length != maxListLength)
if (this.isListLengthFixed || values.length > maxListLength)
values = Arrays.copyOf(values, maxListLength);
if (defaultValues != null && defaultValues.length != maxListLength)
if (this.isListLengthFixed || defaultValues.length > maxListLength)
defaultValues = Arrays.copyOf(defaultValues, maxListLength);
}
return this;
}
/**
* Gets the maximum length of this list/array Property. Only important if isList() == true.
*/
@ -352,7 +352,7 @@ public class Property
{
return this.maxListLength;
}
/**
* Sets the flag for whether this list/array Property has a fixed length. Only important if isList() == true. If calling both this
* method and setMaxListLength(), this method should be called first (but is not required).
@ -362,7 +362,7 @@ public class Property
this.isListLengthFixed = isListLengthFixed;
return this;
}
/**
* Returns whether or not this list/array has a fixed length. Only important if isList() == true.
*/
@ -370,7 +370,7 @@ public class Property
{
return this.isListLengthFixed;
}
/**
* Sets a custom IConfigEntry class that should be used in place of the standard entry class for this Property type. This class
* MUST provide a constructor with the following parameter types: {@code GuiConfig} (the owning GuiConfig screen will be provided),
@ -382,24 +382,24 @@ public class Property
this.configEntryClass = clazz;
return this;
}
/**
* Gets the custom IConfigEntry class that should be used in place of the standard entry class for this Property type, or null if
* none has been set.
*
*
* @return a class that implements IConfigEntry
*/
public Class<? extends IConfigEntry> getConfigEntryClass()
{
return this.configEntryClass;
}
/**
* Sets a custom IGuiEditListEntry class that should be used in place of the standard entry class for this Property type. This class
* MUST provide a constructor with the following parameter types: {@code GuiEditList} (the owning GuiEditList screen will be provided),
* {@code GuiPropertyList} (the parent GuiPropertyList will be provided), {@code IConfigProperty} (the IConfigProperty for this Property
* will be provided).
*
*
* @param clazz a class that implements IConfigEntry
*/
public Property setArrayEntryClass(Class<? extends IArrayEntry> clazz)
@ -407,21 +407,21 @@ public class Property
this.arrayEntryClass = clazz;
return this;
}
/**
* Gets the custom IArrayEntry class that should be used in place of the standard entry class for this Property type, or null if
* none has been set.
*
*
* @return a class that implements IArrayEntry
*/
public Class<? extends IArrayEntry> getArrayEntryClass()
{
return this.arrayEntryClass;
}
/**
* Sets a regex Pattern object used to validate user input for formatted String or String[] properties.
*
*
* @param validationPattern
*/
public Property setValidationPattern(Pattern validationPattern)
@ -429,21 +429,21 @@ public class Property
this.validationPattern = validationPattern;
return this;
}
/**
* Gets the Pattern object used to validate user input for this Property.
*
*
* @return the user input validation Pattern object, or null if none is set
*/
public Pattern getValidationPattern()
{
return this.validationPattern;
}
/**
* Sets the localization language key for this Property so that the config GUI screens are nice and pretty <3. The string languageKey +
* ".tooltip" is used for tooltips when a user hovers the mouse over a GUI property label.
*
*
* @param langKey a string language key such as myawesomemod.config.myPropName
*/
public Property setLanguageKey(String langKey)
@ -451,20 +451,20 @@ public class Property
this.langKey = langKey;
return this;
}
/**
* Gets the language key string for this Property.
*
*
* @return the language key
*/
public String getLanguageKey()
{
return this.langKey;
}
/**
* Sets the default string value of this Property.
*
*
* @param defaultValue a String value
*/
public Property setDefaultValue(String defaultValue)
@ -472,10 +472,10 @@ public class Property
this.defaultValue = defaultValue;
return this;
}
/**
* Sets the default String[] values of this Property.
*
*
* @param defaultValues an array of String values
*/
public Property setDefaultValues(String[] defaultValues)
@ -487,10 +487,10 @@ public class Property
this.defaultValues = Arrays.copyOf(defaultValues, defaultValues.length);
return this;
}
/**
* Sets the default int value of this Property.
*
*
* @param defaultValue an int value
*/
public Property setDefaultValue(int defaultValue)
@ -498,10 +498,10 @@ public class Property
setDefaultValue(Integer.toString(defaultValue));
return this;
}
/**
* Sets the default int[] values of this Property.
*
*
* @param defaultValues an array of int values
*/
public Property setDefaultValues(int[] defaultValues)
@ -509,14 +509,14 @@ public class Property
String[] temp = new String[defaultValues.length];
for (int i = 0; i < defaultValues.length; i++)
temp[i] = Integer.toString(defaultValues[i]);
setDefaultValues(temp);
return this;
}
/**
* Sets the default double value of this Property.
*
*
* @param defaultValue a double value
*/
public Property setDefaultValue(double defaultValue)
@ -524,10 +524,10 @@ public class Property
setDefaultValue(Double.toString(defaultValue));
return this;
}
/**
* Sets the default double[] values of this Property
*
*
* @param defaultValues an array of double values
*/
public Property setDefaultValues(double[] defaultValues)
@ -535,14 +535,14 @@ public class Property
String[] temp = new String[defaultValues.length];
for (int i = 0; i < defaultValues.length; i++)
temp[i] = Double.toString(defaultValues[i]);
setDefaultValues(temp);
return this;
}
/**
* Sets the default boolean value of this Property.
*
*
* @param defaultValue a boolean value
*/
public Property setDefaultValue(boolean defaultValue)
@ -550,10 +550,10 @@ public class Property
setDefaultValue(Boolean.toString(defaultValue));
return this;
}
/**
* Sets the default boolean[] values of this Property.
*
*
* @param defaultValues an array of boolean values
*/
public Property setDefaultValues(boolean[] defaultValues)
@ -561,14 +561,14 @@ public class Property
String[] temp = new String[defaultValues.length];
for (int i = 0; i < defaultValues.length; i++)
temp[i] = Boolean.toString(defaultValues[i]);
setDefaultValues(temp);
return this;
}
/**
* Sets the minimum int value of this Property.
*
*
* @param minValue an int value
*/
public Property setMinValue(int minValue)
@ -576,10 +576,10 @@ public class Property
this.minValue = Integer.toString(minValue);
return this;
}
/**
* Sets the maximum int value of this Property.
*
*
* @param maxValue an int value
*/
public Property setMaxValue(int maxValue)
@ -587,10 +587,10 @@ public class Property
this.maxValue = Integer.toString(maxValue);
return this;
}
/**
* Sets the minimum double value of this Property.
*
*
* @param minValue a double value
*/
public Property setMinValue(double minValue)
@ -598,10 +598,10 @@ public class Property
this.minValue = Double.toString(minValue);
return this;
}
/**
* Sets the maximum double value of this Property.
*
*
* @param maxValue a double value
*/
public Property setMaxValue(double maxValue)
@ -609,30 +609,30 @@ public class Property
this.maxValue = Double.toString(maxValue);
return this;
}
/**
* Gets the minimum value.
*
*
* @return the minimum value bound
*/
public String getMinValue()
{
return minValue;
}
/**
* Gets the maximum value.
*
*
* @return the maximum value bound
*/
public String getMaxValue()
{
return maxValue;
}
/**
* Returns the value in this property as it's raw string.
*
*
* @return current value
*/
public String getString()
@ -643,7 +643,7 @@ public class Property
/**
* Sets the array of valid values that this String Property can be set to. When an array of valid values is defined for a Property the
* GUI control for that property will be a value cycle button.
*
*
* @param validValues a String array of valid values
*/
public Property setValidValues(String[] validValues)
@ -651,21 +651,21 @@ public class Property
this.validValues = validValues;
return this;
}
/**
* Gets the array of valid values that this String Property can be set to, or null if not defined.
*
*
* @return a String array of valid values
*/
public String[] getValidValues()
{
return this.validValues;
}
/**
* Returns the value in this property as an integer,
* if the value is not a valid integer, it will return the initially provided default.
*
*
* @return The value
*/
public int getInt()
@ -684,7 +684,7 @@ public class Property
* Returns the value in this property as an integer,
* if the value is not a valid integer, it will return the
* provided default.
*
*
* @param _default The default to provide if the current value is not a valid integer
* @return The value
*/
@ -699,7 +699,7 @@ public class Property
return _default;
}
}
/**
* Checks if the current value stored in this property can be converted to an integer.
* @return True if the type of the Property is an Integer
@ -721,7 +721,7 @@ public class Property
* Returns the value in this property as a boolean,
* if the value is not a valid boolean, it will return the
* provided default.
*
*
* @param _default The default to provide
* @return The value as a boolean, or the default
*/
@ -739,7 +739,7 @@ public class Property
/**
* Returns the value in this property as a boolean, if the value is not a valid boolean, it will return the provided default.
*
*
* @return The value as a boolean, or the default
*/
public boolean getBoolean()
@ -753,10 +753,10 @@ public class Property
return Boolean.parseBoolean(defaultValue);
}
}
/**
* Checks if the current value held by this property is a valid boolean value.
*
*
* @return True if it is a boolean value
*/
public boolean isBooleanValue()
@ -785,7 +785,7 @@ public class Property
* Returns the value in this property as a double,
* if the value is not a valid double, it will return the
* provided default.
*
*
* @param _default The default to provide if the current value is not a valid double
* @return The value
*/
@ -803,7 +803,7 @@ public class Property
/**
* Returns the value in this property as a double, if the value is not a valid double, it will return the provided default.
*
*
* @param _default The default to provide if the current value is not a valid double
* @return The value
*/
@ -818,7 +818,7 @@ public class Property
return Double.parseDouble(defaultValue);
}
}
public String[] getStringList()
{
return values;
@ -827,13 +827,13 @@ public class Property
/**
* Returns the integer value of all values that can
* be parsed in the list.
*
*
* @return Array of length 0 if none of the values could be parsed.
*/
public int[] getIntList()
{
ArrayList<Integer> nums = new ArrayList<Integer>();
for (String value : values)
{
try
@ -877,7 +877,7 @@ public class Property
/**
* Returns the boolean value of all values that can
* be parsed in the list.
*
*
* @return Array of length 0 if none of the values could be parsed.
*/
public boolean[] getBooleanList()
@ -916,14 +916,14 @@ public class Property
return false;
}
}
return isList && type == Type.BOOLEAN;
}
/**
* Returns the double value of all values that can
* be parsed in the list.
*
*
* @return Array of length 0 if none of the values could be parsed.
*/
public double[] getDoubleList()
@ -966,13 +966,13 @@ public class Property
return false;
}
}
return isList && type == Type.DOUBLE;
}
/**
* Gets the name/key for this Property.
*
*
* @return the Property name
*/
public String getName()
@ -982,20 +982,19 @@ public class Property
/**
* Sets the name/key for this Property.
*
*
* @param name a name
*/
public Property setName(String name)
public void setName(String name)
{
this.name = name;
return this;
}
/**
* Determines if this config value was just created, or if it was read from the config file.
* This is useful for mods who auto-assign their blocks to determine if the ID returned is
* This is useful for mods who auto-assign their blocks to determine if the ID returned is
* a configured one, or a automatically generated one.
*
*
* @return True if this property was loaded from the config file with a value
*/
public boolean wasRead()
@ -1005,7 +1004,7 @@ public class Property
/**
* Gets the Property.Type enum value for this Property.
*
*
* @return the Property's type
*/
public Type getType()
@ -1015,7 +1014,7 @@ public class Property
/**
* Returns whether or not this Property is a list/array.
*
*
* @return true if this Property is a list/array, false otherwise
*/
public boolean isList()
@ -1025,12 +1024,12 @@ public class Property
/**
* Gets the changed status of this Property.
*
*
* @return true if this Property has changed, false otherwise
*/
public boolean hasChanged(){ return changed; }
void resetChangedState(){ changed = false; }
/**
* Sets the value of this Property to the provided String value.
*/
@ -1045,7 +1044,7 @@ public class Property
{
this.setValue(value);
}
/**
* Sets the values of this Property to the provided String[] values.
*/
@ -1060,7 +1059,7 @@ public class Property
{
this.setValues(values);
}
/**
* Sets the value of this Property to the provided int value.
*/
@ -1069,7 +1068,7 @@ public class Property
setValue(Integer.toString(value));
return this;
}
/**
* Sets the value of this Property to the provided boolean value.
*/
@ -1078,7 +1077,7 @@ public class Property
setValue(Boolean.toString(value));
return this;
}
/**
* Sets the value of this Property to the provided double value.
*/
@ -1087,7 +1086,7 @@ public class Property
setValue(Double.toString(value));
return this;
}
/**
* Sets the values of this Property to the provided boolean[] values.
*/
@ -1104,7 +1103,7 @@ public class Property
{
this.setValues(values);
}
/**
* Sets the values of this Property to the provided int[] values.
*/
@ -1116,12 +1115,12 @@ public class Property
changed = true;
return this;
}
public void set(int[] values)
{
this.setValues(values);
}
/**
* Sets the values of this Property to the provided double[] values.
*/
@ -1133,7 +1132,7 @@ public class Property
changed = true;
return this;
}
public void set(double[] values)
{
this.setValues(values);