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 a 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 a 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 a 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 a 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 a 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 an 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 an 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:
      Integer or default
    • getDouble

      public Double getDouble(String path)
      Gets a double at a location. This will either return a 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 a 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 a 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 a 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 a 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 a 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 Doubles
    • 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 Booleans
    • 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 vectors
    • 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 vectors
    • 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 vectors
    • 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 YAMLNode.
      Parameters:
      path - path to node (dot notation)
      def - default value or null for an empty list as default
      Returns:
      list of nodes
    • 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)