From eb7106eb766e6f275453d41603baa540f66d9d15 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 26 Sep 2014 10:22:25 +1000 Subject: [PATCH] Fixes to merge methods - Merged automatically added to DB - Started work on commands - Fixed getCurrentPlot not working for roads --- .../src/com/intellectualcrafters/plot/C.java | 2 +- .../plot/PlayerFunctions.java | 64 +++++++++++++++---- .../plot/commands/Command.java | 4 ++ .../plot/commands/Merge.java | 64 +++++++++++++++++++ .../plot/database/DBFunc.java | 8 ++- 5 files changed, 128 insertions(+), 14 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index b69e883af..0a259f8e3 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_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."), /* * Commands */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index 968fa3448..0a70632bb 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -58,8 +58,25 @@ public class PlayerFunctions { public static Set getPlotSelectionIds(World world, PlotId pos1, PlotId pos2) { Set myplots = new HashSet(); - for (int x = pos1.x; x <= pos2.x; x++) { - for (int y = pos1.y; x <= pos2.y; x++) { + 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++) { myplots.add(new PlotId(x,y)); } } @@ -122,20 +139,43 @@ public class PlayerFunctions { int end = pathWidthLower+plotworld.PLOT_WIDTH; - if (rx<=pathWidthLower) { -// System.out.print("WEST"); + boolean northSouth = rz<=pathWidthLower || rz>pathWidthLower+plotworld.PLOT_WIDTH; + boolean eastWest = rx<=pathWidthLower || rx>end; + + if (northSouth && eastWest) { + // This means you are in the intersection + PlotId id = getPlot(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)) { + return getBottomPlot(loc.getWorld(), plot).id; + } return null; } - if (rx>end) { -// System.out.print("EAST"); + 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)); + Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); + if (plot==null) { + return null; + } + if (plot.settings.getMerged(0)) { + return getBottomPlot(loc.getWorld(), plot).id; + } return null; } - if (rz<=pathWidthLower) { -// System.out.print("NORTH"); - return null; - } - if (rz>pathWidthLower+plotworld.PLOT_WIDTH) { -// System.out.print("SOUTH"); + if (eastWest) { + // This is the road separating an Eastern and Western plot + PlotId id = getPlot(loc.add(plotworld.ROAD_WIDTH, 0, 0)); + Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); + if (plot==null) { + return null; + } + if (plot.settings.getMerged(3)) { + return getBottomPlot(loc.getWorld(), plot).id; + } return null; } PlotId id = new PlotId(dx+1,dz+1); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java index 2595fdf8f..4b8d340b1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java @@ -27,6 +27,10 @@ public enum Command { * */ CLAIM("claim", "c"), + /** + * + */ + MERGE("merge", "m"), /** * */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java new file mode 100644 index 000000000..415078d63 --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java @@ -0,0 +1,64 @@ +/* + * 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 = Merge.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; + +/** + * + * @author Citymonstret + * + */ +public class Merge extends SubCommand { + + public Merge() { + super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING); + } + + @Override + public boolean execute(Player plr, String... args) { + if (!PlayerFunctions.isInPlot(plr)) { + PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT); + return true; + } + Plot plot = PlayerFunctions.getCurrentPlot(plr); + if (!plot.hasOwner()) { + PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); + return false; + } + if (!plot.getOwner().equals(plr.getUniqueId())) { + 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; + } + + public static boolean mergePlot(Player player, Plot plot, java.util.Set plots) { + return true; + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 695c119b6..e06e9ceaa 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -223,7 +223,13 @@ public class DBFunc { statement.addBatch("UPDATE `plot` SET\n" + " `plot_id_x` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, 1, LOCATE(';', `plot_id`) - 1)," + " `plot_id`" + " )," + " `plot_id_z` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, LOCATE(';', `plot_id`) + 1)," + " NULL" + " )"); statement.addBatch("ALTER TABLE `plot` DROP `plot_id`"); statement.addBatch("ALTER IGNORE TABLE `plot_settings` ADD `flags` VARCHAR(512) DEFAULT NULL"); - statement.addBatch("ALTER IGNORE TABLE `plot_settings` ADD `merged` int(11) DEFAULT 0"); + statement.executeBatch(); + statement.close(); + } + rs = data.getColumns(null, null, "plot_settings", "merged"); + if (!rs.next()) { + Statement statement = connection.createStatement(); + statement.addBatch("ALTER IGNORE TABLE `plot_settings` ADD `merged` int(11) DEFAULT NULL"); statement.executeBatch(); statement.close(); }