From c4635be66b5287215321f8fd648e33e3edd0b5fa Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 26 Sep 2014 21:38:18 +1000 Subject: [PATCH] Untested (plot unlink) --- .../plot/commands/Unlink.java | 141 +++++++++++++++++- 1 file changed, 140 insertions(+), 1 deletion(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java index ab1e2af88..cba1c3ff4 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java @@ -11,6 +11,8 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -21,13 +23,28 @@ import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotSettings; +import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlotMergeEvent; +import com.intellectualcrafters.plot.events.PlotUnlinkEvent; /** * Created by Citymonstret on 2014-08-01. */ public class Unlink extends SubCommand { + private short w_id; + private byte w_v; + private short wf_id; + private byte wf_v; + private short f1_id; + private byte f1_v; + private short f2_id; + private byte f2_v; + private int pathsize; + private boolean stripes_enabled; + private int wallheight; + private int roadheight; public Unlink() { super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS); } @@ -48,13 +65,135 @@ public class Unlink extends SubCommand { return true; } World world = plr.getWorld(); - ArrayList ids = PlayerFunctions.getPlotSelectionIds(world, PlayerFunctions.getBottomPlot(world, plot).id, PlayerFunctions.getTopPlot(world, plot).id); + PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id; + PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id; + ArrayList ids = PlayerFunctions.getPlotSelectionIds(world, pos1, pos2); + + PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids); + + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + event.setCancelled(true); + PlayerFunctions.sendMessage(plr, "&cUnlink has been cancelled"); + return false; + } + for (PlotId id:ids) { Plot myplot = PlotMain.getPlots(world).get(id); myplot.settings.setMerged(new boolean[] {false, false, false, false} ); DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged()); } + + PlotWorld plotworld = PlotMain.getWorldSettings(world); + this.pathsize = plotworld.ROAD_WIDTH; + this.roadheight = plotworld.ROAD_HEIGHT; + this.wallheight = plotworld.WALL_HEIGHT; + this.stripes_enabled = plotworld.ROAD_STRIPES_ENABLED; + + // WALL + short[] result_w = PlotHelper.getBlock(plotworld.WALL_BLOCK); + this.w_id = result_w[0]; + this.w_v = (byte) result_w[1]; + + // WALL FILLING + short[] result_wf = PlotHelper.getBlock(plotworld.WALL_FILLING); + this.wf_id = result_wf[0]; + this.wf_v = (byte) result_wf[1]; + + // ROAD + short[] result_f1 = PlotHelper.getBlock(plotworld.ROAD_BLOCK); + this.f1_id = result_f1[0]; + this.f1_v = (byte) result_f1[1]; + // + + // Floor 2 + short[] result_f2 = PlotHelper.getBlock(plotworld.ROAD_STRIPES); + this.f2_id = result_f2[0]; + this.f2_v = (byte) result_f2[1]; + + for (int x = pos1.x; x <= pos2.x; x++) { + for (int y = pos1.y; y <= pos2.y; y++) { + + boolean lx = x < pos2.x; + boolean ly = y < pos2.y; + + PlotId id = new PlotId(x,y); + + if (lx) { + setRoadX(world, id); + + if (ly&&lx) { + setRoadXY(world, id); + } + + } + + if (ly) { + setRoadY(world, id); + } + + } + } PlayerFunctions.sendMessage(plr, "&cPLOT UNLINKING IS NOT FINISHED (as you can see by the lack of roads appearing)"); return true; } + /** + * Setting the road with the greatest X value + * @param world + * @param id + */ + public void setRoadX(World w, PlotId id) { + Location pos1 = PlotHelper.getPlotBottomLoc(w, id); + Location pos2 = PlotHelper.getPlotTopLoc(w, id); + + int sx = pos2.getBlockX()+1; + int ex = sx + pathsize - 1; + int sz = pos1.getBlockZ(); + int ez = pos2.getBlockZ()+1; + + PlotHelper.setCuboid(w, new Location(w,sx,1,sz), new Location(w,sx+1,wallheight,sz+1), new short[] {wf_id}, new short[] {wf_v}); + PlotHelper.setCuboid(w, new Location(w,sx,wallheight+1,sz), new Location(w,sx+1,wallheight+2,sz+1), new short[] {w_id}, new short[] {w_v}); + + PlotHelper.setCuboid(w, new Location(w,ex,1,ez), new Location(w,ex+1,wallheight,ez+1), new short[] {wf_id}, new short[] {wf_v}); + PlotHelper.setCuboid(w, new Location(w,ex,wallheight+1,ez), new Location(w,ex+1,wallheight+2,ez+1), new short[] {w_id}, new short[] {w_v}); + + PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight,ex), new short[] {wf_id}, new short[] {wf_v}); + } + /** + * Setting the road with the greatest Y value + * @param world + * @param id + */ + public void setRoadY(World w, PlotId id) { + Location pos1 = PlotHelper.getPlotBottomLoc(w, id); + Location pos2 = PlotHelper.getPlotTopLoc(w, id); + + int sz = pos2.getBlockX()+1; + int ez = sz + pathsize - 1; + int sx = pos1.getBlockZ(); + int ex = pos2.getBlockZ()+1; + + PlotHelper.setCuboid(w, new Location(w,sx,1,sz), new Location(w,sx+1,wallheight,sz+1), new short[] {wf_id}, new short[] {wf_v}); + PlotHelper.setCuboid(w, new Location(w,sx,wallheight+1,sz), new Location(w,sx+1,wallheight+2,sz+1), new short[] {w_id}, new short[] {w_v}); + + PlotHelper.setCuboid(w, new Location(w,ex,1,ez), new Location(w,ex+1,wallheight,ez+1), new short[] {wf_id}, new short[] {wf_v}); + PlotHelper.setCuboid(w, new Location(w,ex,wallheight+1,ez), new Location(w,ex+1,wallheight+2,ez+1), new short[] {w_id}, new short[] {w_v}); + + PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight,ex), new short[] {wf_id}, new short[] {wf_v}); + } + /** + * Setting the intersection with the greatest X and Y value + * @param world + * @param id + */ + public void setRoadXY(World w, PlotId id) { + Location pos2 = PlotHelper.getPlotTopLoc(w, id); + + int sx = pos2.getBlockX()+2; + int ex = sx + pathsize - 1; + int sz = pos2.getBlockZ()+2; + int ez = sz + pathsize - 1; + + PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight,ex), new short[] {wf_id}, new short[] {wf_v}); + } }