From bbd3fd34842fb2441f1c41af16de67dc02a2abcb Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 28 Feb 2015 16:19:52 +1100 Subject: [PATCH] Improved plot swapping --- .../plot/commands/Swap.java | 10 ++++---- .../plot/database/PlotMeConverter.java | 10 ++++---- .../plot/util/MainUtil.java | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java index acac040e7..ed822bd49 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java @@ -83,10 +83,12 @@ public class Swap extends SubCommand { MainUtil.sendMessage(plr, C.SWAP_SYNTAX); return false; } - ChunkManager.manager.swap(world, plot.id, plotid); - // FIXME Requires testing!! - DBFunc.dbManager.swapPlots(plot, MainUtil.getPlot(world, plotid)); - MainUtil.sendMessage(plr, C.SWAP_SUCCESS); + MainUtil.swap(world, plot.id, plotid, new Runnable() { + @Override + public void run() { + // FIXME not implemented yet + } + }); MainUtil.update(plr.getLocation()); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java index 06c84f4f7..681d1d42a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -298,14 +298,14 @@ public class PlotMeConverter { } } PlotSquared.setAllPlotsRaw(DBFunc.getPlots()); - sendMessage("Conversion has finished"); - PlotSquared.log("&c - Stop the server"); - PlotSquared.log("&c - Disable 'plotme-convert.enabled' in the settings.yml"); - PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly"); - PlotSquared.log("&c - Start the server"); } catch (final Exception e) { e.printStackTrace(); } + sendMessage("Conversion has finished"); + PlotSquared.log("&c - Stop the server"); + PlotSquared.log("&c - Disable 'plotme-convert.enabled' in the settings.yml"); + PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly"); + PlotSquared.log("&c - Start the server"); } }); } catch (final Exception e) { 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 4a8d383bb..0a916840c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -794,6 +794,29 @@ public class MainUtil { } return true; } + + public static boolean swap(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { + Plot p1 = PlotSquared.getPlots(world).get(current); + Plot p2 = PlotSquared.getPlots(world).get(newPlot); + if (p1==null || p2 == null || p1.owner == null || !p1.owner.equals(p2.owner)) { + return false; + } + // Swap blocks + ChunkManager.manager.swap(world, current, newPlot); + // Swap cached + PlotId temp = new PlotId(p1.id.x.intValue(), p1.id.y.intValue()); + p1.id.x = p2.id.x.intValue(); + p1.id.y = p2.id.y.intValue(); + p2.id.x = temp.x; + p2.id.y = temp.y; + PlotSquared.getPlots(world).remove(p1.id); + PlotSquared.getPlots(world).remove(p2.id); + PlotSquared.getPlots(world).put(p1.id, p1); + PlotSquared.getPlots(world).put(p2.id, p2); + // Swap database + DBFunc.dbManager.swapPlots(p2, p1); + return true; + } public static boolean move(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(world, current);