Class ConfigValueImpl

All Implemented Interfaces:
ConfigTag, ConfigValue

public class ConfigValueImpl extends AbstractConfigTag<ConfigValue> implements ConfigValue
TODO do we want to explode if someone tires to set a value when it is set from the network?

Created by covers1624 on 18/4/22.

  • Constructor Details

  • Method Details

    • getType

      public ValueType getType()
      Description copied from interface: ConfigValue
      Gets the type of the ConfigValue.
      Specified by:
      getType in interface ConfigValue
      Returns:
      The ValueType of this tag.
    • getBoolean

      public boolean getBoolean()
      Description copied from interface: ConfigValue
      Gets the boolean value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getBoolean in interface ConfigValue
      Returns:
      The boolean value or the default.
    • getString

      public String getString()
      Description copied from interface: ConfigValue
      Gets the String value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getString in interface ConfigValue
      Returns:
      The String value or the default.
    • getInt

      public int getInt()
      Description copied from interface: ConfigValue
      Gets the int value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getInt in interface ConfigValue
      Returns:
      The int value or the default.
    • getLong

      public long getLong()
      Description copied from interface: ConfigValue
      Gets the long value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getLong in interface ConfigValue
      Returns:
      The long value or the default.
    • getHex

      public int getHex()
      Description copied from interface: ConfigValue
      Gets the int value stored as a Hex String of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getHex in interface ConfigValue
      Returns:
      The int value or the default.
    • getDouble

      public double getDouble()
      Description copied from interface: ConfigValue
      Gets the double value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getDouble in interface ConfigValue
      Returns:
      The double value or the default.
    • setBoolean

      public ConfigValue setBoolean(boolean value)
      Description copied from interface: ConfigValue
      Sets the boolean value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setBoolean in interface ConfigValue
      Parameters:
      value - The boolean value.
      Returns:
      The same ConfigValue.
    • setString

      public ConfigValue setString(String value)
      Description copied from interface: ConfigValue
      Sets the String value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setString in interface ConfigValue
      Parameters:
      value - The String value.
      Returns:
      The same ConfigValue.
    • setInt

      public ConfigValue setInt(int value)
      Description copied from interface: ConfigValue
      Sets the int value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setInt in interface ConfigValue
      Parameters:
      value - The int value.
      Returns:
      The same ConfigValue.
    • setLong

      public ConfigValue setLong(long value)
      Description copied from interface: ConfigValue
      Sets the long value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setLong in interface ConfigValue
      Parameters:
      value - The long value.
      Returns:
      The same ConfigValue.
    • setHex

      public ConfigValue setHex(int value)
      Description copied from interface: ConfigValue
      Sets the int value represented as a hex String of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setHex in interface ConfigValue
      Parameters:
      value - The int value.
      Returns:
      The same ConfigValue.
    • setDouble

      public ConfigValue setDouble(double value)
      Description copied from interface: ConfigValue
      Sets the double value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setDouble in interface ConfigValue
      Parameters:
      value - The double value.
      Returns:
      The same ConfigValue.
    • getDefaultBoolean

      public boolean getDefaultBoolean()
      Description copied from interface: ConfigValue
      Gets the default boolean value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getDefaultBoolean in interface ConfigValue
      Returns:
      The default boolean value.
    • getDefaultString

      public String getDefaultString()
      Description copied from interface: ConfigValue
      Gets the default String value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getDefaultString in interface ConfigValue
      Returns:
      The default String value.
    • getDefaultInt

      public int getDefaultInt()
      Description copied from interface: ConfigValue
      Gets the default int value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getDefaultInt in interface ConfigValue
      Returns:
      The default int value.
    • getDefaultLong

      public long getDefaultLong()
      Description copied from interface: ConfigValue
      Gets the default long value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getDefaultLong in interface ConfigValue
      Returns:
      The default long value.
    • getDefaultHex

      public int getDefaultHex()
      Description copied from interface: ConfigValue
      Gets the default int value stored as a Hex String of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getDefaultHex in interface ConfigValue
      Returns:
      The default int value.
    • getDefaultDouble

      public double getDefaultDouble()
      Description copied from interface: ConfigValue
      Gets the default double value of this tag.

      No attempt to convert between tag types is made, this must be called on a tag which has a non ValueType.UNKNOWN type.

      Specified by:
      getDefaultDouble in interface ConfigValue
      Returns:
      The default double value.
    • setDefaultBoolean

      public ConfigValue setDefaultBoolean(boolean value)
      Description copied from interface: ConfigValue
      Sets the default boolean value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setDefaultBoolean in interface ConfigValue
      Parameters:
      value - The boolean value.
      Returns:
      The same ConfigValue.
    • setDefaultString

      public ConfigValue setDefaultString(String value)
      Description copied from interface: ConfigValue
      Sets the default String value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setDefaultString in interface ConfigValue
      Parameters:
      value - The String value.
      Returns:
      The same ConfigValue.
    • setDefaultInt

      public ConfigValue setDefaultInt(int value)
      Description copied from interface: ConfigValue
      Sets the default int value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setDefaultInt in interface ConfigValue
      Parameters:
      value - The int value.
      Returns:
      The same ConfigValue.
    • setDefaultLong

      public ConfigValue setDefaultLong(long value)
      Description copied from interface: ConfigValue
      Sets the default long value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setDefaultLong in interface ConfigValue
      Parameters:
      value - The long value.
      Returns:
      The same ConfigValue.
    • setDefaultHex

      public ConfigValue setDefaultHex(int value)
      Description copied from interface: ConfigValue
      Sets the default int value represented as a hex String of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setDefaultHex in interface ConfigValue
      Parameters:
      value - The int value.
      Returns:
      The same ConfigValue.
    • setDefaultDouble

      public ConfigValue setDefaultDouble(double value)
      Description copied from interface: ConfigValue
      Sets the default double value of this tag.

      If the tag has an ValueType.UNKNOWN value type, this function will set it appropriately.

      Specified by:
      setDefaultDouble in interface ConfigValue
      Parameters:
      value - The double value.
      Returns:
      The same ConfigValue.
    • setRestriction

      public ConfigValue setRestriction(Restriction restriction)
      Description copied from interface: ConfigValue
      Set the Restriction for this ConfigValue.

      A restriction is just a Predicate, and can be used for anything, but is most commonly used for int/float value ranges on tags.

      If the restriction is violated, either by the tag being loaded from disk, or via a set method, it will be reset to default.

      TODO, in the future, provide a function to choose what to do when a value is invalid, allow the value to be altered (clamped), removed, or reset entirely to default. It is invalid for the restriction to not accept the tag's default value, if the restriction does not, it will throw an IllegalArgumentException either when the restriction is set, or the default is set, whichever comes last.

      See Restriction for more information.

      Specified by:
      setRestriction in interface ConfigValue
      Parameters:
      restriction - The restriction to set.
      Returns:
      The same ConfigValue.
      See Also:
    • getRestriction

      @Nullable public @Nullable Restriction getRestriction()
      Description copied from interface: ConfigValue
      Gets the Restriction predicate for this tag.
      Specified by:
      getRestriction in interface ConfigValue
      Returns:
      The Restriction
    • reset

      public void reset()
      Description copied from interface: ConfigTag
      Reset this tag back to the default.

      In the event that this is a ConfigCategory sets all descendant values to their default.

      Specified by:
      reset in interface ConfigTag
    • copy

      public AbstractConfigTag<ConfigValue> copy(@Nullable @Nullable ConfigCategoryImpl parent)
      Specified by:
      copy in class AbstractConfigTag<ConfigValue>
    • write

      public void write(MCDataOutput out)
      Description copied from interface: ConfigTag
      Write this tag to a MCDataOutput. Only categories and/or tags which have ConfigTag.syncTagToClient() set will be written.
      Specified by:
      write in interface ConfigTag
      Parameters:
      out - The output stream.
    • read

      public void read(MCDataInput in)
      Description copied from interface: ConfigTag
      Read this tag from a MCDataInput. All tags and values will be read and inserted into the tree.

      If a tag does not already exist in the tree, one will be added and marked as a 'network tag', ConfigTag.isNetworkTag().

      All tags with a network value will be reset to default when ConfigTag.resetFromNetwork() is called, whilst any 'network only' tags will be deleted.

      Specified by:
      read in interface ConfigTag
      Parameters:
      in - The input stream.
    • resetFromNetwork

      public void resetFromNetwork()
      Description copied from interface: ConfigTag
      Resets all network tags back to their original value.

      Whilst a tag is set from the network, it is effectively immutable and may not be set.

      Any tags which are 'network only' are deleted during this operation.

      Specified by:
      resetFromNetwork in interface ConfigTag
    • setValue

      public ConfigValue setValue(Object value)
    • setDefaultValue

      public ConfigValue setDefaultValue(Object value)
    • getRawValue

      public Object getRawValue()
    • setKnownType

      public void setKnownType(ValueType type)