From d0ec93b15c11dcbcd50548a6b3fe5ee66ed2660b Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 26 Sep 2014 18:07:24 +1000 Subject: [PATCH] Megaplots are pretty much done now I still need to finish the unlinking, currently it doesn't recreate the roads, but that's not a big deal. --- .../src/com/intellectualcrafters/plot/C.java | 1 + .../plot/PlayerFunctions.java | 1 - .../intellectualcrafters/plot/PlotHelper.java | 82 +++++++++----- .../plot/commands/Merge.java | 101 ++++++++++++++++-- .../plot/commands/Unlink.java | 1 + .../plot/database/DBFunc.java | 10 +- 6 files changed, 151 insertions(+), 45 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 9acbb6b34..6639eece6 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -55,6 +55,7 @@ public enum C { */ 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."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"), + NO_MERGE_TO_MEGA("&cMega plots cannot be merged into. Please merge from the desired mega plot."), /* * Commands */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index b3d485131..b18dcbe85 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -194,7 +194,6 @@ public class PlayerFunctions { // This is the road separating an Eastern and Western plot 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 04e14e12a..89905d9f6 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -76,12 +76,24 @@ public class PlotHelper { * @param greaterPlot */ public static void mergePlot(World world, Plot lesserPlot, Plot greaterPlot) { - Location pos1 = getPlotTopLoc(world, lesserPlot.id); - Location pos2 = getPlotTopLoc(world, lesserPlot.id); - int startx = Math.min(pos1.getBlockX(),pos2.getBlockX()); - int endx = Math.max(pos1.getBlockX(),pos2.getBlockX()); - int startz = Math.min(pos1.getBlockZ(),pos2.getBlockZ()); - int endz = Math.max(pos1.getBlockZ(),pos2.getBlockZ()); + Location pos1 = getPlotBottomLocAbs(world, lesserPlot.id).add(1,0,1); + Location pos2 = getPlotTopLocAbs(world, lesserPlot.id); + + Location pos3 = getPlotBottomLocAbs(world, greaterPlot.id).add(1,0,1); + Location pos4 = getPlotTopLocAbs(world, greaterPlot.id); + + int sx = Math.max(pos1.getBlockX(),pos2.getBlockX()); + int ex = Math.min(pos3.getBlockX(),pos4.getBlockX()); + int sz = Math.max(pos1.getBlockZ(),pos2.getBlockZ()); + int ez = Math.min(pos3.getBlockZ(),pos4.getBlockZ()); + + int startx = Math.min(sx,ex); + int startz = Math.min(sz,ez); + int endx = Math.max(sx,ex)+1; + int endz = Math.max(sz,ez)+1; + + System.out.print("X "+startx+" | "+endx); + System.out.print("Z "+startz+" | "+endz); PlotWorld plotworld = PlotMain.getWorldSettings(world); @@ -92,40 +104,30 @@ public class PlotHelper { final short[] filling_data = new short[plotworld.MAIN_BLOCK.length]; for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) { - Short[] result = getBlock(plotworld.TOP_BLOCK[i]); + short[] result = getBlock(plotworld.TOP_BLOCK[i]); plotfloors[i] = result[0]; plotfloors_data[i] = result[1]; } for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) { - Short[] result = getBlock(plotworld.MAIN_BLOCK[i]); + short[] result = getBlock(plotworld.MAIN_BLOCK[i]); filling[i] = result[0]; filling_data[i] = result[1]; } if (lesserPlot.id.x == greaterPlot.id.x) { -// if (lesserPlot.id.y < greaterPlot.id.y) { lesserPlot.settings.setMerged(2, true); greaterPlot.settings.setMerged(0, true); - startz++; - endz--; -// } -// else { -// lesserPlot.settings.setMerged(0, true); -// greaterPlot.settings.setMerged(2, true); -// } + startx--; + endx++; } else { -// if (lesserPlot.id.x < greaterPlot.id.x) { lesserPlot.settings.setMerged(1, true); greaterPlot.settings.setMerged(3, true); - startx++; - endx--; -// } -// else { -// lesserPlot.settings.setMerged(3, true); -// greaterPlot.settings.setMerged(1, true); -// } + startz--; + endz++; } + + setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7); setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0); setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data); @@ -543,12 +545,12 @@ public class PlotHelper { return (square(plotworld.PLOT_WIDTH)) * (world.getMaxHeight()); } - public static Short[] getBlock(String block) { + public static short[] getBlock(String block) { if (block.contains(":")) { String[] split = block.split(":"); - return new Short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) }; + return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) }; } - return new Short[] { Short.parseShort(block), 0 }; + return new short[] { Short.parseShort(block), 0 }; } /** @@ -573,12 +575,12 @@ public class PlotHelper { final short[] filling_data = new short[plotworld.MAIN_BLOCK.length]; for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) { - Short[] result = getBlock(plotworld.TOP_BLOCK[i]); + short[] result = getBlock(plotworld.TOP_BLOCK[i]); plotfloors[i] = result[0]; plotfloors_data[i] = result[1]; } for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) { - Short[] result = getBlock(plotworld.MAIN_BLOCK[i]); + short[] result = getBlock(plotworld.MAIN_BLOCK[i]); filling[i] = result[0]; filling_data[i] = result[1]; } @@ -845,6 +847,28 @@ public class PlotHelper { } } + public static Location getPlotTopLocAbs(World world, PlotId id) { + PlotWorld plotworld = PlotMain.getWorldSettings(world); + int px = id.x; + int pz = id.y; + + int x = (px * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1; + int z = (pz * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1; + + return new Location(world, x, 255, z); + } + + public static Location getPlotBottomLocAbs(World world, PlotId id) { + PlotWorld plotworld = PlotMain.getWorldSettings(world); + int px = id.x; + int pz = id.y; + + int x = (px * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - plotworld.PLOT_WIDTH - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1; + int z = (pz * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - plotworld.PLOT_WIDTH - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1; + + return new Location(world, x, 1, z); + } + public static Location getPlotTopLoc(World world, PlotId id) { Plot plot = PlotMain.getPlots(world).get(id); if (plot!=null) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java index c163ba0d1..2620d1aab 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Set; import org.apache.commons.lang.StringUtils; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -23,6 +24,7 @@ import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.SetBlockFast; import com.intellectualcrafters.plot.database.DBFunc; /** @@ -96,33 +98,112 @@ public class Merge extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString())); return false; } + if (!PlayerFunctions.getBottomPlot(world, myplot).equals(PlayerFunctions.getTopPlot(world, myplot))) { + PlayerFunctions.sendMessage(plr, C.NO_MERGE_TO_MEGA); + 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(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()); - } + + Location pos1 = PlotHelper.getPlotBottomLoc(world, currentMegaPlots.get(0)).add(1,0,1); + Location pos2 = PlotHelper.getPlotTopLoc(world, currentMegaPlots.get(currentMegaPlots.size()-1)); + 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); + Plot plot = PlotMain.getPlots(world).get(plotid); if (i= 0; i--) { - merged[i] = (merged_int & (1 << i)) != 0; + boolean[] merged = new boolean[4]; + for (int i = 0; i < 4; i++) { + merged[3-i] = (merged_int & (1 << i)) != 0; } p = new Plot(plot_id, owner, plotBiome, helpers, denied, /* changeTime */false, time, rain, alias, position, flags, worldname, merged); if (plots.containsKey(worldname)) { @@ -352,8 +352,8 @@ public class DBFunc { @Override public void run() { try { - int n = 0, l = merged.length; - for (int i = 0; i < l; ++i) { + int n = 0; + for (int i = 0; i < 4; ++i) { n = (n << 1) + (merged[i] ? 1 : 0); } PreparedStatement stmt = connection.prepareStatement("UPDATE `plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?");