Class FileUtils

java.lang.Object
ua.mcchickenstudio.opencreative.utils.FileUtils

public final class FileUtils extends Object

FileUtils

This class contains utils for creating, reading, modifying and removing files for worlds.
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • createWorldSettings

      public static void createWorldSettings(int id, @NotNull @NotNull org.bukkit.entity.Player owner, @NotNull org.bukkit.World.Environment environment, @NotNull @NotNull String generatorID)
      Creates planet's settings.yml file.
      Parameters:
      id - Planet's ID.
      owner - Owner of new world.
      environment - Environment of world.
      generatorID - ID of world generator.
    • fillDefaultSettings

      public static void fillDefaultSettings(@NotNull @NotNull org.bukkit.configuration.file.FileConfiguration config, int id, @NotNull @NotNull org.bukkit.entity.Player owner, @NotNull org.bukkit.World.Environment environment, @NotNull @NotNull String generatorID)
      Fills world's settings configuration with default values.
      Parameters:
      config - settings configuration.
      id - world's id.
      owner - world's owner.
      environment - environment on world creation.
    • createCodeScript

      public static void createCodeScript(@NotNull @NotNull String path, @NotNull @NotNull String worldName)
      Creates planet's codeScript.yml file.
    • loadLocales

      public static void loadLocales()
      Loads localization file from OpenCreative/locales/ folder. If no localization file was found, then it creates a new one.
    • resetLocales

      public static void resetLocales()
      Resets localization file from OpenCreative/locales/ folder. If localization file is detected in folder, then it will be removed and replaced with plugin's new one.
    • loadPlanets

      public static void loadPlanets()
      Loads all planets to base.
    • loadModules

      public static void loadModules()
      Loads all modules to base.
    • getDefaultConfig

      @NotNull public static @NotNull org.bukkit.configuration.file.YamlConfiguration getDefaultConfig()
    • getPlanetFolder

      public static File getPlanetFolder(Planet planet)
      Returns planet's folder, that stores planet's build world data, settings, script and players data.
      Parameters:
      planet - planet to get folder.
      Returns:
      planet's folder.
    • getDevPlanetFolder

      public static File getDevPlanetFolder(DevPlanet devPlanet)
      Returns development planet's folder. It contains world's map.
    • getPlanetConfig

      public static org.bukkit.configuration.file.FileConfiguration getPlanetConfig(Planet planet)
      Returns planet's settings.yml configuration.
    • getPlanetConfigFile

      public static File getPlanetConfigFile(Planet planet)
      Returns planet's settings.yml file.
    • getPlanetScriptFile

      public static File getPlanetScriptFile(Planet planet)
      Returns planet's codeScript.yml file.
    • getPlanetVariablesJson

      public static File getPlanetVariablesJson(Planet planet)
      Returns planet's variables.yml configuration.
    • getWanderJsonFile

      @Nullable public static @Nullable File getWanderJsonFile(@NotNull @NotNull OfflineWander wander, boolean create)
      Returns wanders file with his data, located in ./wanders/UUID.json.
      Parameters:
      wander - wander to get data.
      create - create file if it doesn't exist.
      Returns:
      file - if exists, otherwise - null.
    • getPlayerDataJson

      @Nullable public static @Nullable File getPlayerDataJson(@NotNull @NotNull Planet planet, @NotNull @NotNull org.bukkit.entity.Player player)
      Returns player's data json from planet folder.
    • getWorldsFolders

      public static File[] getWorldsFolders()
      Returns folders of all planets worlds.
      Returns:
      planets worlds folders.
    • getModulesFiles

      public static File[] getModulesFiles()
      Returns folders of all modules yaml files.
      Returns:
      modules files.
    • convertOldPlanetFolders

      public static void convertOldPlanetFolders()
      Returns folders of planets worlds that are stored in server container or /unloadedWorlds/ folder.
    • isOpenCreativeWorldFolder

      public static boolean isOpenCreativeWorldFolder(@NotNull @NotNull File folder)
      Checks whether specified folder has similar OpenCreative+ files.
      Parameters:
      folder - folder to check.
      Returns:
      true - it's OpenCreative+ folder, false - not.
    • convertOldPlanetFolder

      public static boolean convertOldPlanetFolder(File folder)
      Returns a new renamed folder if planet is "plot", otherwise it will return same folder.
      Parameters:
      folder - planet folder to convert.
      Returns:
      renamed or same planet folder.
    • isPlanetFolder

      public static boolean isPlanetFolder(File folder)
      Checks if specified folder is directory of planet world.
      Parameters:
      folder - folder to check.
      Returns:
      true - if folder is planet world, false - not.
    • unloadPlanets

      public static void unloadPlanets()
      Unloads all loaded planets worlds.
    • copyFilesToDirectory

      public static boolean copyFilesToDirectory(File input, File output)
      Copies input files into output directory.
    • deleteUnnecessaryWorldFiles

      public static void deleteUnnecessaryWorldFiles(File worldFolder)
      Deletes Minecraft files, that are interrupting world copying process.
      Parameters:
      worldFolder - folder of world.
    • deleteWorldFoldersInPlugins

      public static void deleteWorldFoldersInPlugins(int planetId)
      Deletes world folders from other plugins.
      Parameters:
      planetId - id of planet.
    • deleteFolder

      public static void deleteFolder(File directory)
      Deletes directory and files inside it, if exists.
      Parameters:
      directory - path of directory.
    • setPlanetConfigParameter

      public static void setPlanetConfigParameter(Planet planet, String parameterPath, long parameterValue)
      Sets parameter to Long value in planet's settings.
      Parameters:
      planet - planet to set.
      parameterPath - path of parameter in config.
      parameterValue - value.
    • removePlanetConfigParameter

      public static void removePlanetConfigParameter(Planet planet, String parameterPath)
      Removes parameter from planet's config.
      Parameters:
      planet - planet to set.
      parameterPath - path of parameter in config.
    • setPlanetConfigParameter

      public static void setPlanetConfigParameter(Planet planet, String parameterPath, int parameterValue)
      Sets parameter to Int value in planet's settings.
      Parameters:
      planet - planet to set.
      parameterPath - path of parameter in config.
      parameterValue - value.
    • setPlanetConfigParameter

      public static void setPlanetConfigParameter(Planet planet, String parameterPath, Object parameterValue)
      Sets parameter to Object value in planet's settings.
      Parameters:
      planet - planet to set.
      parameterPath - path of parameter in config.
      parameterValue - value.
    • setModuleConfigParameter

      public static void setModuleConfigParameter(Module module, String parameterPath, Object parameterValue)
      Sets parameter to Object value in module's settings.
      Parameters:
      module - module to set.
      parameterPath - path of parameter in config.
      parameterValue - value.
    • setPlanetConfigParameter

      public static void setPlanetConfigParameter(Planet planet, String parameterPath, String parameterValue)
      Sets parameter to String value in planet's settings.
      Parameters:
      planet - planet to set.
      parameterPath - path of parameter in config.
      parameterValue - value.
    • setPlanetConfigParameter

      public static void setPlanetConfigParameter(Planet planet, String parameterPath, List<String> parameterValue)
      Sets parameter to List value in planet's settings.
      Parameters:
      planet - planet to set.
      parameterPath - path of parameter in config.
      parameterValue - value.
    • setPlanetConfigParameter

      public static void setPlanetConfigParameter(Planet planet, String parameterPath, Set<String> parameterValue)
      Sets parameter to Set value in planet's settings.
      Parameters:
      planet - planet to set.
      parameterPath - path of parameter in config.
      parameterValue - value.
    • getPlayersFromPlanetList

      public static List<String> getPlayersFromPlanetList(Planet planet, Planet.PlayersType type)
      Returns a specified list of players nicknames.
      Parameters:
      planet - planet to get list.
      type - type of players list.
      Returns:
      list of nicknames.
    • addPlayerInPlanetList

      public static boolean addPlayerInPlanetList(Planet planet, String nickname, Planet.PlayersType type)
      Adds player to list, that located in planet's settings.yml file.
      Parameters:
      planet - planet to add player.
      nickname - nickname of player.
      type - id of player list.
      Returns:
      true - if successfully added, false - if failed.
    • getFolderSize

      public static long getFolderSize(File file)
      Returns size of folder.
      Parameters:
      file - folder to get size.
      Returns:
      size of folder.
    • getModuleConfig

      public static CodeConfiguration getModuleConfig(Module module)
      Returns module's configuration.
    • getModuleConfigFile

      public static File getModuleConfigFile(int id)
      Returns module's config file.
      Returns:
      file of module's config.
    • getModulesStorageFolder

      public static File getModulesStorageFolder()
      Returns folder that stores all modules folders.
      Returns:
      modules folder.
    • getFileSize

      public static long getFileSize(File file)
      Returns size of file.
      Parameters:
      file - file to get size.
      Returns:
      size of file.
    • getTempFolder

      public static File getTempFolder()
      Returns temporary folder, that stores temporary files.
      Returns:
      temporary folder.
    • getPlanetFolderPath

      public static String getPlanetFolderPath(int id)
      Returns file path of planet's world folder.
      Parameters:
      id - planet to get folder.
      Returns:
      planet's folder path.
    • getDevPlanetFolderPath

      public static String getDevPlanetFolderPath(int id)
      Returns file path of dev planet's world folder.
      Parameters:
      id - planet to get folder.
      Returns:
      dev planet's folder path.
    • getPlanetsStorageFolder

      public static File getPlanetsStorageFolder()
      Returns folder that stores all planets folders.
      Returns:
      planets folder.
    • getWandersStorageFolder

      public static File getWandersStorageFolder()
      Returns folder that stores all wanders folders.
      Returns:
      wanders folder.
    • getPlanetIdFromName

      @NotNull public static @NotNull String getPlanetIdFromName(@NotNull @NotNull String name)
      Returns planet's ID without other symbols.
      Parameters:
      name - name of planet's folder.
      Returns:
      planet's ID.
    • usingNewWorldsContainer

      public static boolean usingNewWorldsContainer()
      Checks whether plugin should store all worlds in /world/dimensions/minecraft/planets folder (from 26.1+) instead of /planets/ folder (1.21.x).
      Returns:
      true - planets will be saved in /world/dimensions/minecraft/planets/, false - planets will be saved in /planets/.