From 5df5bb289cef719e9d9845ddca74b0174332d10a Mon Sep 17 00:00:00 2001 From: Daniel Orr Date: Thu, 3 Oct 2024 00:15:06 +0100 Subject: [PATCH 1/2] logDeletionFailure --- .../xyz/nucleoid/fantasy/RuntimeWorldManager.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java index 59f99b6..14b680a 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java +++ b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java @@ -57,7 +57,7 @@ RuntimeWorld add(RegistryKey worldKey, RuntimeWorldConfig config, Runtime return world; } - void delete(ServerWorld world) { + void delete(ServerWorld world, boolean logDeletionFailure) { RegistryKey dimensionKey = world.getRegistryKey(); if (this.serverAccess.getWorlds().remove(dimensionKey, world)) { @@ -72,7 +72,10 @@ void delete(ServerWorld world) { try { FileUtils.deleteDirectory(worldDirectory); } catch (IOException e) { - Fantasy.LOGGER.warn("Failed to delete world directory", e); + if (logDeletionFailure) { + Fantasy.LOGGER.warn("Failed to delete world directory", e); + } + try { FileUtils.forceDeleteOnExit(worldDirectory); } catch (IOException ignored) { @@ -82,6 +85,10 @@ void delete(ServerWorld world) { } } + void delete(ServerWorld world) { + this.delete(world, true); + } + void unload(ServerWorld world) { RegistryKey dimensionKey = world.getRegistryKey(); From 4a569731e9be5380b14eb2926d6ca4612110508d Mon Sep 17 00:00:00 2001 From: Daniel Orr Date: Thu, 3 Oct 2024 00:52:32 +0100 Subject: [PATCH 2/2] Move to static variable The previous method parameter was not accessible --- src/main/java/xyz/nucleoid/fantasy/Fantasy.java | 17 +++++++++++++++++ .../nucleoid/fantasy/RuntimeWorldManager.java | 8 ++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/xyz/nucleoid/fantasy/Fantasy.java b/src/main/java/xyz/nucleoid/fantasy/Fantasy.java index b1d171e..a05243c 100644 --- a/src/main/java/xyz/nucleoid/fantasy/Fantasy.java +++ b/src/main/java/xyz/nucleoid/fantasy/Fantasy.java @@ -49,6 +49,8 @@ public final class Fantasy { private final Set deletionQueue = new ReferenceOpenHashSet<>(); private final Set unloadingQueue = new ReferenceOpenHashSet<>(); + private static boolean logWorldDeletionFailure = true; + static { ServerTickEvents.START_SERVER_TICK.register(server -> { Fantasy fantasy = get(server); @@ -84,6 +86,21 @@ public static Fantasy get(MinecraftServer server) { return instance; } + /** + * Disables logging when a runtime world fails to delete. + * @see RuntimeWorldManager#delete(ServerWorld) + */ + public static void disableWorldDeletionFailureLog() { + Fantasy.logWorldDeletionFailure = false; + } + + /** + * Whether a warning should be logged when runtime world deletion fails. + */ + public static boolean shouldLogWorldDeletionFailure() { + return Fantasy.logWorldDeletionFailure; + } + private void tick() { Set deletionQueue = this.deletionQueue; if (!deletionQueue.isEmpty()) { diff --git a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java index 14b680a..7a82033 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java +++ b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java @@ -57,7 +57,7 @@ RuntimeWorld add(RegistryKey worldKey, RuntimeWorldConfig config, Runtime return world; } - void delete(ServerWorld world, boolean logDeletionFailure) { + void delete(ServerWorld world) { RegistryKey dimensionKey = world.getRegistryKey(); if (this.serverAccess.getWorlds().remove(dimensionKey, world)) { @@ -72,7 +72,7 @@ void delete(ServerWorld world, boolean logDeletionFailure) { try { FileUtils.deleteDirectory(worldDirectory); } catch (IOException e) { - if (logDeletionFailure) { + if (Fantasy.shouldLogWorldDeletionFailure()) { Fantasy.LOGGER.warn("Failed to delete world directory", e); } @@ -85,10 +85,6 @@ void delete(ServerWorld world, boolean logDeletionFailure) { } } - void delete(ServerWorld world) { - this.delete(world, true); - } - void unload(ServerWorld world) { RegistryKey dimensionKey = world.getRegistryKey();