Package ch.njol.skript.config
Class Config
java.lang.Object
ch.njol.skript.config.Config
- All Implemented Interfaces:
NodeNavigator
,AnyNamed
,AnyProvider
,Comparable<Config>
,Iterable<Node>
,Validated
public class Config
extends Object
implements Comparable<Config>, Validated, NodeNavigator, AnyNamed
Represents a config file.
-
Constructor Summary
ConstructorDescriptionConfig
(InputStream source, String fileName, boolean simple, boolean allowEmptySections, String defaultSeparator) Config
(InputStream source, String fileName, @Nullable File file, boolean simple, boolean allowEmptySections, String defaultSeparator) A dummy config with no (known) content. -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
compareValues
(Config other, String... excluded) Compares the keys and values of this Config and another.@Nullable Node
Obtains the immediate child node at this (direct) key.@Nullable String
Gets an entry node's value at the designated path@Nullable String
Splits the given path at the dot character and passes the result toget(String...)
.@NotNull Node
Obtains the current node represented by this navigator.@Nullable File
getFile()
@Nullable Node
Fetches a node at position inside the current node.@Nullable Path
getPath()
void
Mark a thing as no longer safe to use.boolean
isEmpty()
iterator()
If this navigator represents a node with no children (e.g.void
Sets all staticOption
fields of the given class to the values from this configvoid
Sets allOption
fields of the given object to the values from this configname()
void
Saves the config to a file.boolean
Deprecated, for removal: This API element is subject to removal in a future version.This copies all values from the other config and sets them in this config, which could be destructive for sensitive data if something goes wrong.boolean
Deprecated, for removal: This API element is subject to removal in a future version.This copies all values from the other config and sets them in this config, which could be destructive for sensitive data if something goes wrong.boolean
updateNodes
(@NotNull Config newer) Updates the nodes of this config with the nodes of another config.boolean
valid()
Implementations ought to specify what 'valid' means locally (e.g.boolean
validate
(SectionValidator validator) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.njol.skript.lang.util.common.AnyNamed
setName, supportsNameChange
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface ch.njol.skript.config.NodeNavigator
getNodeAt, getValue
-
Constructor Details
-
Config
public Config(InputStream source, String fileName, @Nullable @Nullable File file, boolean simple, boolean allowEmptySections, String defaultSeparator) throws IOException - Throws:
IOException
-
Config
public Config(InputStream source, String fileName, boolean simple, boolean allowEmptySections, String defaultSeparator) throws IOException - Throws:
IOException
-
Config
public Config(File file, boolean simple, boolean allowEmptySections, String defaultSeparator) throws IOException - Throws:
IOException
-
Config
public Config(@NotNull @NotNull Path file, boolean simple, boolean allowEmptySections, String defaultSeparator) throws IOException - Throws:
IOException
-
Config
A dummy config with no (known) content.
-
-
Method Details
-
load
Sets allOption
fields of the given object to the values from this config -
load
Sets all staticOption
fields of the given class to the values from this config -
getMainNode
-
getFileName
-
save
Saves the config to a file.- Parameters:
file
- The file to save to- Throws:
IOException
- If the file could not be written to.
-
setValues
Deprecated, for removal: This API element is subject to removal in a future version.This copies all values from the other config and sets them in this config, which could be destructive for sensitive data if something goes wrong. Also removes user comments. UseupdateNodes(Config)
instead. -
setValues
Deprecated, for removal: This API element is subject to removal in a future version.This copies all values from the other config and sets them in this config, which could be destructive for sensitive data if something goes wrong. Also removes user comments. UseupdateNodes(Config)
instead. -
updateNodes
Updates the nodes of this config with the nodes of another config. Used for updating a config file to a newer version.This method only sets nodes that are missing in this config, thus preserving any existing values.
- Parameters:
newer
- The newer config to update from.- Returns:
- True if any keys were added to this config, false otherwise.
-
compareValues
Compares the keys and values of this Config and another.- Parameters:
other
- The other Config.excluded
- Keys to exclude from this comparison.- Returns:
- True if there are differences in the keys and their values of this Config and the other Config.
-
getByPath
Splits the given path at the dot character and passes the result toget(String...)
.- Parameters:
path
-- Returns:
- get(path.split("\\."))
-
get
Gets an entry node's value at the designated path- Parameters:
path
-- Returns:
- The entry node's value at the location defined by path or null if it either doesn't exist or is not an entry.
-
toMap
-
validate
-
isEmpty
public boolean isEmpty()- Returns:
- Whether the config is empty.
-
getFile
- Returns:
- The file this config was loaded from, or null if it was loaded from an InputStream.
-
getPath
- Returns:
- The path this config was loaded from, or null if it was loaded from an InputStream.
-
getSeparator
- Returns:
- The most recent separator. Only useful while the file is loading.
-
getSaveSeparator
- Returns:
- A separator string useful for saving, e.g. ": ".
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Config>
-
invalidate
public void invalidate()Description copied from interface:Validated
Mark a thing as no longer safe to use. This should (typically) not be used by external modifiers, but implementations may differ.
Implementations that do not want to expose an invalidator hook may throw anUnsupportedOperationException
, which is protected by the internal contract.- Specified by:
invalidate
in interfaceValidated
-
valid
public boolean valid()Description copied from interface:Validated
Implementations ought to specify what 'valid' means locally (e.g. should a new copy be obtained?) when overriding this method. -
getCurrentNode
Description copied from interface:NodeNavigator
Obtains the current node represented by this navigator. If this navigator is itself a node, it should return itself.- Specified by:
getCurrentNode
in interfaceNodeNavigator
- Returns:
- The main node represented by this navigator
-
getNodeAt
Description copied from interface:NodeNavigator
Fetches a node at position inside the current node. If any stage represents a node with no children (e.g. an entry node) the result will be null.
In the following example, the two entry nodes can be obtained from the root with"first", "one"
and"first", "two", "three"
(respectively).first: one: value two: three: value
- Specified by:
getNodeAt
in interfaceNodeNavigator
- Parameters:
steps
- The node steps to traverse- Returns:
- The node at the final step (or nothing)
-
iterator
Description copied from interface:NodeNavigator
If this navigator represents a node with no children (e.g. an entry node) this iterator will be empty.- Specified by:
iterator
in interfaceIterable<Node>
- Specified by:
iterator
in interfaceNodeNavigator
- Returns:
- An iterator for all children represented by this node navigator
-
get
Description copied from interface:NodeNavigator
Obtains the immediate child node at this (direct) key. If this does not represent a node that can have children (e.g. anEntryNode
) then it must returnnull
.- Specified by:
get
in interfaceNodeNavigator
- Parameters:
step
- The name of the node- Returns:
- The child node if one is present, otherwise
null
-
name
-