diff --git a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index 81facb35b..19bb3edf3 100644 --- a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -32,6 +32,12 @@ public interface IPlotMain */ File getDirectory(); + /** + * Get the directory containing all the worlds + * @return + */ + File getWorldContainer(); + /** * Wrap a player into a PlotPlayer object * @param obj diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 6658981e3..a897f1d6d 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -237,6 +237,33 @@ public class PS } } } + + // Auto clearing + if (Settings.AUTO_CLEAR) + { + ExpireManager.runTask(); + } + + // PlotMe + if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) + { + TaskManager.runTaskLater(new Runnable() + { + + @Override + public void run() + { + if (IMP.initPlotMeConverter()) + { + log("&c=== IMPORTANT ==="); + log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!"); + log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!"); + log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!"); + log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'"); + } + } + }, 20); + } } }); } @@ -278,33 +305,6 @@ public class PS } }); - // PlotMe - if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) - { - TaskManager.runTaskLater(new Runnable() - { - - @Override - public void run() - { - if (IMP.initPlotMeConverter()) - { - log("&c=== IMPORTANT ==="); - log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!"); - log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!"); - log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!"); - log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'"); - } - } - }, 200); - } - - // Auto clearing - if (Settings.AUTO_CLEAR) - { - ExpireManager.runTask(); - } - // World generators: final ConfigurationSection section = config.getConfigurationSection("worlds"); if (section != null) diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index 2f2a2d8cc..5f19cbccd 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -64,7 +64,7 @@ public class Trim extends SubCommand 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) { @@ -175,14 +175,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); + public static void sendMessage(final String message) { + PS.log("&3PlotSquared -> World trim&8: &7" + message); } public PlotId getId(final String id) @@ -244,11 +242,13 @@ public class Trim extends SubCommand final ArrayList empty = new ArrayList<>(); getTrimRegions(empty, world, new Runnable() { - @Override - public void run() - { - deleteChunks(world, empty); - PS.log("$1Trim task complete!"); + public void run() { + 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 a688ce484..14e31451b 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -125,7 +125,9 @@ public abstract class ChunkManager public abstract void deleteRegionFiles(final String world, final List chunks); - public abstract Plot hasPlot(final String world, final ChunkLoc chunk); + 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 cff00f127..30651b4af 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -193,6 +193,11 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain return getDataFolder(); } + @Override + public File getWorldContainer() { + return Bukkit.getWorldContainer(); + } + @Override public TaskManager getTaskManager() { diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 8372d52af..f231c482b 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -137,10 +137,9 @@ public class BukkitChunkManager extends ChunkManager 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)"); - if (file.exists()) - { + 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(); } try @@ -154,23 +153,28 @@ public class BukkitChunkManager extends ChunkManager } @Override - public void deleteRegionFiles(final String world, final List chunks) - { - TaskManager.runTaskAsync(new Runnable() - { + 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 (final 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)"); - if (file.exists()) - { + 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 b1fffa0ba..9a7710707 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -491,8 +491,12 @@ public class SpongeMain implements IPlotMain, PluginContainer } @Override - public void disable() - { + public File getWorldContainer() { + return new File("world"); + } + + @Override + public void disable() { PS.get().disable(); THIS = null; } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index c772381b0..5c22d15b4 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -139,6 +139,11 @@ public class SpongeChunkManager extends ChunkManager } + @Override + public void deleteRegionFiles(String world, List chunks, Runnable whenDone) { + // TODO Auto-generated method stub + } + @Override public Plot hasPlot(final String world, final ChunkLoc chunk) { diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index a9c3ad84b..41abe5c81 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ diff --git a/target/PlotSquared-Sponge.jar b/target/PlotSquared-Sponge.jar index 2500a629e..c1a96a055 100644 Binary files a/target/PlotSquared-Sponge.jar and b/target/PlotSquared-Sponge.jar differ