From 1e8e6f4dc0f4adb5174fa4d6e4afb41f9c860215 Mon Sep 17 00:00:00 2001 From: creatorfromhell Date: Sun, 3 Dec 2023 12:21:39 -0500 Subject: [PATCH] Fix unloaded checker, check for level.dat existence to validate that it is a world folder. --- src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java | 7 +------ .../commands/phantomworlds/sub/ListCommand.java | 5 ++++- .../me/lokka30/phantomworlds/managers/WorldManager.java | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java index 2f89630..b4e4c96 100644 --- a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java +++ b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java @@ -2,10 +2,8 @@ import me.lokka30.microlib.files.YamlConfigFile; import me.lokka30.microlib.maths.QuickTimer; -import me.lokka30.microlib.messaging.MultiMessage; import me.lokka30.microlib.other.UpdateChecker; import me.lokka30.phantomworlds.commands.phantomworlds.PWCommand; -import me.lokka30.phantomworlds.commands.phantomworlds.PhantomWorldsCommand; import me.lokka30.phantomworlds.commands.phantomworlds.parameters.resolvers.WorldFolderResolver; import me.lokka30.phantomworlds.commands.phantomworlds.parameters.suggestion.WorldFolderSuggestion; import me.lokka30.phantomworlds.commands.phantomworlds.utils.WorldFolder; @@ -13,12 +11,10 @@ import me.lokka30.phantomworlds.listeners.player.PlayerDeathListener; import me.lokka30.phantomworlds.listeners.player.PlayerJoinListener; import me.lokka30.phantomworlds.listeners.player.PlayerPortalListener; -import me.lokka30.phantomworlds.listeners.world.WorldInitListener; import me.lokka30.phantomworlds.managers.FileManager; import me.lokka30.phantomworlds.managers.WorldManager; import me.lokka30.phantomworlds.misc.CompatibilityChecker; import me.lokka30.phantomworlds.misc.UpdateCheckerResult; -import me.lokka30.phantomworlds.misc.Utils; import me.lokka30.phantomworlds.scheduler.BackupScheduler; import org.bstats.bukkit.Metrics; import org.bukkit.ChatColor; @@ -27,7 +23,6 @@ import revxrsal.commands.bukkit.BukkitCommandHandler; import java.io.File; -import java.util.ArrayList; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -40,7 +35,7 @@ public class PhantomWorlds extends JavaPlugin { /* - TODO: + *TODO: * - Translate backslash character in world names as a space so world names with a space can be used in the plugin * - Vanish compatibility * - don't send 'by' messages unless the sender is not a player / target can see the (player) sender diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ListCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ListCommand.java index 143cd59..62ecec8 100644 --- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ListCommand.java +++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ListCommand.java @@ -68,7 +68,10 @@ public static void onCommand(final BukkitCommandActor actor) { for(File file : directory.listFiles()) { if(file.isDirectory() && !loaded.contains(file.getName())) { - unloaded.add(file.getName()); + final File levelDat = new File(file, "level.dat"); + if(levelDat.exists()) { + unloaded.add(file.getName()); + } } } diff --git a/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java b/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java index 89e453d..ef67a51 100644 --- a/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java +++ b/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java @@ -80,7 +80,8 @@ public WorldLoadResponse loadWorld(final String worldName) { } final File worldFolder = new File(Bukkit.getWorldContainer(), worldName); - if(!worldFolder.exists()) { + final File levelDat = new File(worldFolder, "level.dat"); + if(!worldFolder.exists() || !levelDat.exists()) { // The world was deleted/moved by the user so it must be re-imported. PW should no longer attempt to load that world. PhantomWorlds.logger().info("Discarding world '" + worldName + "' from PhantomWorlds' "