Class Configuration

java.lang.Object
com.welcome234.pluginsystem.Configuration

public class Configuration extends Object
Configurations are provided as a simple way to store plugin data

This provided configuration system is basic, but plugins can use a more complex configuration library

Default configurations can also be provided

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Gets the boolean value at the key
    double
    getDouble​(String key)
    Gets the double value at the key
    float
    getFloat​(String key)
    Gets the float value at the key
    int
    Gets the integer value at the key
    Gets all keys set in this configuration
    long
    getLong​(String key)
    Gets the long value at the key
    getString​(String key)
    Gets the string value at the key
    boolean
    isSet​(String key)
    Checks if the key is set
    void
    Reloads this configuration from the disk
    void
    Saves this configuration to the disk
    void
    Saves the default configuration to the disk
    void
    set​(String key, boolean value)
    Sets the key to the specified boolean value
    void
    set​(String key, double value)
    Sets the key to the specified double value
    void
    set​(String key, float value)
    Sets the key to the specified float value
    void
    set​(String key, int value)
    Sets the key to the specified integer value
    void
    set​(String key, long value)
    Sets the key to the specified long value
    void
    set​(String key, String value)
    Sets the key to the specified string value

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • saveDefault

      public void saveDefault()
      Saves the default configuration to the disk
      Throws:
      IllegalStateException - if the default configuration does not exist or is unreadable
      IllegalStateException - if the plugin is disabled or is not loaded
    • save

      public void save()
      Saves this configuration to the disk
      Throws:
      IllegalStateException - if the plugin is disabled or is not loaded
    • reload

      public void reload()
      Reloads this configuration from the disk
      Throws:
      IllegalStateException - if the plugin is disabled or is not loaded
    • set

      public void set(String key, String value)
      Sets the key to the specified string value

      If the value is set to null, the key will be removed or reset to the default value

      Parameters:
      key - Key name
      value - String value
      Throws:
      IllegalArgumentException - if key is null
    • set

      public void set(String key, boolean value)
      Sets the key to the specified boolean value
      Parameters:
      key - Key name
      value - Boolean value
      Throws:
      IllegalArgumentException - if key is null
    • set

      public void set(String key, int value)
      Sets the key to the specified integer value
      Parameters:
      key - Key name
      value - Integer value
      Throws:
      IllegalArgumentException - if key is null
    • set

      public void set(String key, long value)
      Sets the key to the specified long value
      Parameters:
      key - Key name
      value - Long value
      Throws:
      IllegalArgumentException - if key is null
    • set

      public void set(String key, float value)
      Sets the key to the specified float value
      Parameters:
      key - Key name
      value - Float value
      Throws:
      IllegalArgumentException - if key is null
    • set

      public void set(String key, double value)
      Sets the key to the specified double value
      Parameters:
      key - Key name
      value - Double value
      Throws:
      IllegalArgumentException - if key is null
    • getString

      public String getString(String key)
      Gets the string value at the key
      Parameters:
      key - Key name
      Returns:
      String value
      Throws:
      IllegalArgumentException - if key is null
    • getBoolean

      public boolean getBoolean(String key)
      Gets the boolean value at the key
      Parameters:
      key - Key name
      Returns:
      Boolean value, or false if not a valid boolean
      Throws:
      IllegalArgumentException - if key is null
    • getInteger

      public int getInteger(String key)
      Gets the integer value at the key
      Parameters:
      key - Key name
      Returns:
      Integer value, or 0 if not a valid integer
      Throws:
      IllegalArgumentException - if key is null
    • getLong

      public long getLong(String key)
      Gets the long value at the key
      Parameters:
      key - Key name
      Returns:
      Long value, or 0 if not a valid long
      Throws:
      IllegalArgumentException - if key is null
    • getFloat

      public float getFloat(String key)
      Gets the float value at the key
      Parameters:
      key - Key name
      Returns:
      Float value, or 0 if not a valid float
      Throws:
      IllegalArgumentException - if key is null
    • getDouble

      public double getDouble(String key)
      Gets the double value at the key
      Parameters:
      key - Key name
      Returns:
      Double value, or 0 if not a valid double
      Throws:
      IllegalArgumentException - if key is null
    • getKeys

      public String[] getKeys()
      Gets all keys set in this configuration
      Returns:
      Keys names in this configuration
    • isSet

      public boolean isSet(String key)
      Checks if the key is set
      Parameters:
      key - Key name
      Returns:
      Whether set
      Throws:
      IllegalArgumentException - if key is null