From c6859a5d50d716ed0ff3da3d2aa952e7482cd671 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 26 Sep 2014 14:01:30 +1000 Subject: [PATCH] MegaPlots mostly done now Fixed up methods throwing errors when not merged properly Plot merge command now merges plots as far as the plugin is concerned - Roads are not removed between the plots - No way to unlink a merged plot Added plot delete command (permission: plots.clear.delete) Modified plot clear to simply clear the terrain. --- .../src/com/intellectualcrafters/plot/C.java | 4 +- .../plot/PlayerFunctions.java | 83 ++++++--- .../intellectualcrafters/plot/PlotHelper.java | 176 +++++++++--------- .../plot/PlotSettings.java | 4 + .../plot/commands/Clear.java | 14 +- .../plot/commands/Command.java | 8 +- .../plot/commands/Delete.java | 55 ++++++ .../plot/commands/Info.java | 2 + .../plot/commands/MainCommand.java | 2 +- .../plot/commands/Merge.java | 96 ++++++++-- 10 files changed, 293 insertions(+), 151 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 0a259f8e3..2e4b3c640 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -53,7 +53,7 @@ public enum C { /* * Permission */ - NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"), NO_PERM_MERGE("&cYou must be the owner of all plots taking place in the merge."), + NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"), NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), /* * Commands */ @@ -65,7 +65,7 @@ public enum C { /* * Block List */ - NOT_VALID_BLOCK_LIST_HEADER("&cThat's not a valid block. Valid blocks are:\\n"), BLOCK_LIST_ITEM(" &6%mat%&c,"), + NOT_VALID_BLOCK_LIST_HEADER("&cThat's not a valid block. Valid blocks are:\\n"), BLOCK_LIST_ITEM(" &6%mat%&c,"), BLOCK_LIST_SEPARATER("&6,&c "), /* * Biome */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index 0a70632bb..b3d485131 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -15,6 +15,7 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -56,27 +57,10 @@ public class PlayerFunctions { return (lp - cu) > 30l; } - public static Set getPlotSelectionIds(World world, PlotId pos1, PlotId pos2) { - Set myplots = new HashSet(); - int sx, ex, sy, ey; - if (pos1.x > pos2.x) { - sx = pos2.x; - ex = pos1.x; - } - else { - sx = pos1.x; - ex = pos2.x; - } - if (pos1.y > pos2.y) { - sy = pos2.y; - ey = pos1.y; - } - else { - sy = pos1.y; - ey = pos2.y; - } - for (int x = sx; x <= ex; x++) { - for (int y = sy; x <= ey; x++) { + 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)); } } @@ -85,7 +69,7 @@ public class PlayerFunctions { } public static Plot getBottomPlot(World world, Plot plot) { - if (plot.settings.getMerged(2)) { + if (plot.settings.getMerged(0)) { return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y-1))); } if (plot.settings.getMerged(3)) { @@ -94,11 +78,11 @@ public class PlayerFunctions { return plot; } public static Plot getTopPlot(World world, Plot plot) { - if (plot.settings.getMerged(0)) { - return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y-1))); + if (plot.settings.getMerged(2)) { + return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y+1))); } if (plot.settings.getMerged(1)) { - return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x-1, plot.id.y))); + return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x+1, plot.id.y))); } return plot; } @@ -107,6 +91,46 @@ public class PlayerFunctions { * @param loc * @return */ + public static PlotId getPlotAbs(Location loc) { + int x = loc.getBlockX(); + int z = loc.getBlockZ(); + + String world = loc.getWorld().getName(); + PlotWorld plotworld = PlotMain.getWorldSettings(world); + int size = plotworld.PLOT_WIDTH + plotworld.ROAD_WIDTH; + int pathWidthLower; + if ((plotworld.ROAD_WIDTH % 2) == 0) { + pathWidthLower = (int) (Math.floor(plotworld.ROAD_WIDTH / 2)-1); + } + else { + pathWidthLower = (int) Math.floor(plotworld.ROAD_WIDTH / 2); + } + + int dx = x/size; + int dz = z/size; + + if (x<0) { + dx--; + x+=((-dx) * size); + } + if (z<0) { + dz--; + z+=((-dz) * size); + } + + int rx = (x)%size; + int rz = (z)%size; + + int end = pathWidthLower+plotworld.PLOT_WIDTH; + boolean northSouth = rz<=pathWidthLower || rz>pathWidthLower+plotworld.PLOT_WIDTH; + boolean eastWest = rx<=pathWidthLower || rx>end; + + if (northSouth || eastWest) { + return null; + } + return new PlotId(dx+1,dz+1); + } + public static PlotId getPlot(Location loc) { int x = loc.getBlockX(); int z = loc.getBlockZ(); @@ -144,19 +168,19 @@ public class PlayerFunctions { if (northSouth && eastWest) { // This means you are in the intersection - PlotId id = getPlot(loc.add(plotworld.ROAD_WIDTH, 0, plotworld.ROAD_WIDTH)); + PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, plotworld.ROAD_WIDTH)); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); if (plot==null) { return null; } - if (plot.settings.getMerged(0) && plot.settings.getMerged(3)) { + if ((plot.settings.getMerged(0) && plot.settings.getMerged(3))) { return getBottomPlot(loc.getWorld(), plot).id; } return null; } if (northSouth) { // You are on a road running West to East (yeah, I named the var poorly) - PlotId id = getPlot(loc.add(0, 0, plotworld.ROAD_WIDTH)); + PlotId id = getPlotAbs(loc.add(0, 0, plotworld.ROAD_WIDTH)); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); if (plot==null) { return null; @@ -168,8 +192,9 @@ public class PlayerFunctions { } if (eastWest) { // This is the road separating an Eastern and Western plot - PlotId id = getPlot(loc.add(plotworld.ROAD_WIDTH, 0, 0)); + PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, 0)); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); + System.out.print("IDS "+id); if (plot==null) { return null; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index 076227631..41ac210c9 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -10,6 +10,7 @@ package com.intellectualcrafters.plot; import com.intellectualcrafters.plot.database.DBFunc; + import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.block.Block; @@ -25,7 +26,7 @@ import java.util.*; * */ public class PlotHelper { - + static boolean canSetFast; static long state; /** @@ -38,6 +39,29 @@ public class PlotHelper { return (blocks / blocks_per_second); } + /** + * Merges 2 plots + *
- Assumes the first plot parameter is lower + *
- Assumes neither are a Mega-plot + *
- Assumes plots are directly next to each other + *
- Does not save to DB + *
This is the only public merge method as the other ones were deemed unsafe if used incorrectly + * @param world + * @param lesserPlot + * @param greaterPlot + */ + public static void mergePlot(World world, Plot lesserPlot, Plot greaterPlot) { + if (lesserPlot.id.x == greaterPlot.id.x) { + lesserPlot.settings.setMerged(2, true); + greaterPlot.settings.setMerged(0, true); + } + else { + lesserPlot.settings.setMerged(1, true); + greaterPlot.settings.setMerged(3, true); + } + + } + public static final long nextLong() { long a = state; state = xorShift64(a); @@ -464,15 +488,9 @@ public class PlotHelper { */ public static void clear(final Player requester, final Plot plot) { - /* - * TODO unlink any adjacent plots - */ - - final long start = System.nanoTime(); final PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(plot.world)); PlotHelper.setBiome(requester.getWorld(), plot, Biome.FOREST); - PlotHelper.removeSign(requester, plot); PlayerFunctions.sendMessage(requester, C.CLEARING_PLOT); final World world = requester.getWorld(); final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1); @@ -501,80 +519,12 @@ public class PlotHelper { h = (prime * h) + pos1.getBlockZ(); state = h; - boolean canSetFast; try { new SetBlockFast(); canSetFast = true; } catch (Exception e) { canSetFast = false; } - if (canSetFast) { - PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), (new Runnable() { - @Override - public void run() { - try { - for (int y = 0; y < 1; y++) { - for (int x = pos1.getBlockX(); x <= pos2.getBlockX(); x++) { - for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) { - Block block = world.getBlockAt(x, y, z); - if (!((block.getTypeId() == 7))) { - SetBlockFast.set(world, x, y, z, 7, (byte) 7); - } - } - } - } - for (int y = 1; y < plotworld.PLOT_HEIGHT; y++) { - for (int x = pos1.getBlockX(); x <= pos2.getBlockX(); x++) { - for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) { - int i = random(filling.length); - short id = filling[i]; - byte d = (byte) filling_data[i]; - Block block = world.getBlockAt(x, y, z); - if (!((block.getTypeId() == id && block.getData() == d))) { - SetBlockFast.set(world, x, y, z, id, d); - } - } - } - } - for (int y = plotworld.PLOT_HEIGHT; y < (plotworld.PLOT_HEIGHT + 1); y++) { - for (int x = pos1.getBlockX(); x <= pos2.getBlockX(); x++) { - for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) { - int i = random(plotfloors.length); - short id = plotfloors[i]; - byte d = (byte) plotfloors_data[i]; - Block block = world.getBlockAt(x, y, z); - if (!((block.getTypeId() == id && block.getData() == d))) { - SetBlockFast.set(world, x, y, z, id, d); - } - } - } - } - for (int y = plotworld.PLOT_HEIGHT + 1; y < (world.getMaxHeight() + 1); y++) { - for (int x = pos1.getBlockX(); x <= pos2.getBlockX(); x++) { - for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) { - Block block = world.getBlockAt(x, y, z); - if (!((block.getTypeId() == 0))) { - SetBlockFast.set(world, x, y, z, 0, (byte) 0); - } - } - } - } - PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0))); - SetBlockFast.update(requester); - return; - } catch (Exception e) { - if(Settings.DEBUG) { - PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "Debug Mode Enabled -> Throwing epic stacktrace."); - e.printStackTrace(); - } else { - PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "Something went wrong with plot clearing... Enable debug to get stacktraces."); - } - PlayerFunctions.sendMessage(requester, C.PREFIX.s() + "&cPlot clear failed... Trying again..."); - } - } - })); - return; - } if ((pos2.getBlockX() - pos1.getBlockX()) < 16) { setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX(), 1, pos2.getBlockZ()), (short) 7); setSimpleCuboid(world, new Location(world, pos1.getBlockX(), plotworld.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX(), world.getMaxHeight(), pos2.getBlockZ()), (short) 0); @@ -663,37 +613,81 @@ public class PlotHelper { setCuboid(world, new Location(world, max.getBlockX(), 1, max.getBlockZ()), new Location(world, plotMaxX, plotworld.PLOT_HEIGHT, plotMaxZ), filling, filling_data); setCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT, max.getBlockZ()), new Location(world, plotMaxX, plotworld.PLOT_HEIGHT + 1, plotMaxZ), plotfloors, plotfloors_data); } - PlayerFunctions.sendMessage(requester, "&c(depreciated) &r" + C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0))); + PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0))); + if (canSetFast) { + SetBlockFast.update(requester); + } return; } public static void setCuboid(World world, Location pos1, Location pos2, short[] id_l, short[] d_l) { - for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { - for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { - for (int z = pos1.getBlockZ(); z < pos2.getBlockZ(); z++) { - int i = random(id_l.length); - short id = id_l[i]; - byte d = (byte) d_l[i]; - Block block = world.getBlockAt(x, y, z); - if (!((block.getTypeId() == id) && (block.getData() == d))) { - block.setTypeIdAndData(id, d, false); + if (!canSetFast) { + for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { + for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { + for (int z = pos1.getBlockZ(); z < pos2.getBlockZ(); z++) { + int i = random(id_l.length); + short id = id_l[i]; + byte d = (byte) d_l[i]; + Block block = world.getBlockAt(x, y, z); + if (!((block.getTypeId() == id) && (block.getData() == d))) { + block.setTypeIdAndData(id, d, false); + } } } } } + else { + try { + for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { + for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { + for (int z = pos1.getBlockZ(); z < pos2.getBlockZ(); z++) { + int i = random(id_l.length); + short id = id_l[i]; + byte d = (byte) d_l[i]; + Block block = world.getBlockAt(x, y, z); + if (!((block.getTypeId() == id) && (block.getData() == d))) { + SetBlockFast.set(world, x, y, z, id, d); + } + } + } + } + } + catch (Exception e) { + + } + } } public static void setSimpleCuboid(World world, Location pos1, Location pos2, short id) { - for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { - for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { - for (int z = pos1.getBlockZ(); z < pos2.getBlockZ(); z++) { - Block block = world.getBlockAt(x, y, z); - if (!((block.getTypeId() == id))) { - block.setTypeId(id, false); + if (!canSetFast) { + for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { + for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { + for (int z = pos1.getBlockZ(); z < pos2.getBlockZ(); z++) { + Block block = world.getBlockAt(x, y, z); + if (!((block.getTypeId() == id))) { + block.setTypeId(id, false); + } } } } } + else { + try { + for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { + for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { + for (int z = pos1.getBlockZ(); z < pos2.getBlockZ(); z++) { + Block block = world.getBlockAt(x, y, z); + if (!((block.getTypeId() == id))) { + SetBlockFast.set(world, x, y, z, id, (byte) 0); + } + } + } + } + } + catch (Exception e) { + + } + } } public static void setBiome(World world, Plot plot, Biome b) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java index 6313e8746..32bc4fefb 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java @@ -87,6 +87,10 @@ public class PlotSettings { public void setMerged(boolean[] merged) { this.merged = merged; } + + public void setMerged(int direction, boolean merged) { + this.merged[direction] = merged; + } /** * * @param b diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java index bac6f371f..eba079756 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java @@ -14,6 +14,7 @@ import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; @@ -33,17 +34,16 @@ public class Clear extends SubCommand { return true; } Plot plot = PlayerFunctions.getCurrentPlot(plr); + if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); + return true; + } if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return true; } - boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id, true); - if (result) { - plot.clear(plr); - DBFunc.delete(plr.getWorld().getName(), plot); - } else { - PlayerFunctions.sendMessage(plr, "Plot clearing has been denied."); - } + PlotHelper.removeSign(plr, plot); + plot.clear(plr); return true; } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java index 4b8d340b1..206bc0957 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java @@ -32,9 +32,13 @@ public enum Command { */ MERGE("merge", "m"), /** - * + * + */ + CLEAR("clear", "clear", new CommandPermission("plots.clear")), + /** + * */ - CLEAR("clear", "delete", new CommandPermission("plots.clear")), + DELETE("delete", "d", new CommandPermission("plots.clear.delete")), /** * */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java new file mode 100644 index 000000000..ecb8580ef --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) IntellectualCrafters - 2014. + * You are not allowed to distribute and/or monetize any of our intellectual property. + * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. + * + * >> File = Clear.java + * >> Generated by: Citymonstret at 2014-08-09 01:41 + */ + +package com.intellectualcrafters.plot.commands; + +import org.bukkit.entity.Player; + +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.database.DBFunc; + +/** + * Created by Citymonstret on 2014-08-01. + */ +public class Delete extends SubCommand { + + public Delete() { + super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS); + } + + @Override + public boolean execute(Player plr, String... args) { + if (!PlayerFunctions.isInPlot(plr)) { + PlayerFunctions.sendMessage(plr, "You're not in a plot."); + return true; + } + Plot plot = PlayerFunctions.getCurrentPlot(plr); + if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); + return true; + } + if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { + PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); + return true; + } + boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id, true); + if (result) { + PlotHelper.removeSign(plr, plot); + plot.clear(plr); + DBFunc.delete(plr.getWorld().getName(), plot); + } else { + PlayerFunctions.sendMessage(plr, "Plot clearing has been denied."); + } + return true; + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index b20aa4984..d7f8c7228 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -82,6 +82,8 @@ public class Info extends SubCommand { info = info.replaceAll("%helpers%", getPlayerList(plot.helpers)); info = info.replaceAll("%denied%", getPlayerList(plot.denied)); info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none"); + PlayerFunctions.sendMessage(player, PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString()); + PlayerFunctions.sendMessage(player, PlayerFunctions.getBottomPlot(player.getWorld(), plot).id.toString()); PlayerFunctions.sendMessage(player, info); return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java index f42d1e953..913c16f47 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java @@ -30,7 +30,7 @@ import com.intellectualcrafters.plot.PlotMain; */ public class MainCommand implements CommandExecutor { - private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new SetOwner(), new Denied(), new Helpers(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Reload() }; + private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Reload(), new Merge() }; public static ArrayList subCommands = new ArrayList() { { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java index 415078d63..fcc3f8a95 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java @@ -9,11 +9,20 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.World; import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotId; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.database.DBFunc; /** * @@ -22,8 +31,11 @@ import com.intellectualcrafters.plot.Plot; */ public class Merge extends SubCommand { + public static String[] values = new String[] { "north", "east", "south", "west" }; + public static String[] aliases = new String[] { "n", "e", "s", "w"}; + public Merge() { - super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING); + super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS); } @Override @@ -33,7 +45,7 @@ public class Merge extends SubCommand { return true; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - if (!plot.hasOwner()) { + if (plot==null || !plot.hasOwner()) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } @@ -41,24 +53,70 @@ public class Merge extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - // get the plots involved - -// C.NO_PERM_MERGE; - - // for each plot check if you are the owner - - // execute the merge - - // add methods to get plots relative to your current plot - // getNorthernPlot | getEasternPlot | getSouthernPlot | getWesternPlot -// return mergePlot(plr, plot, false); - - // merge the plots - - return true; + if (args.length<1) { + PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s())); + return false; + } + int direction = -1; + for (int i = 0; i 1 ? direction-2 : direction+2; + if (direction==-1) { + PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s())); + return false; + } + World world = plr.getWorld(); + PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; + PlotId top = PlayerFunctions.getTopPlot(world, plot).id; + ArrayList plots; + switch (direction) { + case 0: // north = -y + plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y-1), new PlotId(top.x,bot.y-1)); + break; + case 1: // east = +x + plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(top.x+1,bot.y), new PlotId(top.x+1,top.y)); + break; + case 2: // south = +y + plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,top.y+1), 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(bot.x-1,top.y)); + break; + default: + return false; + } + for (PlotId myid:plots) { + Plot myplot = PlotMain.getPlots(world).get(myid); + if (myplot==null || !myplot.hasOwner() || !(myplot.getOwner().equals(plr.getUniqueId()))) { + PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString())); + return false; + } + } + PlayerFunctions.sendMessage(plr, "PLOTS HAVE BEEN MERGED"); + return mergePlot(world, plr, PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y), new PlotId(top.x,top.y)), plots, direction, direction2); } - - public static boolean mergePlot(Player player, Plot plot, java.util.Set plots) { + public static boolean mergePlot(World world, Player player, ArrayList currentMegaPlots, ArrayList toMerge, int dir1, int dir2) { + for (PlotId plotid:currentMegaPlots) { + Plot plot = PlotMain.getPlots(world).get(plotid); + plot.settings.setMerged(dir1, true); + DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged()); + } + for (int i = 0;i < toMerge.size(); i++) { + PlotId plotid = toMerge.get(i); + Plot plot = PlotMain.getPlots(world).get(plotid); + plot.settings.setMerged(dir2, true); + if (i