From b4fab94192daaa62503272973f816613c2abb0f3 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 24 Mar 2015 14:11:28 +1100 Subject: [PATCH] Finish cross world plot moving [UNTESTED] --- .../intellectualcrafters/plot/BukkitMain.java | 1 - .../plot/api/PlotAPI.java | 3 - .../plot/commands/Condense.java | 4 +- .../plot/commands/Confirm.java | 1 - .../plot/commands/Home.java | 1 - .../plot/commands/Inbox.java | 1 - .../plot/commands/Info.java | 2 - .../plot/commands/Move.java | 24 +++++-- .../plot/commands/Purge.java | 1 - .../plot/commands/Rate.java | 1 - .../plot/commands/Swap.java | 2 - .../plot/commands/Unclaim.java | 1 - .../intellectualcrafters/plot/config/C.java | 3 +- .../plot/database/AbstractDB.java | 2 +- .../plot/database/DBFunc.java | 4 +- .../plot/generator/HybridGen.java | 1 - .../plot/generator/HybridPlotManager.java | 1 - .../plot/object/Plot.java | 1 - .../plot/object/PlotGenerator.java | 3 - .../plot/titles/HackTitleManager.java | 1 - .../plot/util/MainUtil.java | 63 +++++++++---------- .../plot/util/bukkit/BukkitChunkManager.java | 32 ++++++---- 22 files changed, 76 insertions(+), 77 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 839cd4079..7dcc1b543 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -37,7 +37,6 @@ import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8; import com.intellectualcrafters.plot.listeners.PlotPlusListener; import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.listeners.WorldEvents; -import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.DefaultTitle; import com.intellectualcrafters.plot.util.BlockManager; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index f49f80a5f..84ca7546b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration; @@ -48,11 +47,9 @@ import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.PlotSquaredException; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.SetBlockFast; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.uuid.UUIDWrapper; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java index 77ba45daa..4beff2d08 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java @@ -98,7 +98,7 @@ public class Condense extends SubCommand { MainUtil.sendMessage(plr, "NO PLOTS FOUND"); return false; } - MainUtil.move(worldname, to_move.get(0), free.get(0), new Runnable() { + MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable() { @Override public void run() { if (!TASK) { @@ -140,7 +140,7 @@ public class Condense extends SubCommand { return; } sendMessage("MOVING " + to_move.get(0) + " to " + free.get(0)); - MainUtil.move(worldname, to_move.get(0), free.get(0), this); + MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), this); } }); TASK = true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java index 90d0badaf..364ab5bd0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java @@ -20,7 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.commands.SubCommand.CommandCategory; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.CmdInstance; import com.intellectualcrafters.plot.object.PlotPlayer; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java index 838ea3b0c..3daef2e5f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java @@ -27,7 +27,6 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * @author Citymonstret diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 544219a82..efce9a794 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -34,7 +34,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class Inbox extends SubCommand { public Inbox() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 9fc861387..91a1fbd49 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -21,9 +21,7 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.List; import java.util.UUID; import org.apache.commons.lang.StringUtils; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java index 0d50acb03..c6fd03374 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -20,11 +20,13 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; @@ -55,18 +57,32 @@ public class Move extends SubCommand { return false; } final String world = loc.getWorld(); - final PlotId plot2 = MainUtil.parseId(args[0]); - if ((plot2 == null)) { + final PlotId plot2id = MainUtil.parseId(args[0]); + if ((plot2id == null)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move "); return false; } - if (plot1.id.equals(plot2)) { + String world2; + if (args.length == 2) { + PlotWorld other = PlotSquared.getPlotWorld(args[1]); + PlotWorld current = PlotSquared.getPlotWorld(loc.getWorld()); + if (other == null || current == null || !other.equals(current)) { + MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE); + return false; + } + world2 = other.worldname; + } + else { + world2 = world; + } + Plot plot2 = MainUtil.getPlot(world2, plot2id); + if (plot1.equals(plot2)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move "); return false; } - if (MainUtil.move(world, plot1.id, plot2, new Runnable() { + if (MainUtil.move(plot1, plot2, new Runnable() { @Override public void run() { MainUtil.sendMessage(plr, C.MOVE_SUCCESS); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 2fd574adc..45446fd33 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -31,7 +31,6 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 9b46e38f3..dba751312 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -26,7 +26,6 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class Rate extends SubCommand { /* 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 596abad8d..aadda2c06 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java @@ -22,7 +22,6 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; -import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -34,7 +33,6 @@ import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * Created 2014-08-01 for PlotSquared diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java index f4a468829..a296887dd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java @@ -30,7 +30,6 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class Unclaim extends SubCommand { public Unclaim() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index fd0f23c9d..a15aa7dd0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -32,7 +32,7 @@ import com.intellectualsites.translation.bukkit.BukkitTranslation; /** * Captions class. * - * @author Citymonstret + * @author Citymonstret */ public enum C { /* @@ -260,6 +260,7 @@ public enum C { NOT_IN_PLOT("$2You're not in a plot"), NOT_IN_CLUSTER("$2You must be within a plot cluster to perform that action"), NOT_IN_PLOT_WORLD("$2You're not in a plot world"), + PLOTWORLD_INCOMPATIBLE("$2The two worlds must be compatible"), NOT_VALID_WORLD("$2That is not a valid world (case sensitive)"), NOT_VALID_PLOT_WORLD("$2That is not a valid plot world (case sensitive)"), NO_PLOTS("$2You don't have any plots"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 4c45eb927..f5af819de 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -328,5 +328,5 @@ public interface AbstractDB { public void resizeCluster(PlotCluster current, PlotClusterId resize); - public void movePlot(String world, PlotId originalPlot, PlotId newPlot); + public void movePlot(Plot originalPlot, Plot newPlot); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 6c760e337..c43509403 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -50,8 +50,8 @@ public class DBFunc { */ public static AbstractDB dbManager; - public static void movePlot(final String world, final PlotId originalPlot, final PlotId newPlot) { - dbManager.movePlot(world, originalPlot, newPlot); + public static void movePlot(final Plot originalPlot, final Plot newPlot) { + dbManager.movePlot(originalPlot, newPlot); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 0b7a0ab0c..9fae1fac5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -32,7 +32,6 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; -import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java index 4bdd53197..4a05adbd4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java @@ -33,7 +33,6 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java index e192be634..bf0056eeb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -27,7 +27,6 @@ import java.util.UUID; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * The plot class diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java index 3af8c37ce..7296708cd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -21,10 +21,7 @@ package com.intellectualcrafters.plot.object; import java.util.List; -import java.util.Random; -import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java index 52034bfa5..53ef4af64 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java @@ -1,7 +1,6 @@ package com.intellectualcrafters.plot.titles; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; 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 8c97d9723..a8f8fef2a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.UUID; import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.commands.Claim; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; @@ -41,7 +40,6 @@ import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.SendChunk; /** * plot functions @@ -807,14 +805,14 @@ public class MainUtil { Plot p2 = PlotSquared.getPlots(world).get(newPlot); if (p1 == null || p1.owner == null) { if (p2 != null && p2.owner != null) { - moveData(world, newPlot, current, whenDone); + moveData(p2, p1, whenDone); return true; } return false; } if (p2 == null || p2.owner == null) { if (p1 != null && p1.owner != null) { - moveData(world, current, newPlot, whenDone); + moveData(p1, p2, whenDone); return true; } return false; @@ -835,59 +833,58 @@ public class MainUtil { return true; } - public static boolean moveData(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { - final Plot currentPlot = MainUtil.getPlot(world, current); - if (currentPlot.owner == null) { + public static boolean moveData(final Plot plot1, final Plot plot2, final Runnable whenDone) { + if (plot1.owner == null) { TaskManager.runTaskLater(whenDone, 1); return false; } - final Plot pos1 = getBottomPlot(currentPlot); - final Plot pos2 = getTopPlot(currentPlot); - final PlotId size = MainUtil.getSize(world, currentPlot); - if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) { + final Plot pos1 = getBottomPlot(plot1); + final Plot pos2 = getTopPlot(plot1); + final PlotId size = MainUtil.getSize(plot1.world, plot1); + if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) { TaskManager.runTaskLater(whenDone, 1); return false; } - final int offset_x = newPlot.x - pos1.id.x; - final int offset_y = newPlot.y - pos1.id.y; + final int offset_x = plot2.id.x - pos1.id.x; + final int offset_y = plot2.id.y - pos1.id.y; final ArrayList selection = getPlotSelectionIds(pos1.id, pos2.id); for (final PlotId id : selection) { - DBFunc.movePlot(world, new PlotId(id.x, id.y), new PlotId(id.x + offset_x, id.y + offset_y)); - final Plot plot = PlotSquared.getPlots(world).get(id); - PlotSquared.getPlots(world).remove(id); + DBFunc.movePlot(getPlot(plot1.world, new PlotId(id.x, id.y)), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y))); + final Plot plot = PlotSquared.getPlots(plot1.world).get(id); + PlotSquared.getPlots(plot1.world).remove(id); plot.id.x += offset_x; plot.id.y += offset_y; - PlotSquared.getPlots(world).put(plot.id, plot); + PlotSquared.getPlots(plot2.world).put(plot.id, plot); } + TaskManager.runTaskLater(whenDone, 1); 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); - final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(world, newPlot); - final Location top = MainUtil.getPlotTopLoc(world, current); - final Plot currentPlot = MainUtil.getPlot(world, current); - if (currentPlot.owner == null) { + public static boolean move(final Plot plot1, final Plot plot2, final Runnable whenDone) { + final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(plot1.world, plot1.id); + final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(plot1.world, plot1.id); + final Location top = MainUtil.getPlotTopLoc(plot1.world, plot1.id); + if (plot1.owner == null) { TaskManager.runTaskLater(whenDone, 1); return false; } - final Plot pos1 = getBottomPlot(currentPlot); - final Plot pos2 = getTopPlot(currentPlot); - final PlotId size = MainUtil.getSize(world, currentPlot); - if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) { + final Plot pos1 = getBottomPlot(plot1); + final Plot pos2 = getTopPlot(plot1); + final PlotId size = MainUtil.getSize(plot1.world, plot1); + if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) { TaskManager.runTaskLater(whenDone, 1); return false; } - final int offset_x = newPlot.x - pos1.id.x; - final int offset_y = newPlot.y - pos1.id.y; + final int offset_x = plot2.id.x - pos1.id.x; + final int offset_y = plot2.id.y - pos1.id.y; final ArrayList selection = getPlotSelectionIds(pos1.id, pos2.id); for (final PlotId id : selection) { - DBFunc.movePlot(world, new PlotId(id.x, id.y), new PlotId(id.x + offset_x, id.y + offset_y)); - final Plot plot = PlotSquared.getPlots(world).get(id); - PlotSquared.getPlots(world).remove(id); + DBFunc.movePlot(getPlot(plot1.world, new PlotId(id.x, id.y)), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y))); + final Plot plot = PlotSquared.getPlots(plot1.world).get(id); + PlotSquared.getPlots(plot1.world).remove(id); plot.id.x += offset_x; plot.id.y += offset_y; - PlotSquared.getPlots(world).put(plot.id, plot); + PlotSquared.getPlots(plot2.world).put(plot.id, plot); } ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() { @Override 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 3c030d7aa..dc5409fec 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 @@ -155,28 +155,34 @@ public class BukkitChunkManager extends ChunkManager { index.increment(); final int relX = newPos.getX() - pos1.getX(); final int relZ = newPos.getZ() - pos1.getZ(); + final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); - final World world = Bukkit.getWorld(pos1.getWorld()); - final Chunk c1 = world.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4); - final Chunk c2 = world.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4); - final Chunk c3 = world.getChunkAt((pos1.getX() + relX) >> 4, (pos1.getZ() + relZ) >> 4); - final Chunk c4 = world.getChunkAt((pos2.getX() + relX) >> 4, (pos2.getZ() + relZ) >> 4); + final World oldWorld = Bukkit.getWorld(pos1.getWorld()); + final World newWorld = Bukkit.getWorld(newPos.getWorld()); + + final Chunk c1 = newWorld.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4); + final Chunk c2 = newWorld.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4); + final Chunk c3 = newWorld.getChunkAt((pos1.getX() + relX) >> 4, (pos1.getZ() + relZ) >> 4); + final Chunk c4 = newWorld.getChunkAt((pos2.getX() + relX) >> 4, (pos2.getZ() + relZ) >> 4); + final int sx = pos1.getX(); final int sz = pos1.getZ(); final int ex = pos2.getX(); final int ez = pos2.getZ(); + final int c1x = c1.getX(); final int c1z = c1.getZ(); final int c2x = c2.getX(); final int c2z = c2.getZ(); final int c3x = c3.getX(); final int c3z = c3.getZ(); + final ArrayList chunks = new ArrayList<>(); final ArrayList toGenerate = new ArrayList<>(); // Load chunks for (int x = c2x; x <= c3x; x++) { for (int z = c2z; z <= c3z; z++) { - final Chunk chunk = world.getChunkAt(x, z); + final Chunk chunk = newWorld.getChunkAt(x, z); toGenerate.add(chunk); } } @@ -198,17 +204,17 @@ public class BukkitChunkManager extends ChunkManager { initMaps(); for (int x = c1x; x <= c2x; x++) { for (int z = c1z; z <= c2z; z++) { - final Chunk chunk = world.getChunkAt(x, z); + final Chunk chunk = oldWorld.getChunkAt(x, z); chunks.add(chunk); chunk.load(false); saveEntitiesIn(chunk, region); } } - restoreEntities(world, relX, relZ); + restoreEntities(newWorld, relX, relZ); // Copy blocks final MutableInt mx = new MutableInt(sx); final Integer currentIndex = index.toInteger(); - final int maxY = world.getMaxHeight(); + final int maxY = oldWorld.getMaxHeight(); final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { @@ -216,17 +222,17 @@ public class BukkitChunkManager extends ChunkManager { while ((System.currentTimeMillis() - start) < 25) { final int xv = mx.intValue(); for (int z = sz; z <= ez; z++) { - saveBlocks(world, maxY, xv, z); + saveBlocks(oldWorld, maxY, xv, z); for (int y = 1; y <= maxY; y++) { - final Block block = world.getBlockAt(xv, y, z); + final Block block = oldWorld.getBlockAt(xv, y, z); final int id = block.getTypeId(); final byte data = block.getData(); - BukkitSetBlockManager.setBlockManager.set(world, xv + relX, y, z + relZ, id, data); + BukkitSetBlockManager.setBlockManager.set(newWorld, xv + relX, y, z + relZ, id, data); } } mx.increment(); if (xv == ex) { // done! - restoreBlocks(world, relX, relZ); + restoreBlocks(newWorld, relX, relZ); BukkitSetBlockManager.setBlockManager.update(chunks); for (final Chunk chunk : chunks) { chunk.unload(true, true);