Class JsonConfig


  • public class JsonConfig
    extends Object
    Used for JSON configuration files.
    • Constructor Detail

      • JsonConfig

        public JsonConfig​(File pluginDataFolder,
                          String name)
        Please notice that the constructor does not yet create the JSON configuration file. To create the file on the disk, use createConfig().
        Parameters:
        pluginDataFolder - The plugin's data directory, accessible with JavaPlugin#getDataFolder();
        name - The name of the config file excluding file extensions.
    • Method Detail

      • createConfig

        public void createConfig()
                          throws FileNotFoundException
        This creates the configuration file. If the data folder is invalid, it will be created along with the config file.
        Throws:
        FileNotFoundException - if the file is not found
      • getDirectory

        public File getDirectory()
        Returns:
        The configuration file's directory. To get its name, use getName() instead.
      • getName

        public String getName()
        This returns the name of the configuration file with the .json extension. To get the file's directory, use getDirectory().
        Returns:
        The name of the configuration file, including file extensions.
      • getFile

        public File getFile()
        This returns the actual File object of the config file.
        Returns:
        The config file.
      • deleteFile

        public void deleteFile()
        This deletes the config file.
      • deleteParentDir

        public void deleteParentDir()
        This deletes the config file's directory and all it's contents.
      • reset

        public void reset()
        This deletes and recreates the file, wiping all its contents.
      • wipeDirectory

        public void wipeDirectory()
        Wipe the config file's directory, including the file itself.
      • createSubDirectory

        public void createSubDirectory​(String name)
                                throws IOException
        This will create a sub-directory in the plugin's data folder, which can be accessed with getDirectory(). If the entered name is not a valid name for a directory or the sub-directory already exists or the data folder does not exist, an IOException will be thrown.
        Parameters:
        name - The sub directory's name.
        Throws:
        IOException - If the entered string has a file extension or already exists.
      • putInJsonObject

        public void putInJsonObject​(String k,
                                    com.google.gson.JsonElement v)
                             throws IOException,
                                    com.google.gson.JsonParseException
        Throws:
        IOException
        com.google.gson.JsonParseException
      • putInJsonObject

        public void putInJsonObject​(String k,
                                    String v)
                             throws IOException,
                                    com.google.gson.JsonParseException
        Throws:
        IOException
        com.google.gson.JsonParseException
      • putInJsonObject

        public void putInJsonObject​(String k,
                                    int v)
                             throws IOException,
                                    com.google.gson.JsonParseException
        Throws:
        IOException
        com.google.gson.JsonParseException
      • removeFromJsonObject

        public void removeFromJsonObject​(String key)
                                  throws IOException
        Remove a key-value from the JSONObject inside getFile().
        Parameters:
        key - The key.
        Throws:
        IOException - Thrown when the file cannot be found.