From 2b3a4f738a0562d442a0a26d669b576e620f19be Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 9 Jun 2015 02:01:09 +1000 Subject: [PATCH] Modifications to trim. fixed plot move/swap --- PlotSquared/pom.xml | 2 +- .../plot/commands/Trim.java | 4 +--- .../plot/object/PlotId.java | 5 +++++ .../plot/util/ChunkManager.java | 2 ++ .../plot/util/MainUtil.java | 6 +++++ .../plot/util/bukkit/BukkitChunkManager.java | 22 ++++++++++++++++++- 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 85402c343..b976f864b 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.11.14 + 2.11.15 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index e32865c26..0a987cbef 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -204,9 +204,7 @@ public class Trim extends SubCommand { public static ArrayList expired = null; public static void deleteChunks(final String world, final ArrayList chunks) { - for (final ChunkLoc loc : chunks) { - ChunkManager.manager.deleteRegionFile(world, loc); - } + ChunkManager.manager.deleteRegionFiles(world, chunks); } public static void sendMessage(final String message) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index d769154a1..c1644801e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -126,6 +126,11 @@ public class PlotId { private int hash; + public void recalculateHash() { + this.hash = 0; + hashCode(); + } + @Override public int hashCode() { if (hash == 0) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 1ccaf416e..e983876cb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -38,6 +38,8 @@ public abstract class ChunkManager { public abstract List getChunkChunks(String world); public abstract void deleteRegionFile(final String world, final ChunkLoc loc); + + public abstract void deleteRegionFiles(final String world, final List chunks); public abstract Plot hasPlot(String world, ChunkLoc chunk); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 037e1fd48..257a2ce40 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -1052,6 +1052,8 @@ public class MainUtil { p2.id.y = temp.y; PlotSquared.getPlots(world).remove(p1.id); PlotSquared.getPlots(world).remove(p2.id); + p1.id.recalculateHash(); + p2.id.recalculateHash(); PlotSquared.getPlots(world).put(p1.id, p1); PlotSquared.getPlots(world).put(p2.id, p2); // Swap database @@ -1084,6 +1086,8 @@ public class MainUtil { p2.id.y = temp.y; PlotSquared.getPlots(world).remove(p1.id); PlotSquared.getPlots(world).remove(p2.id); + p1.id.recalculateHash(); + p2.id.recalculateHash(); PlotSquared.getPlots(world).put(p1.id, p1); PlotSquared.getPlots(world).put(p2.id, p2); // Swap database @@ -1113,6 +1117,7 @@ public class MainUtil { PlotSquared.getPlots(plot1.world).remove(id); plot.id.x += offset_x; plot.id.y += offset_y; + plot.id.recalculateHash(); PlotSquared.getPlots(plot2.world).put(plot.id, plot); } TaskManager.runTaskLater(whenDone, 1); @@ -1142,6 +1147,7 @@ public class MainUtil { PlotSquared.getPlots(plot1.world).remove(id); plot.id.x += offset_x; plot.id.y += offset_y; + plot.id.recalculateHash(); PlotSquared.getPlots(plot2.world).put(plot.id, plot); DBFunc.movePlot(getPlot(worldOriginal, idOriginal), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y))); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java index 5502bbd32..652591a85 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java @@ -101,10 +101,30 @@ 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); - PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); + PlotSquared.log("&6 - Deleting region: " + file.getName() + " (approx 1024 chunks)"); if (file.exists()) { file.delete(); } + try { + Thread.sleep(100); + } catch (InterruptedException e) {} + } + }); + } + + @Override + public void deleteRegionFiles(final String world, final List chunks) { + 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); + PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); + if (file.exists()) { + file.delete(); + } + } } }); }