Class ConfigurationNode<T>

java.lang.Object
dev.satyrn.papermc.api.configuration.v1.ConfigurationNode<T>
Type Parameters:
T - The value type.
Direct Known Subclasses:
BigDecimalNode, BigIntegerNode, BooleanNode, ConfigurationContainer, ContainerNode, DifficultyDependentNode, DoubleNode, EnumListNode, EnumNode, IntegerNode, MapListNode, OptionalConfigurationNode, StringNode, TypedMapListNode

public abstract class ConfigurationNode<T> extends Object
Represents a single configuration node. Cannot contain sub-nodes or containers.
Since:
1.0.0
Author:
Isabel Maskrey
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ConfigurationNode(@NotNull ConfigurationNode<?> parent, @Nullable String name)
    Initializes a new Configuration node.
    protected
    ConfigurationNode(@NotNull ConfigurationNode<?> parent, @Nullable String name, @NotNull org.bukkit.configuration.Configuration config)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Since 1.9.0.
    protected
    ConfigurationNode(@NotNull org.bukkit.plugin.Plugin plugin, @Nullable ConfigurationNode<?> parent, @Nullable String name)
    Initializes a new Configuration node.
    protected
    ConfigurationNode(@NotNull org.bukkit.plugin.Plugin plugin, @Nullable ConfigurationNode<?> parent, @Nullable String name, @NotNull org.bukkit.configuration.Configuration config)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Since 1.9.0.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final void
    addChild(@NotNull ConfigurationNode<?> configurationNode)
    Ensures that the node's list of children includes the specified child node.
    abstract T
    Gets the default value of the node.
    boolean
    Indicates whether some other object is "equal to" this one.
    final @NotNull String
    Gets the path of the base node.
    final @NotNull String
    getBasePath(@NotNull StringBuilder stringBuilder)
    Gets the path of the base node.
    @NotNull @Unmodifiable List<@NotNull ConfigurationNode<?>>
    Gets an unmodifiable list of children for this node.
    @NotNull @Unmodifiable List<String>
    Gets the comment list for the value node path.
    @NotNull @Unmodifiable List<String>
    getComments(boolean basePath)
    Gets the comment list for this node.
    @NotNull org.bukkit.configuration.Configuration
    Gets the configuration instance for the plugin.
    @NotNull @Unmodifiable List<String>
    Gets the inline comment list for the value node path.
    @NotNull @Unmodifiable List<String>
    getInlineComments(boolean basePath)
    Gets the inline comment list for this node.
    @NotNull Logger
    Returns the plugin logger associated with this server's logger.
    @Nullable String
    Gets the name of the node.
    @NotNull String
    Deprecated.
    Since 1.9.0.
    final @NotNull String
    getPath(@NotNull StringBuilder stringBuilder)
    Deprecated.
    Since 1.9.0.
    @NotNull org.bukkit.plugin.Plugin
    Gets the plugin instance.
    @NotNull NodePriority
    Gets the priority of this node.
    org.slf4j.Logger
    Returns the plugin logger associated with this server's logger.
    @NotNull String
    Gets the name of the value node, which will be used if this node contains children and a value.
    final @NotNull String
    Gets the path of the node that contains the value.
    final @NotNull String
    getValuePath(@NotNull StringBuilder stringBuilder)
    Gets the path of the node that contains the value.
    final boolean
    Whether the configuration node contains children.
    final boolean
    Whether the configuration node is named.
    final boolean
    Whether the configuration node is a sub node or a root node.
    void
    Writes the value of the node to the config file.
    void
    setComments(boolean basePath, @Nullable String... comments)
    Sets the comment list for the node.
    void
    setComments(@Nullable String... comments)
    Sets the comment list at the value node path.
    void
    Sets the value of the node in the configuration file.
    void
    setInlineComments(boolean basePath, @Nullable String... comments)
    Sets the inline comment list for the node.
    void
    setInlineComments(@Nullable String... comments)
    Sets the inline comment list at the value node path.
    void
    setValue(T value)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Since 1.10.0.
    final @NotNull String
    Returns the string representation of this node.
    void
    toString(@NotNull StringBuilder stringBuilder)
    Builds the string value of the node.
    abstract T
    Gets the value of the node.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ConfigurationNode

      @Deprecated(since="1.9.0", forRemoval=true) protected ConfigurationNode(@NotNull @NotNull ConfigurationNode<?> parent, @Nullable @Nullable String name, @NotNull @NotNull org.bukkit.configuration.Configuration config)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 1.9.0. Use a constructor which does not use a configuration parameter, as the value of the parameter is ignored.
      Initializes a new Configuration node.
      Parameters:
      parent - The parent node.
      name - The node name.
      config - The configuration instance.
      Since:
      1.0.0
    • ConfigurationNode

      @Deprecated(since="1.9.0", forRemoval=true) protected ConfigurationNode(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @Nullable @Nullable ConfigurationNode<?> parent, @Nullable @Nullable String name, @NotNull @NotNull org.bukkit.configuration.Configuration config)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 1.9.0. Use a constructor which does not use a configuration parameter, as the value of the parameter is ignored.
      Initializes a new Configuration node.
      Parameters:
      plugin - The plugin instance.
      parent - The parent node.
      name - The node name.
      config - The configuration instance.
      Since:
      1.6.0
    • ConfigurationNode

      protected ConfigurationNode(@NotNull @NotNull ConfigurationNode<?> parent, @Nullable @Nullable String name)
      Initializes a new Configuration node.
      Parameters:
      parent - The parent node.
      name - The node name.
      Since:
      1.0.0
    • ConfigurationNode

      protected ConfigurationNode(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @Nullable @Nullable ConfigurationNode<?> parent, @Nullable @Nullable String name)
      Initializes a new Configuration node.
      Parameters:
      plugin - The plugin instance.
      parent - The parent node.
      name - The node name.
      Since:
      1.6.0
  • Method Details

    • getPlugin

      @NotNull public @NotNull org.bukkit.plugin.Plugin getPlugin()
      Gets the plugin instance.
      Returns:
      The plugin instance.
      Since:
      1.6.0
    • getConfig

      @NotNull public @NotNull org.bukkit.configuration.Configuration getConfig()
      Gets the configuration instance for the plugin.
      Returns:
      The configuration instance.
      Since:
      1.0.0
    • getName

      @Nullable public @Nullable String getName()
      Gets the name of the node.
      Returns:
      The name of the node.
      Since:
      1.0.0
    • getPath

      @Deprecated(since="1.9.0") @NotNull public @NotNull String getPath()
      Deprecated.
      Since 1.9.0. Use getValuePath() or getBasePath(StringBuilder) instead.
      Constructs the full node path.
      Returns:
      The full node path.
      Since:
      1.0.0
    • getPath

      @Deprecated(since="1.9.0") @NotNull public final @NotNull String getPath(@NotNull @NotNull StringBuilder stringBuilder)
      Deprecated.
      Since 1.9.0. Use getValuePath() or getBasePath(StringBuilder) instead.
      Constructs the full node path.
      Parameters:
      stringBuilder - The StringBuilder with which to build out the full node path.
      Returns:
      The full node path.
      Since:
      1.0.0
    • getValuePath

      @NotNull public final @NotNull String getValuePath()
      Gets the path of the node that contains the value.

      Only matches the value of getBasePath(...) if this node does not contain any children.

      Returns:
      The full path of the node which contains the value.
      Since:
      1.10.0
    • getValuePath

      @NotNull public final @NotNull String getValuePath(@NotNull @NotNull StringBuilder stringBuilder)
      Gets the path of the node that contains the value.

      Only matches the value of getBasePath(...) if this node does not contain any children.

      Parameters:
      stringBuilder - The string builder with which to build out the full path name.
      Returns:
      The full path of the node which contains the value.
      Since:
      1.9.0
    • getBasePath

      @NotNull public final @NotNull String getBasePath()
      Gets the path of the base node.

      Only matches the value of getValuePath(...) if this node does not contain any children.

      Returns:
      The full path of this node.
      Since:
      1.9.0
    • getBasePath

      @NotNull public final @NotNull String getBasePath(@NotNull @NotNull StringBuilder stringBuilder)
      Gets the path of the base node.

      Only matches the value of getValuePath(...) if this node does not contain any children.

      Parameters:
      stringBuilder - The StringBuilder with which to build out the full path name.
      Returns:
      The full path of this node.
      Since:
      1.9.0
    • getValueNodeName

      @NotNull public @NotNull String getValueNodeName()
      Gets the name of the value node, which will be used if this node contains children and a value.

      Defaults to "value" for most node types.

      Returns:
      The name of the value node.
      Since:
      1.9.0
    • toString

      @NotNull public final @NotNull String toString()
      Returns the string representation of this node.

      By default, this matches the format path=value, where path is the path of the configuration value, and value is the string representation of the value of this node.

      This can be overridden indirectly by altering toString(StringBuilder).

      Overrides:
      toString in class Object
      Returns:
      The value as a string.
      Since:
      1.0.0
    • toString

      public void toString(@NotNull @NotNull StringBuilder stringBuilder)
      Builds the string value of the node.

      Override this to alter the value returned by toString().

      By default, this matches the format path=value, where path is the path of the configuration value, and value is the string representation of the value of this node.

      Parameters:
      stringBuilder - The StringBuilder with which to build the string.
      Since:
      1.9.1
    • value

      @Nullable public abstract T value()
      Gets the value of the node.
      Returns:
      The value.
      Since:
      1.0.0
    • defaultValue

      @Nullable public abstract T defaultValue()
      Gets the default value of the node.
      Returns:
      The default value.
      Since:
      1.3.0
    • setValue

      @Deprecated(since="1.10.0", forRemoval=true) public void setValue(@Nullable T value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 1.10.0. Use setConfigValue(T) instead. Will be removed in the future.
      Sets the value of the node in the configuration file.
      Parameters:
      value - The value to set.
      Since:
      1.9.0
    • setConfigValue

      public void setConfigValue(@Nullable T value)
      Sets the value of the node in the configuration file.
      Parameters:
      value - The value to set.
      Since:
      1.10.0
    • addChild

      protected final void addChild(@NotNull @NotNull ConfigurationNode<?> configurationNode)
      Ensures that the node's list of children includes the specified child node.

      Duplicated values are discarded.

      Parameters:
      configurationNode - the child to add to the node.
      Since:
      1.9.0
    • hasChildren

      public final boolean hasChildren()
      Whether the configuration node contains children.
      Returns:
      true if the child list is not empty; otherwise, false
      Since:
      1.9.0
    • isSubNode

      public final boolean isSubNode()
      Whether the configuration node is a sub node or a root node.
      Returns:
      true if the node has a parent node; otherwise, false
      Since:
      1.9.0
    • hasName

      public final boolean hasName()
      Whether the configuration node is named.
      Returns:
      true if the root node name is not null or blank; otherwise, false
      Since:
      1.9.0
    • save

      public void save()
      Writes the value of the node to the config file.
      Since:
      1.9.0
    • getComments

      @NotNull public @NotNull @Unmodifiable List<String> getComments()
      Gets the comment list for the value node path.

      If no comments exist, an empty list will be returned. A null entry represents an empty line and an empty String represents an empty comment line.

      Returns:
      An unmodifiable list of the node's comments. Every entry represents one line.
      Since:
      1.9.0
    • getComments

      @NotNull public @NotNull @Unmodifiable List<String> getComments(boolean basePath)
      Gets the comment list for this node.

      If no comments exist, an empty list will be returned. A null entry represents an empty line and an empty String represents an empty comment line.

      Parameters:
      basePath - If true, the node's base path will be used instead of its value path. This is useful if you have nested value nodes.
      Returns:
      An unmodifiable list of the node's comments. Every entry represents one line.
      Since:
      1.9.0
    • getInlineComments

      @NotNull public @NotNull @Unmodifiable List<String> getInlineComments()
      Gets the inline comment list for the value node path.

      If no comments exist, an empty list will be returned. A null entry represents an empty line and an empty String represents an empty comment line.

      Returns:
      An unmodifiable list of the node's inline comments. Every entry represents one line.
      Since:
      1.9.0
    • getInlineComments

      @NotNull public @NotNull @Unmodifiable List<String> getInlineComments(boolean basePath)
      Gets the inline comment list for this node.

      If no comments exist, an empty list will be returned. A null entry represents an empty line and an empty String represents an empty comment line.

      Parameters:
      basePath - If true, the node's base path will be used instead of the value path. This is useful if you have nested value nodes.
      Returns:
      An unmodifiable list of the node's inline comments. Every entry represents one line.
      Since:
      1.9.0
    • setComments

      public void setComments(@Nullable @Nullable String... comments)
      Sets the comment list at the value node path.

      If value is null, the comments will be removed. A null entry is an empty line and an empty String entry is an empty comment line. If the path does not exist, no comments will be set. Any existing comments will be replaced, regardless of what the new comments are.

      Some implementations may have limitations on what persists. See their individual javadocs for details.

      Parameters:
      comments - New comments to set at the value node. Every entry represents a new line.
      Since:
      1.9.0
    • setComments

      public void setComments(boolean basePath, @Nullable @Nullable String... comments)
      Sets the comment list for the node.

      If value is null, the comments will be removed. A null entry is an empty line and an empty String entry is an empty comment line. If the path does not exist, no comments will be set. Any existing comments will be replaced, regardless of what the new comments are.

      Some implementations may have limitations on what persists. See their individual javadocs for details.

      Parameters:
      basePath - If true, the node's base path will be used instead of its value path. This is useful if you have nested value nodes.
      comments - New comments to set for the node. Every entry represents a new line.
      Since:
      1.9.0
    • setInlineComments

      public void setInlineComments(@Nullable @Nullable String... comments)
      Sets the inline comment list at the value node path.

      If value is null, the comments will be removed. A null entry is an empty line and an empty String entry is an empty comment line. If the path does not exist, no comment will be set. Any existing comments will be replaced, regardless of what the new comments are.

      Some implementations may have limitations on what persists. See their individual javadocs for details.

      Parameters:
      comments - New comments to set at the value node path. Every entry represents a new line.
      Since:
      1.9.0
    • setInlineComments

      public void setInlineComments(boolean basePath, @Nullable @Nullable String... comments)
      Sets the inline comment list for the node.

      If value is null, the comments will be removed. A null entry is an empty line and an empty String entry is an empty comment line. If the path does not exist, no comment will be set. Any existing comments will be replaced, regardless of what the new comments are.

      Some implementations may have limitations on what persists. See their individual javadocs for details.

      Parameters:
      basePath - if true, the base path will be used instead of the value path. This can be useful if you have nested value nodes.
      comments - New comments to set for the node. Every entry represents a new line.
      Since:
      1.9.0
    • getLogger

      @NotNull public @NotNull Logger getLogger()
      Returns the plugin logger associated with this server's logger. The returned logger automatically tags all log messages with the plugin's name.
      Returns:
      Logger associated with this plugin
      Since:
      1.9.0
    • getSLF4JLogger

      @NotNull public org.slf4j.Logger getSLF4JLogger()
      Returns the plugin logger associated with this server's logger. The returned logger automatically tags all log messages with the plugin's name.
      Returns:
      SLF4J Logger associated with the plugin.
      Since:
      1.9.0
    • getChildren

      @NotNull public @NotNull @Unmodifiable List<@NotNull ConfigurationNode<?>> getChildren()
      Gets an unmodifiable list of children for this node.
      Returns:
      An unmodifiable list of the item's children.
      Since:
      1.9.1
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one.

      Two ConfigurationNode objects are equivalent based purely on whether their plugin instance and base path are the same.

      Overrides:
      equals in class Object
      Since:
      1.10.0
    • getPriority

      @NotNull public @NotNull NodePriority getPriority()
      Gets the priority of this node.

      See NodePriority for an explanation of priority functionality.

      Returns:
      The node's priority.