From 75800d61cf22442d4d1bc93c1f236af83a4d4998 Mon Sep 17 00:00:00 2001 From: Antony Riley Date: Wed, 27 Mar 2013 01:41:54 +0200 Subject: [PATCH] Close Unloaded Save Files diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java index f4f72ef..1b03878 100644 --- a/src/main/java/net/minecraft/server/RegionFileCache.java +++ b/src/main/java/net/minecraft/server/RegionFileCache.java @@ -10,7 +10,7 @@ import java.util.Map; public class RegionFileCache { - private static final Map a = Maps.newHashMap(); + public static final Map a = Maps.newHashMap(); // Spigot - private -> public public static synchronized RegionFile a(File file, int i, int j) { File file1 = new File(file, "region"); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0d23ec1..2da23eb 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -945,6 +945,31 @@ public final class CraftServer implements Server { worlds.remove(world.getName().toLowerCase()); console.worlds.remove(console.worlds.indexOf(handle)); + + File parentFolder = world.getWorldFolder().getAbsoluteFile(); + + // Synchronized because access to RegionFileCache.a is guarded by this lock. + synchronized (RegionFileCache.class) { + // RegionFileCache.a should be RegionFileCache.cache + Iterator> i = RegionFileCache.a.entrySet().iterator(); + while(i.hasNext()) { + Map.Entry entry = i.next(); + File child = entry.getKey().getAbsoluteFile(); + while (child != null) { + if (child.equals(parentFolder)) { + i.remove(); + try { + entry.getValue().c(); // Should be RegionFile.close(); + } catch (IOException ex) { + getLogger().log(Level.SEVERE, null, ex); + } + break; + } + child = child.getParentFile(); + } + } + } + return true; } -- 2.1.0