diff --git a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index 6988fd6a9..261017357 100644 --- a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -31,6 +31,12 @@ public interface IPlotMain { * @return */ File getDirectory(); + + /** + * Get the directory containing all the worlds + * @return + */ + File getWorldContainer(); /** * Wrap a player into a PlotPlayer object diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index d7894974d..1ccdbb708 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -63,7 +63,7 @@ public class Trim extends SubCommand { @Override public void run() { final String directory = world + File.separator + "region"; - final File folder = new File(directory); + final File folder = new File(PS.get().IMP.getWorldContainer(), directory); final File[] regionFiles = folder.listFiles(); for (final File file : regionFiles) { final String name = file.getName(); @@ -155,12 +155,12 @@ public class Trim extends SubCommand { return true; } - public static void deleteChunks(final String world, final ArrayList chunks) { - ChunkManager.manager.deleteRegionFiles(world, chunks); + public static void deleteChunks(final String world, final ArrayList chunks, final Runnable whenDone) { + ChunkManager.manager.deleteRegionFiles(world, chunks, whenDone); } public static void sendMessage(final String message) { - PS.debug("&3PlotSquared -> World trim&8: &7" + message); + PS.log("&3PlotSquared -> World trim&8: &7" + message); } public PlotId getId(final String id) { @@ -211,8 +211,12 @@ public class Trim extends SubCommand { getTrimRegions(empty, world, new Runnable() { @Override public void run() { - deleteChunks(world, empty); - PS.log("$1Trim task complete!"); + deleteChunks(world, empty, new Runnable() { + @Override + public void run() { + PS.log("$1Trim task complete!"); + } + }); } }); return true; diff --git a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 125b3153e..0ed8dcd9b 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -111,6 +111,8 @@ public abstract class ChunkManager { public abstract void deleteRegionFiles(final String world, final List chunks); + public abstract void deleteRegionFiles(final String world, final List chunks, final Runnable whenDone); + public abstract Plot hasPlot(String world, ChunkLoc chunk); public abstract boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone); diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index cb8931e14..2c0511630 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -180,7 +180,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public File getDirectory() { return getDataFolder(); } - + + @Override + public File getWorldContainer() { + return Bukkit.getWorldContainer(); + } + @Override public TaskManager getTaskManager() { return new BukkitTaskManager(); diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 314d282cc..02b11aca2 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -68,8 +68,8 @@ import com.plotsquared.bukkit.object.entity.EntityWrapper; public class BukkitChunkManager extends ChunkManager { @Override public ArrayList getChunkChunks(final String world) { - final String directory = Bukkit.getWorldContainer() + File.separator + world + File.separator + "region"; - final File folder = new File(directory); + final String directory = world + File.separator + "region"; + final File folder = new File(PS.get().IMP.getWorldContainer(), directory); final File[] regionFiles = folder.listFiles(); final ArrayList chunks = new ArrayList<>(); if (regionFiles == null) { @@ -123,8 +123,8 @@ public class BukkitChunkManager extends ChunkManager { @Override public void run() { final String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; - final File file = new File(directory); - PS.debug("&6 - Deleting region: " + file.getName() + " (approx 1024 chunks)"); + final File file = new File(PS.get().IMP.getWorldContainer(), directory); + PS.log("&6 - Deleting region: " + file.getName() + " (approx 1024 chunks)"); if (file.exists()) { file.delete(); } @@ -136,18 +136,26 @@ public class BukkitChunkManager extends ChunkManager { } @Override - public void deleteRegionFiles(final String world, final List chunks) { + public void deleteRegionFiles(String world, List chunks) { + deleteRegionFiles(world, chunks, null); + } + + @Override + public void deleteRegionFiles(final String world, final List chunks, final Runnable whenDone) { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { for (ChunkLoc loc : chunks) { final String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; - final File file = new File(directory); - PS.debug("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); + final File file = new File(PS.get().IMP.getWorldContainer(), directory); + PS.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); if (file.exists()) { file.delete(); } } + if (whenDone != null) { + whenDone.run(); + } } }); } diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index 5a90673b4..e9c743d6d 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -427,6 +427,11 @@ public class SpongeMain implements IPlotMain, PluginContainer { return new File("mods/PlotSquared"); } + @Override + public File getWorldContainer() { + return new File("."); + } + @Override public void disable() { PS.get().disable(); diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index 3340f5907..0151ce6ca 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -120,7 +120,12 @@ public class SpongeChunkManager extends ChunkManager { // TODO Auto-generated method stub } - + + @Override + public void deleteRegionFiles(String world, List chunks, Runnable whenDone) { + // TODO Auto-generated method stub + } + @Override public Plot hasPlot(String world, ChunkLoc chunk) { // TODO Auto-generated method stub