Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Option to Disable Warning Log for Failed World Deletion #60

Open
wants to merge 2 commits into
base: 1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/xyz/nucleoid/fantasy/Fantasy.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public final class Fantasy {
private final Set<ServerWorld> deletionQueue = new ReferenceOpenHashSet<>();
private final Set<ServerWorld> unloadingQueue = new ReferenceOpenHashSet<>();

private static boolean logWorldDeletionFailure = true;

static {
ServerTickEvents.START_SERVER_TICK.register(server -> {
Fantasy fantasy = get(server);
Expand Down Expand Up @@ -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<ServerWorld> deletionQueue = this.deletionQueue;
if (!deletionQueue.isEmpty()) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 (Fantasy.shouldLogWorldDeletionFailure()) {
Fantasy.LOGGER.warn("Failed to delete world directory", e);
}

try {
FileUtils.forceDeleteOnExit(worldDirectory);
} catch (IOException ignored) {
Expand Down