diff --git a/pom.xml b/pom.xml index 76de12486..45e89a318 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.2.21 + 3.2.22 PlotSquared jar diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 762a31d16..fe281bb52 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -22,20 +22,17 @@ package com.intellectualcrafters.plot.commands; import java.util.Set; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration(command = "clear", description = "Clear a plot", permission = "plots.clear", category = CommandCategory.ACTIONS, usage = "/plot clear [id]") @@ -45,34 +42,34 @@ public class Clear extends SubCommand { public boolean onCommand(final PlotPlayer plr, final String... args) { final Location loc = plr.getLocation(); final Plot plot; - if (args.length == 2) { - final PlotId id = PlotId.fromString(args[0]); - if (id == null) { - if (args[1].equalsIgnoreCase("mine")) { - final Set plots = PS.get().getPlots(plr); - if (plots.size() == 0) { - MainUtil.sendMessage(plr, C.NO_PLOTS); - return false; - } + if (args.length == 1) { + if (args[0].equalsIgnoreCase("mine")) { + Set plots = plr.getPlots(); + if (plots.size() > 0) { plot = plots.iterator().next(); } else { - MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]"); + MainUtil.sendMessage(plr, C.NO_PLOTS); return false; } } else { - plot = MainUtil.getPlotAbs(loc.getWorld(), id); + plot = MainUtil.getPlotFromString(plr, args[0], true); + } + if (plot == null) { + MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]"); + return false; + } + } else if (args.length == 0) { + plot = MainUtil.getPlotAbs(loc); + if (plot == null) { + MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]"); + C.NOT_IN_PLOT.send(plr); + return false; } } else { - plot = MainUtil.getPlotAbs(loc); - } - if (plot == null) { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]"); - return sendMessage(plr, C.NOT_IN_PLOT); + return false; } - // if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { - // return sendMessage(plr, C.UNLINK_REQUIRED); - // } - if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { + if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { return sendMessage(plr, C.NO_PLOT_PERMS); } if (plot.getRunning() != 0) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Copy.java b/src/main/java/com/intellectualcrafters/plot/commands/Copy.java index ffcfe4bd0..9d56b4ffb 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Copy.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Copy.java @@ -26,7 +26,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -39,10 +38,6 @@ usage = "/plot copy ", requiredType = RequiredType.NONE) public class Copy extends SubCommand { - public Copy() { - requiredArguments = new Argument[] { Argument.PlotID }; - } - @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 6fd9611be..cc9a81376 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -26,12 +26,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.ConsolePlayer; +import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; @@ -205,65 +204,84 @@ public class MainCommand extends CommandManager { } public static boolean onCommand(final PlotPlayer player, final String cmd, String... args) { + // Clear perm caching // + player.deleteMeta("perm"); + //////////////////////// int help_index = -1; String category = null; - if (args.length == 0) { - help_index = 0; - } else if (StringMan.isEqualIgnoreCaseToAny(args[0], "he", "help", "?")) { - help_index = 0; - switch (args.length) { - case 3: { - category = args[1]; - if (MathMan.isInteger(args[2])) { - try { - help_index = Integer.parseInt(args[2]); - } catch (final NumberFormatException e) { - help_index = 1; - } - } - break; - } - case 2: { - if (MathMan.isInteger(args[1])) { - category = null; - try { - help_index = Integer.parseInt(args[1]); - } catch (final NumberFormatException e) { - help_index = 1; - } - } else { - help_index = 1; - category = args[1]; - } + Location loc = null; + switch (args.length) { + case 0: { + help_index = 0; + break; + } + case 1: { + if (MathMan.isInteger(args[0])) { + try { + help_index = Integer.parseInt(args[args.length - 1]); + } catch (final NumberFormatException e) {} break; } } - } else if ((args.length == 1) && MathMan.isInteger(args[args.length - 1])) { - try { - help_index = Integer.parseInt(args[args.length - 1]); - } catch (final NumberFormatException e) {} - } else if (ConsolePlayer.isConsole(player) && (args.length >= 2)) { - final String[] split = args[0].split(";"); - String world; - PlotId id; - if (split.length == 2) { - world = player.getLocation().getWorld(); - id = PlotId.fromString(split[0] + ";" + split[1]); - } else if (split.length == 3) { - world = split[0]; - id = PlotId.fromString(split[1] + ";" + split[2]); - } else { - id = null; - world = null; - } - if ((id != null) && PS.get().isPlotWorld(world)) { - final Plot plot = MainUtil.getPlotAbs(world, id); - if (plot != null) { - player.teleport(plot.getBottomAbs()); - args = Arrays.copyOfRange(args, 1, args.length); + default: { + switch (args[0].toLowerCase()) { + case "he": + case "help": + case "?": { + switch (args.length) { + case 1: { + help_index = 0; + break; + } + case 2: { + if (MathMan.isInteger(args[1])) { + category = null; + try { + help_index = Integer.parseInt(args[1]); + } catch (final NumberFormatException e) { + help_index = 1; + } + } else { + help_index = 1; + category = args[1]; + } + break; + } + case 3: { + category = args[1]; + if (MathMan.isInteger(args[2])) { + try { + help_index = Integer.parseInt(args[2]); + } catch (final NumberFormatException e) { + help_index = 1; + } + } + break; + } + default: { + C.COMMAND_SYNTAX.send(player, "/" + cmd + "? [#||category [#]]"); + return true; + } + } + break; + } + default: { + if (args.length >= 2) { + String world = player.getLocation().getWorld(); + Plot plot = Plot.fromString(world, args[0]); + if (plot == null) { + break; + } + if (!ConsolePlayer.isConsole(player) && (!plot.world.equals(world) || plot.isDenied(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN)) { + break; + } + loc = (Location) player.getMeta("location"); + player.setMeta("location", plot.getBottomAbs()); + args = Arrays.copyOfRange(args, 1, args.length); + } + } } } - } if (help_index != -1) { displayHelp(player, category, help_index, cmd); @@ -274,6 +292,9 @@ public class MainCommand extends CommandManager { } String fullCmd = StringMan.join(args, " "); getInstance().handle(player, cmd + " " + fullCmd); + if (loc != null) { + player.setMeta("location", loc); + } return true; } @@ -320,9 +341,6 @@ public class MainCommand extends CommandManager { @Override public int handle(final PlotPlayer plr, final String input) { - // Clear perm caching // - plr.deleteMeta("perm"); - //////////////////////// final String[] parts = input.split(" "); String[] args; String label; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/src/main/java/com/intellectualcrafters/plot/commands/Move.java index 8de95945c..cd622470b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -26,7 +26,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -39,10 +38,6 @@ category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE) public class Move extends SubCommand { - public Move() { - requiredArguments = new Argument[] { Argument.PlotID }; - } - @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 865a68e5d..1167efc77 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -49,7 +49,6 @@ import com.intellectualcrafters.plot.util.TaskManager; /** * The plot class - * */ @SuppressWarnings("javadoc") public class Plot { @@ -74,8 +73,9 @@ public class Plot { public UUID owner; /** - * Plot creation timestamp (rough) - * Direct access is Deprecated: use getTimestamp() + * Plot creation timestamp (not accurate if the plot was created before this was implemented)
+ * - Milliseconds since the epoch
+ * Direct access is Deprecated: use {@link #getTimestamp() getTimestamp} */ @Deprecated public long timestamp; @@ -171,6 +171,23 @@ public class Plot { return MainUtil.getPlot(world, id); } + public static Plot fromString(String defaultWorld, String string) { + final String[] split = string.split(";|,"); + if (split.length == 2) { + if (PS.get().isPlotWorld(defaultWorld)) { + PlotId id = PlotId.fromString(split[0] + ";" + split[1]); + return Plot.getPlot(defaultWorld, id); + } + } else if (split.length == 3) { + defaultWorld = split[0]; + if (PS.get().isPlotWorld(defaultWorld)) { + PlotId id = PlotId.fromString(split[1] + ";" + split[2]); + return Plot.getPlot(defaultWorld, id); + } + } + return null; + } + /** * Return a new/cached plot object at a given location * @@ -250,7 +267,9 @@ public class Plot { } /** - * Get the metadata for a key + * Get the metadata for a key
+ *
+ * For persistent metadata use the flag system * @param key * @return */ @@ -275,7 +294,7 @@ public class Plot { /** * Get the cluster this plot is associated with - * @return + * @return the PlotCluster object, or null */ public PlotCluster getCluster() { if (!Settings.ENABLE_CLUSTERS) { @@ -311,8 +330,10 @@ public class Plot { } /** - * Efficiently get the players currently inside this plot - * @return + * Efficiently get the players currently inside this plot
+ * - Will return an empty list if no players are in the plot
+ * - Remember, you can cast a PlotPlayer to it's respective implementation (BukkitPlayer, SpongePlayer) to obtain the player object + * @return list of PlotPlayer(s) or an empty list */ public List getPlayersInPlot() { return MainUtil.getPlayersInPlot(this); @@ -327,6 +348,11 @@ public class Plot { return owner != null; } + /** + * Check if a UUID is a plot owner (merged plots may have multiple owners) + * @param uuid + * @return + */ public boolean isOwner(final UUID uuid) { return PlotHandler.isOwner(this, uuid); } @@ -370,7 +396,7 @@ public class Plot { /** * Get the plot world object for this plot
- * - The generic PlotWorld object can be casted to it's respective class for more control + * - The generic PlotWorld object can be casted to its respective class for more control (e.g. HybridPlotWorld) * @return PlotWorld */ public PlotWorld getWorld() { @@ -379,7 +405,7 @@ public class Plot { /** * Get the plot manager object for this plot
- * - The generic PlotManager object can be casted to it's respective class for more control + * - The generic PlotManager object can be casted to its respective class for more control (e.g. HybridPlotManager) * @return PlotManager */ public PlotManager getManager() { @@ -450,7 +476,7 @@ public class Plot { } /** - * Check if the plot is merged + * Check if the plot is merged in any direction * @return */ public boolean isMerged() { @@ -461,7 +487,9 @@ public class Plot { } /** - * Get the timestamp in milliseconds of when the plot was created (unreliable) + * Get the timestamp of when the plot was created (unreliable)
+ * - not accurate if the plot was created before this was implemented
+ * - Milliseconds since the epoch
* @return */ public long getTimestamp() { @@ -472,9 +500,21 @@ public class Plot { } /** - * Get if the plot is merged in a direction + * Get if the plot is merged in a direction
+ * ------- Actual -------
+ * 0 = north
+ * 1 = east
+ * 2 = south
+ * 3 = west
+ * ----- Artificial -----
+ * 4 = north-east
+ * 5 = south-east
+ * 6 = south-west
+ * 7 = north-west
+ * ----------
+ * Note: A plot that is merged north and east will not be merged northeast if the northeast plot is not part of the same group
* @param direction - * @return + * @return true if merged in that direction */ public boolean getMerged(final int direction) { if (settings == null) { @@ -536,7 +576,6 @@ public class Plot { /** * Deny someone (updates database as well) - * * @param uuid */ public void addDenied(final UUID uuid) { @@ -903,13 +942,13 @@ public class Plot { } /** - * Returns the top and bottom connected plot.
- * - If the plot is not connected, it will return itself for the top/bottom
- * - the returned IDs will not necessarily correspond to claimed plots if the connected plots do not form a rectangular shape + * Returns the top and bottom location.
+ * - If the plot is not connected, it will return its own corners
+ * - the returned locations will not necessarily correspond to claimed plots if the connected plots do not form a rectangular shape * @deprecated as merged plots no longer need to be rectangular * @param plot - * @return new PlotId[] { bottom, top } - * @see MainUtil#getCornerIds(Plot) + * @return new Location[] { bottom, top } + * @see MainUtil#getCorners(Plot) */ @Deprecated public Location[] getCorners() { @@ -917,7 +956,21 @@ public class Plot { } /** - * @deprecated in favor of getCorners()[0]; + * Returns the top and bottom plot id.
+ * - If the plot is not connected, it will return itself for the top/bottom
+ * - the returned ids will not necessarily correspond to claimed plots if the connected plots do not form a rectangular shape + * @deprecated as merged plots no longer need to be rectangular + * @param plot + * @return new Plot[] { bottom, top } + * @see MainUtil#getCornerIds(Plot) + */ + @Deprecated + public PlotId[] getCornerIds() { + return MainUtil.getCornerIds(this); + } + + /** + * @deprecated in favor of getCorners()[0];
* @return */ @Deprecated @@ -945,8 +998,9 @@ public class Plot { } /** - * This will combine each plot into effective rectangular regions - * - This result is cached globally + * This will combine each plot into effective rectangular regions
+ * - This result is cached globally
+ * - Useful for handling non rectangular shapes * @see MainUtil#getRegions(Plot) * @return */ @@ -1005,8 +1059,8 @@ public class Plot { } /** - * Remove a denied player (use DBFunc as well) - * + * Remove a denied player (use DBFunc as well)
+ * Using the * uuid will remove all users * @param uuid */ public boolean removeDenied(final UUID uuid) { @@ -1021,8 +1075,8 @@ public class Plot { } /** - * Remove a helper (use DBFunc as well) - * + * Remove a helper (use DBFunc as well)
+ * Using the * uuid will remove all users * @param uuid */ public boolean removeTrusted(final UUID uuid) { @@ -1037,8 +1091,8 @@ public class Plot { } /** - * Remove a trusted user (use DBFunc as well) - * + * Remove a trusted user (use DBFunc as well)
+ * Using the * uuid will remove all users * @param uuid */ public boolean removeMember(final UUID uuid) { @@ -1098,7 +1152,7 @@ public class Plot { } /** - * Upload the plot to the configured web interface + * Upload the plot as a schematic to the configured web interface * @param whenDone value will be null if uploading fails */ public void upload(final RunnableVal whenDone) { @@ -1147,6 +1201,11 @@ public class Plot { return id.hashCode(); } + /** + * Get the flags specific to this plot
+ * - Does not take default flags into account
+ * @return + */ public HashMap getFlags() { if (settings == null) { return new HashMap<>(0); @@ -1154,6 +1213,11 @@ public class Plot { return settings.flags; } + /** + * Get the plot Alias
+ * - Returns an empty string if no alias is set + * @return + */ public String getAlias() { if (settings == null) { return ""; @@ -1163,8 +1227,16 @@ public class Plot { /** * Set the raw merge data
- * - Updates DB - * - Does not modify terrain + * - Updates DB
+ * - Does not modify terrain
+ * Get if the plot is merged in a direction
+ * ----------
+ * 0 = north
+ * 1 = east
+ * 2 = south
+ * 3 = west
+ * ----------
+ * Note: Diagonal merging (4-7) must be done by merging the corresponding plots. * @param merged */ public void setMerged(boolean[] merged) { @@ -1180,8 +1252,14 @@ public class Plot { /** * Set the raw merge data
- * - Updates DB - * - Does not modify terrain + * - Updates DB
+ * - Does not modify terrain
+ * ----------
+ * 0 = north
+ * 1 = east
+ * 2 = south
+ * 3 = west
+ * ----------
* @param merged */ public void setMerged(int direction, boolean value) { @@ -1208,6 +1286,10 @@ public class Plot { } } + /** + * Get the merged array + * @return boolean [ north, east, south, west ] + */ public boolean[] getMerged() { if (settings == null) { return new boolean[] {false, false, false, false }; @@ -1215,6 +1297,13 @@ public class Plot { return settings.getMerged(); } + /** + * Get the set home location or 0,0,0 if no location is set
+ * - Does not take the default home location into account + * @see MainUtil#getPlotHome(Plot) + * @see #getHome() + * @return + */ public BlockLoc getPosition() { if (settings == null) { return new BlockLoc(0, 0, 0); diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index bf6804dfe..401350c00 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -17,8 +17,8 @@ import com.plotsquared.general.commands.CommandCaller; import com.plotsquared.listener.PlotListener; /** - * Created 2015-02-20 for PlotSquared - * + * The PlotPlayer class
+ * - Can cast to: BukkitPlayer / SpongePlayer, which are the current implementations
*/ public abstract class PlotPlayer implements CommandCaller { @@ -28,7 +28,7 @@ public abstract class PlotPlayer implements CommandCaller { private ConcurrentHashMap meta; /** - * Efficiently wrap a Player object to get a PlotPlayer (or fetch if it's already cached)
+ * Efficiently wrap a Player, or OfflinePlayer object to get a PlotPlayer (or fetch if it's already cached)
* - Accepts sponge/bukkit Player (online) * - Accepts player name (online) * - Accepts UUID @@ -42,7 +42,7 @@ public abstract class PlotPlayer implements CommandCaller { /** * Get the cached PlotPlayer from a username
- * - This will return null if the player has just logged in or is not online + * - This will return null if the player has not finished logging in or is not online * @param name * @return */ diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index 7729f27c0..c4711815f 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ