From 4403edf7ca37a25d140c044bfa517560ef73f164 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 13 Oct 2014 17:33:37 +1100 Subject: [PATCH] Multiple bug fixes Plot clearing also now requires an unlink if mega. Copy paste now requires an unlink if mega *We should fix this at some later point Plot merging now checks the entirety of both mega plots being merged (rather that just the two adjacent) --- .../plot/PlayerFunctions.java | 39 ++++++++++++++----- .../plot/commands/Clear.java | 4 ++ .../plot/commands/Copy.java | 5 +++ .../plot/commands/Merge.java | 8 ++-- .../plot/commands/Paste.java | 5 +++ 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index 3a6fa9fcc..4d39d9d15 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -54,15 +54,36 @@ public class PlayerFunctions { } public static ArrayList getPlotSelectionIds(World world, PlotId pos1, PlotId pos2) { - ArrayList myplots = new ArrayList(); - for (int x = pos1.x; x <= pos2.x; x++) { - for (int y = pos1.y; y <= pos2.y; y++) { - myplots.add(new PlotId(x, y)); - } - } - - return myplots; - } + ArrayList myplots = new ArrayList(); + for (int x = pos1.x; x <= pos2.x; x++) { + for (int y = pos1.y; y <= pos2.y; y++) { + myplots.add(new PlotId(x, y)); + } + } + return myplots; + } + + public static ArrayList getMaxPlotSelectionIds(World world, PlotId pos1, PlotId pos2) { + + Plot plot1 = PlotMain.getPlots(world).get(pos1); + Plot plot2 = PlotMain.getPlots(world).get(pos2); + + if (plot1 != null) { + pos1 = getBottomPlot(world, plot1).id; + } + + if (plot2 != null) { + pos2 = getTopPlot(world, plot2).id; + } + + ArrayList myplots = new ArrayList(); + for (int x = pos1.x; x <= pos2.x; x++) { + for (int y = pos1.y; y <= pos2.y; y++) { + myplots.add(new PlotId(x, y)); + } + } + return myplots; + } public static Plot getBottomPlot(World world, Plot plot) { if (plot.settings.getMerged(0)) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java index bf0844c47..ec4d00e16 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java @@ -30,6 +30,10 @@ public class Clear extends SubCommand { return false; } Plot plot = PlayerFunctions.getCurrentPlot(plr); + if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); + return false; + } if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java index 57bb142a7..233f4c9df 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java @@ -9,6 +9,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.*; + import org.bukkit.entity.Player; /** @@ -32,6 +33,10 @@ public class Copy extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } + if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); + return false; + } assert plot != null; int size = (PlotHelper.getPlotTopLocAbs(plr.getWorld(), plot.getId()).getBlockX() - PlotHelper.getPlotBottomLocAbs(plr.getWorld(), plot.getId()).getBlockX()); PlotSelection selection = new PlotSelection(size, plr.getWorld(), plot); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java index 8c86a5afa..74571696e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java @@ -102,19 +102,19 @@ public class Merge extends SubCommand { switch (direction) { case 0: // north = -y plots = - PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); + PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); break; case 1: // east = +x plots = - PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); + PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); break; case 2: // south = +y plots = - PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); + PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); break; case 3: // west = -x plots = - PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); + PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); break; default: return false; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java index 43ff8d289..d7a7d8db6 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.*; + import org.bukkit.entity.Player; /** @@ -24,6 +25,10 @@ public class Paste extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } + if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); + return false; + } assert plot != null; int size = (PlotHelper.getPlotTopLocAbs(plr.getWorld(), plot.getId()).getBlockX() - PlotHelper.getPlotBottomLocAbs(plr.getWorld(), plot.getId()).getBlockX());