diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 8f4d3f79f..4338a2351 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -167,6 +167,10 @@ public enum C { * Help */ HELP_CATEGORY("&6Current Category&c: &l%category%"), HELP_INFO("&6You need to specify a help category"), HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"), HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c] &c- &6%desc%"), HELP_HEADER("&6Help for Plots"), + /* + * Direction + */ + DIRECTION("&6Current direction: %dir%"), /* * Custom */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index afbd7197c..b8c9e3b74 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -303,15 +303,7 @@ public class PlayerFunctions { */ @SuppressWarnings("SuspiciousNameCombination") public static int getAllowedPlots(Player p) { - if (p.hasPermission("plots.admin")) { - return Integer.MAX_VALUE; - } - for (int x = 0; x <= 100; x++) { - if (p.hasPermission("plots.plot." + (100-x))) { - return 100-x; - } - } - return 0; + return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS); } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index 75b7a3ee3..1af690dde 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -59,9 +59,124 @@ public class PlotHelper { } return id; } + + + /** + * TODO auto plot merging + * Merges a set of plots with another set.
+ * - Misuse of this method can result in unusable plots
+ * - currentMegaPlots must be a single plot, or a set of already merged plots
+ * - toMerge must be a list of unmerged plots
+ * - the resultant mega plot must be rectangular
+ * - the plot arrays must be sorted in ascending order
+ * - Road will be removed where required
+ * @param world + * @param player + * @param currentMegaPlots + * @param toMerge + * @param dir1 + * @param dir2 + * @return + */ + public static boolean mergePlot(World world, Player player, ArrayList currentMegaPlots, ArrayList toMerge, int dir1, int dir2) { + + 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); + if (i - 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 @@ -111,24 +225,35 @@ public class PlotHelper { filling_data[i] = result[1]; } + boolean noMerge = false; + if (lesserPlot.id.x == greaterPlot.id.x) { + + noMerge = lesserPlot.settings.getMerged(2); + lesserPlot.settings.setMerged(2, true); greaterPlot.settings.setMerged(0, true); startx--; endx++; } else { + + noMerge = lesserPlot.settings.getMerged(1); + lesserPlot.settings.setMerged(1, true); greaterPlot.settings.setMerged(3, true); startz--; endz++; } + if (!noMerge) { - 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); - setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data); + 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); + setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data); + + } } public static final long nextLong() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 8d4fa90e8..fdfbf3dd7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -33,6 +33,8 @@ import org.bukkit.*; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.*; import org.bukkit.generator.ChunkGenerator; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -93,7 +95,6 @@ public class PlotMain extends JavaPlugin { public static WorldGuardPlugin worldGuard; - /** * !!WorldGeneration!! */ @@ -116,7 +117,57 @@ public class PlotMain extends JavaPlugin { } }, 0l, 12 * 60 * 60 * 20l); } + + /** + * Check a range of permissions e.g. 'plots.plot.<0-100>'
+ * Returns highest integer in range. + * @param player + * @param stub + * @param range + * @return + */ + public static int hasPermissionRange(Player player, String stub, int range) { + if (player.isOp()) { + return range; + } + if (player.hasPermission(stub+".*")) { + return range; + } + for (int i = range; i>0; i--) { + if (player.hasPermission(stub+"."+i)) { + return i; + } + } + return 0; + } + /** + * Check a player for a permission
+ * - Op has all permissions
+ * - checks for '*' nodes + * @param player + * @param perm + * @return + */ + public static boolean hasPermission(Player player, String perm) { + if (player.isOp()) { + return true; + } + if (player.hasPermission(perm)) { + return true; + } + String[] nodes = perm.split("\\."); + StringBuilder n = new StringBuilder(); + for(int i = 0; i < nodes.length-1; i++) { + n.append(nodes[i]+"."); + if (player.hasPermission(n+"*")) { + return true; + } + } + + return false; + } + /** * All loaded plots */ @@ -812,7 +863,7 @@ public class PlotMain extends JavaPlugin { } /** - * SETUP: settings.properties + * SETUP: settings.yml */ private static void setupConfig() { config.set("version", config_ver); @@ -827,6 +878,7 @@ public class PlotMain extends JavaPlugin { options.put("debug", true); options.put("clear.auto.enabled", false); options.put("clear.auto.days", 365); + options.put("max_plots", Settings.MAX_PLOTS); for (Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { @@ -843,6 +895,9 @@ public class PlotMain extends JavaPlugin { Settings.WORLDGUARD = config.getBoolean("worldguard.enabled"); Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding"); Settings.METRICS = config.getBoolean("metrics"); + Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); + Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); + Settings.MAX_PLOTS = config.getInt("max_plots"); for (String node : config.getConfigurationSection("worlds").getKeys(false)) { World world = Bukkit.getWorld(node); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java index a52c57df9..3154476ac 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java @@ -17,6 +17,7 @@ package com.intellectualcrafters.plot; * @author Empire92 */ public class Settings { + public static int MAX_PLOTS = 20; /** * WorldGuard region on claimed plots */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java index 56b2d7d60..178b3f76f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java @@ -43,6 +43,17 @@ public class Merge extends SubCommand { super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS); } + public static String direction(float yaw) { + yaw = yaw / 90; + yaw = (float)Math.round(yaw); + + if (yaw == -4 || yaw == 0 || yaw == 4) {return "SOUTH";} + if (yaw == -1 || yaw == 3) {return "EAST";} + if (yaw == -2 || yaw == 2) {return "NORTH";} + if (yaw == -3 || yaw == 1) {return "WEST";} + return ""; + } + @Override public boolean execute(Player plr, String... args) { if (!PlayerFunctions.isInPlot(plr)) { @@ -72,6 +83,7 @@ public class Merge extends SubCommand { int direction2 = direction > 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())); + PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw()))); return false; } World world = plr.getWorld(); @@ -115,106 +127,7 @@ public class Merge extends SubCommand { 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) { - - 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); - if (i