From 38dd0018e75e6e90c7aa34fb75eac0d4ebca1f2e Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:48:51 +0800 Subject: [PATCH] Fix and refactor cloneWorld hasWorldFolder check --- .../multiverse/core/world/WorldManager.java | 13 ++++--------- .../multiverse/core/world/WorldNameChecker.java | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java index b46ec662..a94e2f29 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java @@ -185,17 +185,12 @@ public class WorldManager { return worldActionResult(CreateFailureReason.WORLD_EXIST_LOADED, options.worldName()); } else if (getWorld(options.worldName()).isDefined()) { return worldActionResult(CreateFailureReason.WORLD_EXIST_UNLOADED, options.worldName()); - } else if (hasWorldFolder(options.worldName())) { + } else if (worldNameChecker.hasWorldFolder(options.worldName())) { return worldActionResult(CreateFailureReason.WORLD_EXIST_FOLDER, options.worldName()); } return worldActionResult(options); } - private boolean hasWorldFolder(String worldName) { - File worldFolder = new File(Bukkit.getWorldContainer(), worldName); - return worldFolder.exists(); - } - private Attempt createValidatedWorld( CreateWorldOptions options) { String parsedGenerator = parseGenerator(options.worldName(), options.generator()); @@ -530,9 +525,6 @@ public class WorldManager { Logging.severe("Invalid world name: " + newWorldName); return worldActionResult(CloneFailureReason.INVALID_WORLDNAME, newWorldName); } - if (worldNameChecker.isValidWorldFolder(newWorldName)) { - return worldActionResult(CloneFailureReason.WORLD_EXIST_FOLDER, newWorldName); - } if (isLoadedWorld(newWorldName)) { Logging.severe("World already loaded when attempting to clone: " + newWorldName); return worldActionResult(CloneFailureReason.WORLD_EXIST_LOADED, newWorldName); @@ -541,6 +533,9 @@ public class WorldManager { Logging.severe("World already exist unloaded: " + newWorldName); return worldActionResult(CloneFailureReason.WORLD_EXIST_UNLOADED, newWorldName); } + if (worldNameChecker.hasWorldFolder(newWorldName)) { + return worldActionResult(CloneFailureReason.WORLD_EXIST_FOLDER, newWorldName); + } return worldActionResult(options); } diff --git a/src/main/java/org/mvplugins/multiverse/core/world/WorldNameChecker.java b/src/main/java/org/mvplugins/multiverse/core/world/WorldNameChecker.java index 65d86fd4..e8801baf 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/WorldNameChecker.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/WorldNameChecker.java @@ -55,7 +55,17 @@ public class WorldNameChecker { } /** - * Checks if a world name has a valid world folder. + * Check if a world name has a world folder directory. It may not contain valid world data. + * + * @param worldName The world name to check on. + * @return True if the folder exists, else false. + */ + public boolean hasWorldFolder(@Nullable String worldName) { + return checkFolder(worldName) != FolderStatus.DOES_NOT_EXIST; + } + + /** + * Checks if a world name has a valid world folder with basic world data. * * @param worldName The world name to check on. * @return True if check result is valid, else false. @@ -65,7 +75,7 @@ public class WorldNameChecker { } /** - * Checks if a world folder is valid. + * Checks if a world folder is valid with basic world data. * * @param worldFolder The world folder to check on. * @return True if check result is valid, else false.