Package dev.cashire.cashconfig
Class Config
java.lang.Object
dev.cashire.cashconfig.Config
Configuration Object. Use this to load and save configuration data from a file.
-
Constructor Summary
ConstructorsConstructorDescriptionConfig(@NotNull BaseConfigItem<?> item, @NotNull String fileName)
Create new Configuration Instance.Create new Configuration Instance.Create new Configuration Instance.Config(@NotNull List<BaseConfigItem<?>> items, @NotNull String fileName)
Create new Configuration Instance.Config(BaseConfigItem<?> item, @NotNull File file)
Create new Configuration Instance.Config(List<BaseConfigItem<?>> items, @NotNull File file)
Create new Configuration Instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addItem(@NotNull BaseConfigItem<?> item)
Adds item to root of the config.boolean
addItem(@NotNull String path, @NotNull BaseConfigItem<?> item)
Adds item to existing item found at end of path.Retrieves an Item from the configuration structure.getItem(@NotNull String path, @NotNull BaseConfigItem.Type type)
Retrieves an Item from the configuration structure.List<BaseConfigItem<?>>
getItems()
Get list of Configuration items in this configuration.Get the type of the item at the given path.boolean
hasFile()
Checks to see if the file exists.boolean
Checks if Config has item at given path.void
readFile()
Reads configuration from file.void
removeItem(@NotNull String path)
Removes an item from the Config File.void
saveFile()
Saves current configuration to a file.void
setItem(@NotNull BaseConfigItem<?> item)
Sets the given item at the root of the config.void
setItem(@NotNull String path, @NotNull BaseConfigItem<?> item)
Sets the given item in the existing item at the end of the path.
-
Constructor Details
-
Config
Create new Configuration Instance. Loads/Saves file with given name fromFabricLoader.getConfigDir()
- Parameters:
fileName
- filename of config file.
-
Config
Create new Configuration Instance. Loads/Saves file with given name fromFabricLoader.getConfigDir()
- Parameters:
item
- item to default in if no values.fileName
- filename of config file.
-
Config
Create new Configuration Instance. Loads/Saves file with given name fromFabricLoader.getConfigDir()
- Parameters:
items
- items to default in if no values.fileName
- filename of config file.
-
Config
Create new Configuration Instance.- Parameters:
file
- file to read/save to.
-
Config
Create new Configuration Instance.- Parameters:
item
- item to default in if no valuesfile
- file to read/save to.
-
Config
Create new Configuration Instance.- Parameters:
items
- List of items to default in if no valuesfile
- file to read/save to.
-
-
Method Details
-
getItems
Get list of Configuration items in this configuration. IfreadFile()
hasn't been called, this will contain the defaults given.- Returns:
- list of
BaseConfigItem
's containing configuration data. - See Also:
for retrieving an individual item
-
saveFile
public void saveFile()Saves current configuration to a file. -
hasFile
public boolean hasFile()Checks to see if the file exists.- Returns:
- true if file exists, false otherwise
-
readFile
public void readFile()Reads configuration from file. Values can be retrieved viagetItem(String, Type)
orgetItems()
-
getItem
public BaseConfigItem<?> getItem(@NotNull @NotNull String path, @NotNull @NotNull BaseConfigItem.Type type) throws IllegalArgumentExceptionRetrieves an Item from the configuration structure.- Parameters:
path
- path to item in format: group.itemtype
- Type of the value expected to find at the end of the path.- Returns:
- item found, null otherwise
- Throws:
IllegalArgumentException
- thrown if type doesn't match item.
-
getItem
Retrieves an Item from the configuration structure.- Parameters:
path
- path to item in format: group.item- Returns:
- item if found, null otherwise
-
removeItem
Removes an item from the Config File.- Parameters:
path
- path to item in format: group.item
-
hasItem
Checks if Config has item at given path.- Parameters:
path
- path to item in format: group.item- Returns:
- true if item found, false otherwise
-
setItem
Sets the given item in the existing item at the end of the path. If existing item is an array, item is added.- Parameters:
path
- path where to add item in format: group.itemitem
- item to add, must have key if adding to group
-
setItem
Sets the given item at the root of the config.- Parameters:
item
- item to set, must have a key
-
addItem
Adds item to root of the config.- Parameters:
item
- item to add, must have key- Returns:
- true if added, false otherwise
-
addItem
Adds item to existing item found at end of path.- Parameters:
path
- path to item to add to. format: group.itemitem
- Item to add, must have key if path item is a group- Returns:
- true if added, false otherwise
-
getType
Get the type of the item at the given path.- Parameters:
path
- path to item in the format: group.item- Returns:
- Item Type if found, null otherwise.
-