From e1cfde520e81bdbd30991022ac5f237961ff2fea Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 26 Sep 2014 22:21:14 +1000 Subject: [PATCH] Finished mega plots (unlink now removes roads) --- .../intellectualcrafters/plot/PlotHelper.java | 5 +- .../plot/commands/Merge.java | 13 +++- .../plot/commands/Unlink.java | 50 +++++++++---- .../plot/database/PlotMeConverter.java | 10 +++ .../plot/events/PlotMergeEvent.java | 28 +++++-- .../plot/events/PlotUnlinkEvent.java | 75 +++++++++++++++++++ .../plot/listeners/WorldGuardListener.java | 5 ++ 7 files changed, 161 insertions(+), 25 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index 89905d9f6..c48bd20bd 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -27,7 +27,7 @@ import java.util.*; * */ public class PlotHelper { - static boolean canSetFast; + static boolean canSetFast = false; static long state; /** @@ -693,6 +693,8 @@ public class PlotHelper { } public static void setCuboid(World world, Location pos1, Location pos2, short[] id_l, short[] d_l) { + System.out.print("S "+pos1.getBlockX()+" | "+pos1.getBlockY()+" | "+pos1.getBlockZ()); + System.out.print("E "+pos2.getBlockX()+" | "+pos2.getBlockY()+" | "+pos2.getBlockZ()); if (!canSetFast) { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { @@ -725,7 +727,6 @@ public class PlotHelper { } } catch (Exception e) { - } } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java index 2620d1aab..56b2d7d60 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.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -26,6 +27,7 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.SetBlockFast; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlotMergeEvent; /** * @@ -103,7 +105,16 @@ public class Merge extends SubCommand { return false; } } - PlayerFunctions.sendMessage(plr, "PLOTS HAVE BEEN MERGED"); + + PlotMergeEvent event = new PlotMergeEvent(world, plot, plots); + + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + event.setCancelled(true); + PlayerFunctions.sendMessage(plr, "&cMerge has been cancelled"); + return false; + } + PlayerFunctions.sendMessage(plr, "&cPlots 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) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java index cba1c3ff4..4e51e4f6b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java @@ -24,6 +24,7 @@ import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotSettings; import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.SetBlockFast; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlotMergeEvent; import com.intellectualcrafters.plot.events.PlotUnlinkEvent; @@ -120,20 +121,31 @@ public class Unlink extends SubCommand { PlotId id = new PlotId(x,y); if (lx) { + System.out.print("LX "+id); setRoadX(world, id); - if (ly&&lx) { + if (ly) { + System.out.print("LXY "+id); setRoadXY(world, id); } } if (ly) { + System.out.print("LY "+id); setRoadY(world, id); } } } + + try { + SetBlockFast.update(plr); + } + catch (Exception e) { + + } + PlayerFunctions.sendMessage(plr, "&cPLOT UNLINKING IS NOT FINISHED (as you can see by the lack of roads appearing)"); return true; } @@ -148,16 +160,18 @@ public class Unlink extends SubCommand { int sx = pos2.getBlockX()+1; int ex = sx + pathsize - 1; - int sz = pos1.getBlockZ(); - int ez = pos2.getBlockZ()+1; + int sz = pos1.getBlockZ()-1; + int ez = pos2.getBlockZ()+2; - 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.setSimpleCuboid(w, new Location(w,sx,Math.min(wallheight, roadheight)+1,sz+1), new Location(w,ex+1,257+1,ez), (short) 0); - 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,sz+1), new Location(w,sx+1,wallheight+1,ez), new short[] {wf_id}, new short[] {wf_v}); + PlotHelper.setCuboid(w, new Location(w,sx,wallheight+1,sz+1), new Location(w,sx+1,wallheight+2,ez), 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}); + PlotHelper.setCuboid(w, new Location(w,ex,1,sz+1), new Location(w,ex+1,wallheight+1,ez), new short[] {w_id}, new short[] {w_v}); + PlotHelper.setCuboid(w, new Location(w,ex,wallheight+1,sz+1), new Location(w,ex+1,wallheight+2,ez), new short[] {wf_id}, new short[] {wf_v}); + + PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight+1,ez), new short[] {f1_id}, new short[] {f1_v}); } /** * Setting the road with the greatest Y value @@ -170,16 +184,18 @@ public class Unlink extends SubCommand { int sz = pos2.getBlockX()+1; int ez = sz + pathsize - 1; - int sx = pos1.getBlockZ(); - int ex = pos2.getBlockZ()+1; + int sx = pos1.getBlockZ()-1; + int ex = pos2.getBlockZ()+2; - 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.setSimpleCuboid(w, new Location(w,sx,Math.min(wallheight, roadheight)+1,sz+1), new Location(w,ex+1,257+1,ez), (short) 0); - 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,sz+1), new Location(w,sx+1,wallheight+1,ez), new short[] {wf_id}, new short[] {wf_v}); + PlotHelper.setCuboid(w, new Location(w,sx,wallheight+1,sz+1), new Location(w,sx+1,wallheight+2,ez), 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}); + PlotHelper.setCuboid(w, new Location(w,ex,1,sz+1), new Location(w,ex+1,wallheight+1,ez), new short[] {wf_id}, new short[] {wf_v}); + PlotHelper.setCuboid(w, new Location(w,ex,wallheight+1,sz+1), new Location(w,ex+1,wallheight+2,ez), new short[] {w_id}, new short[] {w_v}); + + PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight+1,ez), new short[] {f1_id}, new short[] {f1_v}); } /** * Setting the intersection with the greatest X and Y value @@ -194,6 +210,8 @@ public class Unlink extends SubCommand { 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}); + PlotHelper.setSimpleCuboid(w, new Location(w,sx,roadheight+1,sz+1), new Location(w,ex+1,257+1,ez), (short) 0); + + PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight+1,ez), new short[] {f1_id}, new short[] {f1_v}); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java index de7f5fd93..927b660e7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -38,6 +38,9 @@ public class PlotMeConverter { for (World world : Bukkit.getWorlds()) { HashMap plots = PlotManager.getPlots(world); if (plots!=null) { + + // TODO generate configuration based on PlotMe config + PlotMain.sendConsoleSenderMessage("Converting " + plots.size() + " plots for '" + world.toString() + "'..."); for (Plot plot : plots.values()) { PlayerList denied = null; @@ -77,6 +80,9 @@ public class PlotMeConverter { stream.println(eR3040bl230); PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1])); com.intellectualcrafters.plot.Plot pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psDenied, false, 8000l, false, "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] {false, false, false, false} ); + + // TODO createPlot doesn't add helpers / denied users + DBFunc.createPlot(pl); DBFunc.createPlotSettings(DBFunc.getId(world.getName(), pl.id), pl); } @@ -84,6 +90,10 @@ public class PlotMeConverter { } stream.close(); PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has finished"); + + // TODO disable PlotMe -> Unload all plot worlds, change the generator, restart the server automatically + // Possibly use multiverse / multiworld if it's to difficult modifying a world's generator while the server is running + Bukkit.getPluginManager().disablePlugin(PlotMeConverter.this.plugin); } }); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java index e0e0b1499..b620133f1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java @@ -9,8 +9,10 @@ package com.intellectualcrafters.plot.events; +import java.util.ArrayList; import java.util.Set; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -18,6 +20,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotId; /** * Created by Citymonstret on 2014-08-09. @@ -26,25 +29,38 @@ public class PlotMergeEvent extends Event implements Cancellable { private static HandlerList handlers = new HandlerList(); private boolean cancelled; - private Set plots; + private ArrayList plots; + private Plot plot; + private World world; /** - * PlotMergeEvent: Called when a plot is merged + * PlotMergeEvent: Called when plots are merged * @param player * @param plot */ - public PlotMergeEvent(Set plots) { + public PlotMergeEvent(World world, Plot plot, ArrayList plots) { this.plots = plots; } /** - * Get the plots involved + * Get the plots being added; * @return Plot */ - public Set getPlost() { + public ArrayList getPlots() { return this.plots; } - + /** + * Get the main plot + * @return Plot + */ + public Plot getPlot() { + return this.plot; + } + + public World getWorld() { + return this.world; + } + public static HandlerList getHandlerList() { return handlers; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java new file mode 100644 index 000000000..6f018114e --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java @@ -0,0 +1,75 @@ +/* + * 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 = PlayerClaimPlotEvent.java + * >> Generated by: Citymonstret at 2014-08-09 15:21 + */ + +package com.intellectualcrafters.plot.events; + +import java.util.ArrayList; +import java.util.Set; + +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotId; + +/** + * Created by Citymonstret on 2014-08-09. + */ +public class PlotUnlinkEvent extends Event implements Cancellable { + private static HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private ArrayList plots; + private World world; + + /** + * Called when a mega-plot is unlinked. + * @param world + * @param plots + */ + public PlotUnlinkEvent(World world, ArrayList plots) { + this.plots = plots; + this.world = world; + } + + /** + * Get the plots involved + * @return PlotId + */ + public ArrayList getPlots() { + return this.plots; + } + + public World getWorld() { + return this.world; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = b; + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java index 3327680b6..f4604b6d0 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java @@ -23,6 +23,11 @@ import org.bukkit.event.Listener; */ public class WorldGuardListener implements Listener { + /* + * TODO recreate WG region when a plot is merged + * - It should use the region of the main plot, and delete the other ones. + */ + private PlotMain plugin; public WorldGuardListener(PlotMain plugin) {