Class YAMLNode

java.lang.Object
com.sk89q.util.yaml.YAMLNode
Direct Known Subclasses:
YAMLProcessor

public class YAMLNode extends Object
Represents a configuration node.
  • Field Details

  • Constructor Details

    • YAMLNode

      public YAMLNode(Map<String,Object> root, boolean writeDefaults)
  • Method Details

    • getMap

      public Map<String,Object> getMap()
      Return the underlying map.
      Returns:
      the map
    • clear

      public void clear()
      Clear all nodes.
    • getProperty

      public Object getProperty(String path)
      Gets a property at a location. This will either return an Object or null, with null meaning that no configuration value exists at that location. This could potentially return a default value (not yet implemented) as defined by a plugin, if this is a plugin-tied configuration.
      Parameters:
      path - path to node (dot notation)
      Returns:
      object or null
    • setProperty

      public void setProperty(String path, Object value)
      Set the property at a location. This will override existing configuration data to have it conform to key/value mappings.
      Parameters:
      path - the path
      value - the new value
    • addNode

      public YAMLNode addNode(String path)
      Adds a new node to the given path. The returned object is a reference to the new node. This method will replace an existing node at the same path. See setProperty.
      Parameters:
      path - the path
      Returns:
      a node for the path
    • getString

      public String getString(String path)
      Gets a string at a location. This will either return an String or null, with null meaning that no configuration value exists at that location. If the object at the particular location is not actually a string, it will be converted to its string representation.
      Parameters:
      path - path to node (dot notation)
      Returns:
      string or null
    • getVector

      public Vector3 getVector(String path)
      Gets a vector at a location. This will either return an Vector or a null. If the object at the particular location is not actually a string, it will be converted to its string representation.
      Parameters:
      path - path to node (dot notation)
      Returns:
      string or default
    • getVector2

      public Vector2 getVector2(String path)
      Gets a 2D vector at a location. This will either return an Vector or a null. If the object at the particular location is not actually a string, it will be converted to its string representation.
      Parameters:
      path - path to node (dot notation)
      Returns:
      string or default
    • getVector

      public Vector3 getVector(String path, Vector3 def)
      Gets a string at a location. This will either return an Vector or the default value. If the object at the particular location is not actually a string, it will be converted to its string representation.
      Parameters:
      path - path to node (dot notation)
      def - default value
      Returns:
      string or default
    • getString

      public String getString(String path, String def)
      Gets a string at a location. This will either return an String or the default value. If the object at the particular location is not actually a string, it will be converted to its string representation.
      Parameters:
      path - path to node (dot notation)
      def - default value
      Returns:
      string or default
    • getInt

      public Integer getInt(String path)
      Gets an integer at a location. This will either return an integer or null. If the object at the particular location is not actually a integer, the default value will be returned. However, other number types will be casted to an integer.
      Parameters:
      path - path to node (dot notation)
      Returns:
      integer or null
    • getInt

      public int getInt(String path, int def)
      Gets an integer at a location. This will either return an integer or the default value. If the object at the particular location is not actually a integer, the default value will be returned. However, other number types will be casted to an integer.
      Parameters:
      path - path to node (dot notation)
      def - default value
      Returns:
      int or default
    • getDouble

      public Double getDouble(String path)
      Gets a double at a location. This will either return an double or null. If the object at the particular location is not actually a double, the default value will be returned. However, other number types will be casted to an double.
      Parameters:
      path - path to node (dot notation)
      Returns:
      double or null
    • getDouble

      public double getDouble(String path, double def)
      Gets a double at a location. This will either return an double or the default value. If the object at the particular location is not actually a double, the default value will be returned. However, other number types will be casted to an double.
      Parameters:
      path - path to node (dot notation)
      def - default value
      Returns:
      double or default
    • getBoolean

      public Boolean getBoolean(String path)
      Gets a boolean at a location. This will either return an boolean or null. If the object at the particular location is not actually a boolean, the default value will be returned.
      Parameters:
      path - path to node (dot notation)
      Returns:
      boolean or null
    • getBoolean

      public boolean getBoolean(String path, boolean def)
      Gets a boolean at a location. This will either return an boolean or the default value. If the object at the particular location is not actually a boolean, the default value will be returned.
      Parameters:
      path - path to node (dot notation)
      def - default value
      Returns:
      boolean or default
    • getKeys

      public List<String> getKeys(String path)
      Get a list of keys at a location. If the map at the particular location does not exist or it is not a map, null will be returned.
      Parameters:
      path - path to node (dot notation)
      Returns:
      list of keys
    • getList

      public List<Object> getList(String path)
      Gets a list of objects at a location. If the list is not defined, null will be returned. The node must be an actual list.
      Parameters:
      path - path to node (dot notation)
      Returns:
      boolean or default
    • getStringList

      public List<String> getStringList(String path, List<String> def)
      Gets a list of strings. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. If an item in the list is not a string, it will be converted to a string. The node must be an actual list and not just a string.
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of strings
    • getIntList

      public List<Integer> getIntList(String path, List<Integer> def)
      Gets a list of integers. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. The node must be an actual list and not just an integer.
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of integers
    • getDoubleList

      public List<Double> getDoubleList(String path, List<Double> def)
      Gets a list of doubles. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. The node must be an actual list and cannot be just a double.
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of integers
    • getBooleanList

      public List<Boolean> getBooleanList(String path, List<Boolean> def)
      Gets a list of booleans. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. The node must be an actual list and cannot be just a boolean,
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of integers
    • getVectorList

      public List<Vector3> getVectorList(String path, List<Vector3> def)
      Gets a list of vectors. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. The node must be an actual node and cannot be just a vector,
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of integers
    • getVector2List

      public List<Vector2> getVector2List(String path, List<Vector2> def)
      Gets a list of 2D vectors. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. The node must be an actual node and cannot be just a vector,
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of integers
    • getBlockVector2List

      public List<BlockVector2> getBlockVector2List(String path, List<BlockVector2> def)
      Gets a list of 2D vectors. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. The node must be an actual node and cannot be just a vector,
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of integers
    • getNodeList

      public List<YAMLNode> getNodeList(String path, List<YAMLNode> def)
      Gets a list of nodes. Non-valid entries will not be in the list. There will be no null slots. If the list is not defined, the default will be returned. 'null' can be passed for the default and an empty list will be returned instead. The node must be an actual node and cannot be just a boolean,
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of integers
    • getNode

      @Nullable public YAMLNode getNode(String path)
      Get a configuration node at a path. If the node doesn't exist or the path does not lead to a node, null will be returned. A node has key/value mappings.
      Parameters:
      path - the path
      Returns:
      node or null
    • getNodes

      public Map<String,YAMLNode> getNodes(String path)
      Get a list of nodes at a location. If the map at the particular location does not exist or it is not a map, null will be returned.
      Parameters:
      path - path to node (dot notation)
      Returns:
      map of nodes
    • removeProperty

      public void removeProperty(String path)
      Remove the property at a location. This will override existing configuration data to have it conform to key/value mappings.
      Parameters:
      path - a path
    • writeDefaults

      public boolean writeDefaults()
    • setWriteDefaults

      public void setWriteDefaults(boolean writeDefaults)