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 Details

  • Method Details

    • load

      public void load(Object object)
      Sets all Option fields of the given object to the values from this config
    • load

      public void load(Class<?> clazz)
      Sets all static Option fields of the given class to the values from this config
    • getMainNode

      public SectionNode getMainNode()
    • getFileName

      public String getFileName()
    • save

      public void save(File file) throws IOException
      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(forRemoval=true) public boolean setValues(Config other)
      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. Use updateNodes(Config) instead.
    • setValues

      @Deprecated(forRemoval=true) public boolean setValues(Config other, String... excluded)
      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. Use updateNodes(Config) instead.
    • updateNodes

      public boolean updateNodes(@NotNull @NotNull Config newer)
      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

      public boolean compareValues(Config other, String... excluded)
      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

      @Nullable public @Nullable String getByPath(@NotNull @NotNull String path)
      Splits the given path at the dot character and passes the result to get(String...).
      Parameters:
      path -
      Returns:
      get(path.split("\\."))
    • get

      @Nullable public @Nullable String get(String... path)
      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

      public Map<String,String> toMap(String separator)
    • validate

      public boolean validate(SectionValidator validator)
    • isEmpty

      public boolean isEmpty()
      Returns:
      Whether the config is empty.
    • getFile

      @Nullable public @Nullable File getFile()
      Returns:
      The file this config was loaded from, or null if it was loaded from an InputStream.
    • getPath

      @Nullable public @Nullable Path getPath()
      Returns:
      The path this config was loaded from, or null if it was loaded from an InputStream.
    • getSeparator

      public String getSeparator()
      Returns:
      The most recent separator. Only useful while the file is loading.
    • getSaveSeparator

      public String getSaveSeparator()
      Returns:
      A separator string useful for saving, e.g. ": ".
    • compareTo

      public int compareTo(@Nullable @Nullable Config other)
      Specified by:
      compareTo in interface Comparable<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 an UnsupportedOperationException, which is protected by the internal contract.
      Specified by:
      invalidate in interface Validated
    • 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.
      Specified by:
      valid in interface Validated
      Returns:
      Whether this is still valid
    • getCurrentNode

      @NotNull public @NotNull Node 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 interface NodeNavigator
      Returns:
      The main node represented by this navigator
    • getNodeAt

      @Nullable public @Nullable Node getNodeAt(@NotNull @NotNull String @NotNull ... steps)
      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 interface NodeNavigator
      Parameters:
      steps - The node steps to traverse
      Returns:
      The node at the final step (or nothing)
    • iterator

      @NotNull public @NotNull Iterator<Node> 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 interface Iterable<Node>
      Specified by:
      iterator in interface NodeNavigator
      Returns:
      An iterator for all children represented by this node navigator
    • get

      @Nullable public @Nullable Node get(String step)
      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. an EntryNode) then it must return null.
      Specified by:
      get in interface NodeNavigator
      Parameters:
      step - The name of the node
      Returns:
      The child node if one is present, otherwise null
    • name

      public String name()
      Specified by:
      name in interface AnyNamed
      Returns:
      The name of this config (excluding path and file extensions)