From 5978c9c3c07d967d2f16af0ba98a78e95c4ed82f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 3 Oct 2016 00:56:08 +1100 Subject: [PATCH] Fix center --- .../com/intellectualcrafters/plot/commands/Auto.java | 3 ++- .../plot/generator/ClassicPlotManager.java | 7 +++++-- .../com/intellectualcrafters/plot/object/ChunkLoc.java | 6 +----- .../java/com/intellectualcrafters/plot/object/Plot.java | 7 ++++++- .../com/intellectualcrafters/plot/util/BO3Handler.java | 9 +++++++-- .../java/com/intellectualcrafters/plot/util/MathMan.java | 4 ++++ .../plot/util/expiry/ExpireManager.java | 8 ++++++++ 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 3cf2490ab..5875bb8e7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -10,6 +10,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ByteArrayUtilities; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.Permissions; import com.plotsquared.general.commands.CommandDeclaration; @@ -143,7 +144,7 @@ public class Auto extends SubCommand { if (plotarea.TYPE == 2) { PlotId bot = plotarea.getMin(); PlotId top = plotarea.getMax(); - PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2); + PlotId origin = new PlotId(MathMan.average(bot.x, top.x), MathMan.average(bot.y, top.y)); PlotId id = new PlotId(0, 0); int width = Math.max(top.x - bot.x + 1, top.y - bot.y + 1); int max = width * width; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index 6e7183e57..2f45c8e8e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -7,6 +7,7 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.block.GlobalBlockQueue; import com.intellectualcrafters.plot.util.block.LocalBlockQueue; import java.util.ArrayList; @@ -130,8 +131,10 @@ public class ClassicPlotManager extends SquarePlotManager { Location[] corners = plot.getCorners(); ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea; LocalBlockQueue queue = plotArea.getQueue(false); - queue.setBlock((corners[0].getX() + corners[1].getX()) / 2, dpw.PLOT_HEIGHT, - (corners[0].getZ() + corners[1].getZ()) / 2, blocks[0]); + + int x = MathMan.average(corners[0].getX(), corners[1].getX()); + int z = MathMan.average(corners[0].getZ(), corners[1].getZ()); + queue.setBlock(x, dpw.PLOT_HEIGHT,z, blocks[0]); queue.enqueue(); return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/ChunkLoc.java b/Core/src/main/java/com/intellectualcrafters/plot/object/ChunkLoc.java index c947be5bc..04333a8c5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/ChunkLoc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/ChunkLoc.java @@ -12,11 +12,7 @@ public class ChunkLoc { @Override public int hashCode() { - int prime = 31; - int result = 1; - result = (prime * result) + this.x; - result = (prime * result) + this.z; - return result; + return (x << 16) | (z & 0xFFFF); } @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index bfe6244f1..b0ce0f109 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.util.BO3Handler; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.EventUtil; @@ -24,6 +25,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.block.GlobalBlockQueue; import com.intellectualcrafters.plot.util.block.LocalBlockQueue; +import com.intellectualcrafters.plot.util.expiry.ExpireManager; import com.intellectualcrafters.plot.util.expiry.PlotAnalysis; import com.plotsquared.listener.PlotListener; import java.awt.geom.Area; @@ -948,6 +950,9 @@ public class Plot { * @param value */ public boolean setFlag(Flag flag, Object value) { + if (flag == Flags.KEEP && ExpireManager.IMP != null) { + ExpireManager.IMP.updateExpired(this); + } return FlagManager.addPlotFlag(this, flag, value); } @@ -1103,7 +1108,7 @@ public class Plot { Location[] corners = getCorners(); Location top = corners[0]; Location bot = corners[1]; - Location loc = new Location(this.area.worldname, (top.getX() + bot.getX()) / 2, (top.getY() + bot.getY()) / 2, (top.getZ() + bot.getZ()) / 2); + Location loc = new Location(this.area.worldname, MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ())); loc.setY(1 + Math.max(WorldUtil.IMP.getHighestBlock(this.area.worldname, loc.getX(), loc.getZ()), getManager().getSignLoc(this.area, this).getY())); return loc; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java index 9b00cbc02..a12335903 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java @@ -84,8 +84,8 @@ public class BO3Handler { ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld; int height = cpw.PLOT_HEIGHT; - int cx = (bot.getX() + top.getX()) / 2; - int cz = (bot.getZ() + top.getZ()) / 2; + int cx = MathMan.average(bot.getX(), top.getX()); + int cz = MathMan.average(bot.getZ(), top.getZ()); HashMap map = new HashMap<>(); @@ -193,6 +193,7 @@ public class BO3Handler { return true; } + public static void upload(final Plot plot, UUID uuid, String file, RunnableVal whenDone) { if (plot == null) { throw new IllegalArgumentException("Arguments may not be null!"); @@ -250,6 +251,10 @@ public class BO3Handler { public static boolean save(Plot plot, BO3 bo3) { try { File bo3File = bo3.getFile(); + File parent = bo3File.getParentFile(); + if (parent != null) { + parent.mkdirs(); + } bo3File.createNewFile(); bo3File.getParentFile().mkdirs(); try (FileOutputStream fos = new FileOutputStream(bo3File)) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java index 7b5da6eaa..10beca24f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java @@ -159,6 +159,10 @@ public class MathMan { return (x << 16) | (y & 0xFFFF); } + public static final int average(int a, int b) { + return (a&b) + (a^b)/2; + } + public static short unpairX(int hash) { return (short) (hash >> 16); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java index 7f5c97be8..08ba065b9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java @@ -76,6 +76,14 @@ public class ExpireManager { return value == null ? 0 : value; } + public void updateExpired(Plot plot) { + if (!plotsToDelete.isEmpty() && plotsToDelete.contains(plot)) { + if (isExpired(new ArrayDeque<>(tasks), plot).isEmpty()) { + plotsToDelete.remove(plot); + } + } + } + public void confirmExpiry(final PlotPlayer pp) { if (pp.getMeta("ignoreExpireTask") != null) { return;