Class Files

java.lang.Object
net.lewmc.foundry.Files

public class Files extends Object
File Utility.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Files(FoundryConfig config, org.bukkit.plugin.java.JavaPlugin plugin)
    The constructor for the Files class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Closes the configuration file without saving it.
    boolean
    create(String path)
    Creates a file.
    boolean
    delete(String path)
    Deletes a file.
    boolean
    exists(String path)
    Checks if a file exists.
    get(String key)
    Gets an object from the configuration file.
    boolean
    Gets a boolean from the configuration file.
    double
    Gets a double from the configuration file.
    int
    Gets an integer from the configuration file.
    getKeys(boolean deep)
    Gets a List from the configuration file if is root.
    getKeys(String section, boolean deep)
    Gets a List from the configuration file if not root.
    Gets a string from the configuration file.
    Gets a String List from the configuration file.
    boolean
    Checks if a file is open.
    boolean
    load(String path)
    Opens a configuration file.
    boolean
    Opens a configuration file from root (without checking format).
    Return the location of the player's data file from the player's UUID.
    playerDataFile(org.bukkit.entity.Player player)
    Return the location of the player's data file from an instance of the player.
    boolean
    Removes a key and it's associated data.
    boolean
    Saves and closes the current configuration file.
    boolean
    save(File file)
    Saves and closes the current configuration file to a custom location.
    boolean
    set(String key, Object value)
    Sets a value in the configuration file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Files

      public Files(FoundryConfig config, org.bukkit.plugin.java.JavaPlugin plugin)
      The constructor for the Files class.
      Parameters:
      plugin - Reference to the main plugin class.
  • Method Details

    • create

      public boolean create(String path)
      Creates a file.
      Parameters:
      path - String - Path to the file.
      Returns:
      boolean - If the file and directories (if required) were created successfully.
    • exists

      public boolean exists(String path)
      Checks if a file exists.
      Parameters:
      path - - Path to the file.
      Returns:
      boolean - If the file exists
    • load

      public boolean load(String path)
      Opens a configuration file.
      Parameters:
      path - String - Path to the file
      Returns:
      boolean - If the operation was successful
    • loadNoReformat

      public boolean loadNoReformat(File file)
      Opens a configuration file from root (without checking format).
      Parameters:
      file - File - Instance of the file.
      Returns:
      boolean - If the operation was successful
    • delete

      public boolean delete(String path)
      Deletes a file.
      Parameters:
      path - String - The path of the file
      Returns:
      boolean - If the operation was successful
    • save

      public boolean save(File file)
      Saves and closes the current configuration file to a custom location.
      Parameters:
      file - String - The file.
      Returns:
      boolean - If the operation was successful
    • save

      public boolean save()
      Saves and closes the current configuration file.
      Returns:
      boolean - If the operation was successful
    • set

      public boolean set(String key, Object value)
      Sets a value in the configuration file.
      Parameters:
      key - The location of the value.
      value - The value to set.
      Returns:
      boolean - If the operation was successful
    • get

      public Object get(String key)
      Gets an object from the configuration file.
      Parameters:
      key - The location of the value.
      Returns:
      Object - the value.
    • getBoolean

      public boolean getBoolean(String key)
      Gets a boolean from the configuration file.
      Parameters:
      key - The location of the value.
      Returns:
      boolean - the value.
    • getString

      public String getString(String key)
      Gets a string from the configuration file.
      Parameters:
      key - The location of the value.
      Returns:
      String - the value.
    • getInt

      public int getInt(String key)
      Gets an integer from the configuration file.
      Parameters:
      key - The location of the value.
      Returns:
      int - the value.
    • getDouble

      public double getDouble(String key)
      Gets a double from the configuration file.
      Parameters:
      key - The location of the value.
      Returns:
      double - the value.
    • getStringList

      public List<String> getStringList(String key)
      Gets a String List from the configuration file.
      Parameters:
      key - The location of the value.
      Returns:
      List - the value.
    • getKeys

      public Set<String> getKeys(boolean deep)
      Gets a List from the configuration file if is root.
      Parameters:
      deep - Should do deep search?
      Returns:
      List - the value.
    • getKeys

      public Set<String> getKeys(String section, boolean deep)
      Gets a List from the configuration file if not root.
      Parameters:
      section - The section of the file.
      deep - Should do deep search?
      Returns:
      List - the value.
    • close

      public boolean close()
      Closes the configuration file without saving it. Not needed if save() has been used.
      Returns:
      boolean - If the operation was successful
    • isOpen

      public boolean isOpen()
      Checks if a file is open.
      Returns:
      boolean - If a file is open
    • playerDataFile

      public String playerDataFile(org.bukkit.entity.Player player)
      Return the location of the player's data file from an instance of the player.
      Parameters:
      player - Player - The player.
      Returns:
      The data file URI inside the /plugin/essence folder.
    • playerDataFile

      public String playerDataFile(UUID uuid)
      Return the location of the player's data file from the player's UUID.
      Parameters:
      uuid - UUID - The player's UUID.
      Returns:
      The data file URI inside the /plugin/essence folder.
    • remove

      public boolean remove(String key)
      Removes a key and it's associated data.
      Parameters:
      key - String - The item to remove.
      Returns:
      If the operation was successful