Class FileUtil

java.lang.Object
net.lewmc.essence.utils.FileUtil

public class FileUtil extends Object
Essence File Utility.
  • Constructor Details

    • FileUtil

      public FileUtil(Essence plugin)
      The constructor for the FileUtil class.
      Parameters:
      plugin - Reference to the main Essence 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