Class AddonConfig
A map from config paths to config values. Paths are dot-separated
expressions such as foo.bar.baz. Values are as in JSON
(booleans, strings, numbers, lists, or objects). Values accessed through an
AddonConfig are never null.
If a path does not exist when called with a get____ function, a ConfigException.Missing will be thrown.
All paths must be initially registered during BTWAddon.registerConfigProperties(api.config.AddonConfig),
or they will not be saved.
readAndWriteConfig() when editing this config after BTWAddon.registerConfigProperties(api.config.AddonConfig), or properties WILL NOT BE SAVED.
An example config would be set up during BTWAddon.registerConfigProperties(api.config.AddonConfig):
public void registerConfigProperties(AddonConfig config) {
// Register an integer with no minimum and no maximum and a default value of 6 to path foo.bar with no comment
config.registerInt("foo.bar", 6);
//Register a boolean with a default value of false to
config.registerBoolean("foo.buzz", false, "A boolean");
//Note that the previous two examples will be in the path category "foo", and you can add a comment to that category
config.registerCategoryComment("foo", "This is the foo category");
// If transferring old values to new values, such as when updating a config, you can update the old path to the new one with updatePath like so
config.updatePath("bar", "foo.bar");
}-
Constructor Summary
ConstructorsConstructorDescriptionAddonConfig(String fileName) AddonConfig(String fileName, String oldFileName) -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBoolean(String path) getBooleanList(String path) Gets a list value with boolean elements.doublegetDoubleList(String path) Gets a list value with double elements.<T extends Enum<T>>
TgetEnumList(Class<T> enumClass, String path) Gets a list value withEnumelements.booleanintGets the integer at the given path.getIntList(String path) Gets a list value with int elements.longGets the long integer at the given path.getLongList(String path) Gets a list value with long elements.getStringList(String path) Gets a list value with string elements.booleanisEmpty()Call this method after you update the config.registerBoolean(String path, boolean value, String... comments) Register a boolean key value pair to this config.registerBoolean(String path, boolean value, List<String> comments) Register a boolean key value pair to this config.registerBooleanList(String path, List<Boolean> value, String... comments) Register a boolean list key value pair to this config.Register a boolean list key value pair to this config.registerCategoryComment(String path, String... comment) Register a comment for a specific path.registerCategoryComment(String path, List<String> comment) Register a comment for a specific path.registerDouble(String path, double value, double min, double max, String... comments) Register a double key value pair to this config.registerDouble(String path, double value, double min, double max, List<String> comments) Register a double key value pair to this config.registerDouble(String path, double value, String... comments) Register a double key value pair to this config.registerDouble(String path, double value, List<String> comments) Register a double key value pair to this config.registerDoubleList(String path, List<Double> value, double min, double max, String... comments) Register a double list key value pair to this config.Register a double list key value pair to this config.registerDoubleList(String path, List<Double> value, String... comments) Register a double list key value pair to this config.Register a double list key value pair to this config.<T extends Enum<T>>
AddonConfigregisterEnum(String path, T value, Class<T> enumClass, String... comments) Register an Enum based key value pair to this config.<T extends Enum<T>>
AddonConfigregisterEnum(String path, T value, Class<T> enumClass, List<String> comments) Register an Enum based key value pair to this config.<T extends Enum<T>>
voidregisterEnumList(String path, List<T> value, Class<T> enumClass, String... comments) Register an Enum list-based key value pair to this config.<T extends Enum<T>>
voidRegister an Enum list-based key value pair to this config.registerInt(String path, int value, int min, int max, String... comments) Register an integer key value pair.registerInt(String path, int value, int min, int max, List<String> comments) Register an integer key value pair.registerInt(String path, int value, String... comments) Register an integer key value pair.registerInt(String path, int value, List<String> comments) Register an integer key value pair.registerIntList(String path, List<Integer> value, int min, int max, String... comments) Register an integer list key value pair to this config.Register an integer list key value pair to this config.registerIntList(String path, List<Integer> value, String... comments) Register an integer list key value pair to this config.Register an integer list key value pair to this config.registerLong(String path, long value, long min, long max, String... comments) Register a long key value pair.registerLong(String path, long value, long min, long max, List<String> comments) Register a long key value pair.registerLong(String path, long value, String... comments) Register a long key value pair to this config.registerLong(String path, long value, List<String> comments) Register a long key value pair to this config.registerLongList(String path, List<Long> value, long min, long max, String... comments) Register a long list key value pair to this config.Register a long list key value pair to this config.Register a number list key value pair to this config.Register a number list key value pair to this config.registerNumberList(String path, List<Number> value, String... comments) Register a number list key value pair to this config.Register a number list key value pair to this config.registerString(String path, String value, String... comments) Register a string key value pair to this config allowing any string value.registerString(String path, String value, List<String> comments) Register a string key value pair to this config allowing any string value.registerStringList(String path, List<String> value, String... comments) Register a string list-based key value pair to this config allowing any string value.Register a string list key value pair to this config allowing any string value.render()Render the current config to a string.render(com.typesafe.config.ConfigRenderOptions renderOptions) Render the current config to a string.updatePath(@NotNull String oldPath, @NotNull String newPath) Use this to update an old path to a new one, e.g., when migrating from the old config system.
-
Constructor Details
-
AddonConfig
-
AddonConfig
-
-
Method Details
-
registerCategoryComment
Register a comment for a specific path. It's recommended to call this after registering values, or the comment might not be appended properly.Recommended for categories, for example, if you have multiple paths such as
general.fooandgeneral.bar, callingregisterCategoryComment("general", "Some comment")will append the comment# Some commentin the config.- Parameters:
path- Path to register comment for. If the path already exists, appends old comment to the end.comment- Comments to add to the path. Use separate strings instead of\n.
-
registerCategoryComment
Register a comment for a specific path. It's recommended to call this after registering values, or the comment might not be appended properly.Recommended for categories, for example, if you have multiple paths such as
general.fooandgeneral.bar, callingregisterCategoryComment("general", "Some comment")will append the comment# Some commentin the user facing config.- Parameters:
path- Path to register comment for. If the path already exists, appends old comment to the end.comment- Comments to add to the path. Use separate strings instead of\n.
-
registerInt
Register an integer key value pair. Specify aminandmaxvalue to set the minimum and maximum allowed values.- Parameters:
path- Path to register integer to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseInteger.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseInteger.MAX_VALUEto have no maximum.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerInt
Register an integer key value pair. Specify aminandmaxvalue to set the minimum and maximum allowed values.- Parameters:
path- Path to register integer to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseInteger.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseInteger.MAX_VALUEto have no maximum.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerInt
Register an integer key value pair. Has no min or max value.- Parameters:
path- Path to register integer to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerInt
Register an integer key value pair. Has no min or max value.- Parameters:
path- Path to register integer to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerLong
Register a long key value pair. Specify aminandmaxvalue to set the minimum and maximum allowed values.- Parameters:
path- Path to register long to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseLong.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseLong.MAX_VALUEto have no maximum.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerLong
Register a long key value pair. Specify aminandmaxvalue to set the minimum and maximum allowed values.- Parameters:
path- Path to register long to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseLong.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseLong.MAX_VALUEto have no maximum.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerLong
Register a long key value pair to this config. Has no min or max value.- Parameters:
path- Path to register long to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerLong
Register a long key value pair to this config. Has no min or max value.- Parameters:
path- Path to register long to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerDouble
public AddonConfig registerDouble(String path, double value, double min, double max, List<String> comments) Register a double key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseDouble.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseDouble.MAX_VALUEto have no maximum.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerDouble
public AddonConfig registerDouble(String path, double value, double min, double max, String... comments) Register a double key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseDouble.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseDouble.MAX_VALUEto have no maximum.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerDouble
Register a double key value pair to this config. Has no min or max value.- Parameters:
path- Path to register double to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerDouble
Register a double key value pair to this config. Has no min or max value.- Parameters:
path- Path to register double to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerString
Register a string key value pair to this config allowing any string value. UseregisterEnum(String, Enum, Class, List)instead if there should only be specific strings allowed.- Parameters:
path- Path to register string to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerString
Register a string key value pair to this config allowing any string value. UseregisterEnum(String, Enum, Class, String...)instead if there should only be specific strings allowed.- Parameters:
path- Path to register string to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerBoolean
Register a boolean key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerBoolean
Register a boolean key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerEnum
public <T extends Enum<T>> AddonConfig registerEnum(String path, T value, Class<T> enumClass, List<String> comments) Register an Enum based key value pair to this config. Will use the name of the enum constants as the valid strings.- Type Parameters:
T- a generic denoting a specific type of enum- Parameters:
path- Path to register double to.value- The default value for this path. Must be an element of an enum class. Users will have to match the case exactly, or an error will be thrown and the default will be used.enumClass- Class of the value enum, e.g.FooBarEnum.class.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerEnum
public <T extends Enum<T>> AddonConfig registerEnum(String path, T value, Class<T> enumClass, String... comments) Register an Enum based key value pair to this config. Will use the name of the enum constants as the valid strings.- Type Parameters:
T- a generic denoting a specific type of enum- Parameters:
path- Path to register double to.value- The default value for this path. Must be an element of an enum class.enumClass- Class of the value enum, e.g.FooBarEnum.class.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerBooleanList
Register a boolean list key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerBooleanList
Register a boolean list key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerNumberList
public AddonConfig registerNumberList(String path, List<Number> value, Number min, Number max, List<String> comments) Register a number list key value pair to this config. This non-specific type allows for users to input Integers, Doubles, and Longs. *- Parameters:
path- Path to register double to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseDouble.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseDouble.MAX_VALUEto have no maximum.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerNumberList
public AddonConfig registerNumberList(String path, List<Number> value, Number min, Number max, String... comments) Register a number list key value pair to this config. This non-specific type allows for users to input Integers, Doubles, and Longs.- Parameters:
path- Path to register a number list to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseDouble.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseDouble.MAX_VALUEto have no maximum.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerNumberList
Register a number list key value pair to this config. This non-specific type allows for users to input Integers, Doubles, and Longs. Has no min or max value.- Parameters:
path- Path to register a number list to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerNumberList
Register a number list key value pair to this config. This non-specific type allows for users to input Integers, Doubles, and Longs. Has no min or max value.- Parameters:
path- Path to register a number list to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerIntList
public AddonConfig registerIntList(String path, List<Integer> value, int min, int max, List<String> comments) Register an integer list key value pair to this config.- Parameters:
path- Path to register integer to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseInteger.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseInteger.MAX_VALUEto have no maximum.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerIntList
public AddonConfig registerIntList(String path, List<Integer> value, int min, int max, String... comments) Register an integer list key value pair to this config.- Parameters:
path- Path to register integer to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseInteger.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseInteger.MAX_VALUEto have no maximum.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerIntList
Register an integer list key value pair to this config. Has no min or max value.- Parameters:
path- Path to register integer to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerIntList
Register an integer list key value pair to this config. Has no min or max value.- Parameters:
path- Path to register integer to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerDoubleList
public AddonConfig registerDoubleList(String path, List<Double> value, double min, double max, List<String> comments) Register a double list key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseDouble.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseDouble.MAX_VALUEto have no maximum.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerDoubleList
public AddonConfig registerDoubleList(String path, List<Double> value, double min, double max, String... comments) Register a double list key value pair to this config.- Parameters:
path- Path to register double to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseDouble.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseDouble.MAX_VALUEto have no maximum.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerDoubleList
Register a double list key value pair to this config. Has no min or max value.- Parameters:
path- Path to register double to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerDoubleList
Register a double list key value pair to this config. Has no min or max value.- Parameters:
path- Path to register double to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerLongList
public AddonConfig registerLongList(String path, List<Long> value, long min, long max, List<String> comments) Register a long list key value pair to this config.- Parameters:
path- Path to register long to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseLong.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseLong.MAX_VALUEto have no maximum.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerLongList
public AddonConfig registerLongList(String path, List<Long> value, long min, long max, String... comments) Register a long list key value pair to this config.- Parameters:
path- Path to register long to.value- The default value for this path.min- The minimum allowed value for this (inclusive). UseLong.MIN_VALUEto have no minimum.max- The maximum allowed value for this (inclusive). UseLong.MAX_VALUEto have no maximum.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerStringList
Register a string list key value pair to this config allowing any string value.- Parameters:
path- Path to register long to.value- The default value for this path.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerStringList
Register a string list-based key value pair to this config allowing any string value.- Parameters:
path- Path to register long to.value- The default value for this path.comments- The user facing comments for this value. Use separate strings instead of\n.
-
registerEnumList
public <T extends Enum<T>> void registerEnumList(String path, List<T> value, Class<T> enumClass, List<String> comments) Register an Enum list-based key value pair to this config. Will use the name of the enum constants as the valid strings.- Type Parameters:
T- a generic denoting a specific type of enum- Parameters:
path- Path to register double to.value- The default value for this path. Must be an element of an enum class. Users will have to match the case exactly, or an error will be thrown and the default will be used.enumClass- Class of the value enum, e.g.FooBarEnum.class.comments- Mutable list (ieArrayList) of user facing comments for this value. Use separate strings instead of\n.
-
registerEnumList
public <T extends Enum<T>> void registerEnumList(String path, List<T> value, Class<T> enumClass, String... comments) Register an Enum list-based key value pair to this config. Will use the name of the enum constants as the valid strings.- Type Parameters:
T- a generic denoting a specific type of enum- Parameters:
path- Path to register double to.value- The default value for this path. Must be an element of an enum class. Users will have to match the case exactly, or an error will be thrown and the default will be used.enumClass- Class of the value enum, e.g.FooBarEnum.class.comments- The user facing comments for this value. Use separate strings instead of\n.
-
updatePath
Use this to update an old path to a new one, e.g., when migrating from the old config system. -
readAndWriteConfig
Call this method after you update the config. Saves the config file with new values to disk. -
getInt
Gets the integer at the given path. If the value at the path has a fractional (floating point) component, it will be discarded, and only the integer part will be returned (it works like a "narrowing primitive conversion" in the Java language specification).- Parameters:
path- path expression- Returns:
- the 32-bit integer value at the requested path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to an int (for example, it is out of range, or it's a boolean value)
-
getLong
Gets the long integer at the given path. If the value at the path has a fractional (floating point) component, it will be discarded, and only the integer part will be returned (it works like a "narrowing primitive conversion" in the Java language specification).- Parameters:
path- path expression- Returns:
- the 64-bit long value at the requested path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a long
-
getDouble
- Parameters:
path- path expression- Returns:
- the floating-point value at the requested path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a double
-
getBoolean
- Parameters:
path- path expression- Returns:
- the boolean value at the requested path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to boolean
-
getString
- Parameters:
path- path expression- Returns:
- the string value at the requested path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a string
-
getEnum
- Type Parameters:
T- a generic denoting a specific type of enum- Parameters:
enumClass- an enum classpath- path expression- Returns:
- the
Enumvalue at the requested path of the requested enum class - Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to an Enum
-
getIntList
Gets a list value with int elements. Throws if the path is unset or null or not a list or contains values not convertible to int.- Parameters:
path- the path to the list value.- Returns:
- the list at the path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a list of ints
-
getLongList
Gets a list value with long elements. Throws if the path is unset or null or not a list or contains values not convertible to long.- Parameters:
path- the path to the list value.- Returns:
- the list at the path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a list of longs
-
getDoubleList
Gets a list value with double elements. Throws if the path is unset or null or not a list or contains values not convertible to double.- Parameters:
path- the path to the list value.- Returns:
- the list at the path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a list of doubles
-
getBooleanList
Gets a list value with boolean elements. Throws if the path is unset or null or not a list or contains values not convertible to boolean.- Parameters:
path- the path to the list value.- Returns:
- the list at the path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a list of booleans
-
getStringList
Gets a list value with string elements. Throws if the path is unset or null or not a list or contains values not convertible to string.- Parameters:
path- the path to the list value.- Returns:
- the list at the path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a list of strings
-
getEnumList
Gets a list value withEnumelements. Throws if the path is unset or null or not a list or contains values not convertible toEnum.- Type Parameters:
T- a generic denoting a specific type of enum- Parameters:
enumClass- the enum classpath- the path to the list value.- Returns:
- the list at the path
- Throws:
com.typesafe.config.ConfigException.Missing- if value is absent or nullcom.typesafe.config.ConfigException.WrongType- if value is not convertible to a list ofEnum
-
getExists
- Returns:
- true if the key exists in the current config, false otherwise
-
getConfigFilePath
-
render
Render the current config to a string. UsesConfigUtils.CONFIG_RENDER_OPTIONSas the render options. -
render
Render the current config to a string.- Parameters:
renderOptions- Config render options to modify how it renders.
-
isEmpty
public boolean isEmpty()- Returns:
- true if the current config has no values registered to it
-