diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/MessagePart.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/MessagePart.java index 6c2e838d6..43cf15e08 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/MessagePart.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/chat/MessagePart.java @@ -134,7 +134,7 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa json.endObject(); } catch (IOException e) { Bukkit.getLogger() - .log(Level.WARNING, "A problem occured during writing of JSON string", e); + .log(Level.WARNING, "A problem occurred during writing of JSON string", e); } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index 55d3dbc1e..a1a358737 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -174,7 +174,7 @@ import java.util.*; * * @param player the recipient of the message * @param caption the message - * @see MainUtil#sendMessage(PlotPlayer, Captions, String...) + * @see MainUtil#sendMessage(com.github.intellectualsites.plotsquared.commands.CommandCaller, Captions, String...) */ public static void sendMessage(Player player, Captions caption) { MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java index b637292c1..bf803d712 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java @@ -13,7 +13,6 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.*; import java.io.IOException; -import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; @@ -56,10 +55,9 @@ public abstract class Command { public Command(Command parent, boolean isStatic) { this.parent = parent; this.isStatic = isStatic; - Annotation cdAnnotation = getClass().getAnnotation(CommandDeclaration.class); + CommandDeclaration cdAnnotation = getClass().getAnnotation(CommandDeclaration.class); if (cdAnnotation != null) { - CommandDeclaration declaration = (CommandDeclaration) cdAnnotation; - init(declaration); + init(cdAnnotation); } for (final Method method : getClass().getDeclaredMethods()) { if (method.isAnnotationPresent(CommandDeclaration.class)) { @@ -101,7 +99,7 @@ public abstract class Command { return this.id; } - public List getCommands(PlotPlayer player) { + public List getCommands(CommandCaller player) { List commands = new ArrayList<>(); for (Command cmd : this.allCommands) { if (cmd.canExecute(player, false)) { @@ -111,10 +109,10 @@ public abstract class Command { return commands; } - public List getCommands(CommandCategory cat, PlotPlayer player) { + public List getCommands(CommandCategory category, CommandCaller player) { List commands = getCommands(player); - if (cat != null) { - commands.removeIf(command -> command.category != cat); + if (category != null) { + commands.removeIf(command -> command.category != category); } return commands; } @@ -123,7 +121,7 @@ public abstract class Command { return this.allCommands; } - public boolean hasConfirmation(PlotPlayer player) { + public boolean hasConfirmation(CommandCaller player) { return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass"); } @@ -272,7 +270,7 @@ public abstract class Command { } return; } - if (this.allCommands == null || this.allCommands.isEmpty()) { + if (this.allCommands.isEmpty()) { player.sendMessage( "Not Implemented: https://github.com/IntellectualSites/PlotSquared/issues/new"); return; @@ -285,13 +283,13 @@ public abstract class Command { } // Help command try { - if (args.length == 0 || MathMan.isInteger(args[0]) - || CommandCategory.valueOf(args[0].toUpperCase()) != null) { - // This will default certain syntax to the help command - // e.g. /plot, /plot 1, /plot claiming - MainCommand.getInstance().help.execute(player, args, null, null); - return; + if (!MathMan.isInteger(args[0])) { + CommandCategory.valueOf(args[0].toUpperCase()); } + // This will default certain syntax to the help command + // e.g. /plot, /plot 1, /plot claiming + MainCommand.getInstance().help.execute(player, args, null, null); + return; } catch (IllegalArgumentException ignored) { } // Command recommendation @@ -328,7 +326,7 @@ public abstract class Command { } } - public boolean checkArgs(PlotPlayer player, String[] args) { + public boolean checkArgs(CommandCaller player, String[] args) { Argument[] reqArgs = getRequiredArguments(); if (reqArgs != null && reqArgs.length > 0) { boolean failed = args.length < reqArgs.length; @@ -421,7 +419,7 @@ public abstract class Command { return null; } - public boolean canExecute(PlotPlayer player, boolean message) { + public boolean canExecute(CommandCaller player, boolean message) { if (player == null) { return true; } @@ -447,7 +445,6 @@ public abstract class Command { } public String getCommandString() { - String base; if (this.parent == null) { return "/" + toString(); } else { @@ -577,7 +574,7 @@ public abstract class Command { this.args = args; } - public void perform(PlotPlayer player) { + public void perform(CommandCaller player) { if (player != null && message != null) { message.send(player, args); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java index 7b1b75432..6398b30be 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java @@ -26,6 +26,7 @@ import java.util.Set; @Override public void execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, final RunnableVal2 whenDone) { + check(EconHandler.manager, Captions.ECON_DISABLED); final Plot plot; if (args.length != 0) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java index 453a6a8ac..2b988c85d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Chat.java @@ -4,8 +4,8 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @CommandDeclaration(command = "chat", description = "Toggle plot chat on or off", - usage = "/plot chat [on|off]", permission = "plots.chat", category = CommandCategory.CHAT, - requiredType = RequiredType.NONE) public class Chat extends SubCommand { + usage = "/plot chat [on|off]", permission = "plots.chat", category = CommandCategory.CHAT, requiredType = RequiredType.PLAYER) +public class Chat extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { MainCommand.getInstance().toggle.chat(this, player, new String[0], null, null); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java index 4aeacf85c..f0ffc71a8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/CommandCategory.java @@ -50,6 +50,8 @@ public enum CommandCategory { this.name = name; } + + @Override public String toString() { return this.name; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java index 623b989ea..d75084407 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java @@ -31,6 +31,8 @@ import java.util.*; private Bindings scope; public DebugExec() { + init(); +/* try { if (PlotSquared.get() != null) { File file = new File(PlotSquared.get().IMP.getDirectory(), @@ -49,6 +51,7 @@ import java.util.*; } catch (IOException | ScriptException ignored) { ignored.printStackTrace(); } +*/ } public ScriptEngine getEngine() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java index 674ba4fe9..f186f3219 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; +import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; @@ -18,7 +19,7 @@ public class Help extends Command { super(parent, true); } - @Override public boolean canExecute(PlotPlayer player, boolean message) { + @Override public boolean canExecute(CommandCaller player, boolean message) { return true; } @@ -54,7 +55,7 @@ public class Help extends Command { } } - public void displayHelp(PlotPlayer player, String cat, int page) { + public void displayHelp(CommandCaller player, String cat, int page) { CommandCategory catEnum = null; if (cat != null) { if (StringMan.isEqualIgnoreCase(cat, "all")) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java index 6f3ba0d28..ccb4558fb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java @@ -1,8 +1,8 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; +import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; -import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm; @@ -126,27 +126,23 @@ public class MainCommand extends Command { @Override public void run(final Command cmd, final Runnable success, final Runnable failure) { if (cmd.hasConfirmation(player)) { - CmdConfirm.addPending(player, cmd.getUsage(), new Runnable() { - @Override public void run() { - if (EconHandler.manager != null) { - PlotArea area = player.getApplicablePlotArea(); - if (area != null) { - Expression priceEval = - area.PRICES.get(cmd.getFullId()); - Double price = - priceEval != null ? priceEval.evaluate(0d) : 0d; - if (price != null - && EconHandler.manager.getMoney(player) < price) { - if (failure != null) { - failure.run(); - } - return; + CmdConfirm.addPending(player, cmd.getUsage(), () -> { + if (EconHandler.manager != null) { + PlotArea area = player.getApplicablePlotArea(); + if (area != null) { + Expression priceEval = area.PRICES.get(cmd.getFullId()); + Double price = priceEval != null ? priceEval.evaluate(0d) : 0d; + if (price != null + && EconHandler.manager.getMoney(player) < price) { + if (failure != null) { + failure.run(); } + return; } } - if (success != null) { - success.run(); - } + } + if (success != null) { + success.run(); } }); return; @@ -180,13 +176,6 @@ public class MainCommand extends Command { return true; } - @Deprecated - /** - * @Deprecated legacy - */ public void addCommand(SubCommand command) { - PlotSquared.debug("Command registration is now done during instantiation"); - } - @Override public void execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { @@ -281,7 +270,7 @@ public class MainCommand extends Command { } } - @Override public boolean canExecute(PlotPlayer player, boolean message) { + @Override public boolean canExecute(CommandCaller player, boolean message) { return true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java index 7c9705475..66f4fc06b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java @@ -16,8 +16,8 @@ import java.util.Map.Entry; import java.util.UUID; @CommandDeclaration(command = "rate", permission = "plots.rate", description = "Rate the plot", - usage = "/plot rate [#|next|purge]", aliases = "rt", category = CommandCategory.INFO, - requiredType = RequiredType.NONE) public class Rate extends SubCommand { + usage = "/plot rate [#|next|purge]", aliases = "rt", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER) +public class Rate extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 1) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RequiredType.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RequiredType.java index 3f13368de..2dc75f919 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RequiredType.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/RequiredType.java @@ -6,11 +6,9 @@ public enum RequiredType { CONSOLE, PLAYER, NONE; public boolean allows(CommandCaller player) { - switch (this) { - case NONE: - return true; - default: - return this == player.getSuperCaller(); + if (this == RequiredType.NONE) { + return true; } + return this == player.getSuperCaller(); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java index b8191dd72..6724efdda 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java @@ -16,7 +16,7 @@ import java.util.Iterator; import java.util.Set; import java.util.UUID; -@CommandDeclaration(command = "trust", aliases = {"t"}, requiredType = RequiredType.NONE, +@CommandDeclaration(command = "trust", aliases = {"t"}, requiredType = RequiredType.PLAYER, usage = "/plot trust ", description = "Allow a user to build in a plot while you are offline", category = CommandCategory.SETTINGS) public class Trust extends Command { @@ -28,16 +28,19 @@ import java.util.UUID; @Override public void execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { - final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT); - checkTrue(plot.hasOwner(), Captions.PLOT_UNOWNED); - checkTrue(plot.isOwner(player.getUUID()) || Permissions + final Plot currentPlot = player.getCurrentPlot(); + if (currentPlot == null) { + throw new CommandException(Captions.NOT_IN_PLOT); + } + checkTrue(currentPlot.hasOwner(), Captions.PLOT_UNOWNED); + checkTrue(currentPlot.isOwner(player.getUUID()) || Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST), Captions.NO_PLOT_PERMS); checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage()); final Set uuids = MainUtil.getUUIDsFromString(args[0]); checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]); Iterator iter = uuids.iterator(); - int size = plot.getTrusted().size() + plot.getMembers().size(); + int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size(); while (iter.hasNext()) { UUID uuid = iter.next(); if (uuid == DBFunc.EVERYONE && !( @@ -47,34 +50,34 @@ import java.util.UUID; iter.remove(); continue; } - if (plot.isOwner(uuid)) { + if (currentPlot.isOwner(uuid)) { MainUtil.sendMessage(player, Captions.ALREADY_OWNER, MainUtil.getName(uuid)); iter.remove(); continue; } - if (plot.getTrusted().contains(uuid)) { + if (currentPlot.getTrusted().contains(uuid)) { MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); iter.remove(); continue; } - size += plot.getMembers().contains(uuid) ? 0 : 1; + size += currentPlot.getMembers().contains(uuid) ? 0 : 1; } checkTrue(!uuids.isEmpty(), null); - checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions + checkTrue(size <= currentPlot.getArea().MAX_PLOT_MEMBERS || Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST), Captions.PLOT_MAX_MEMBERS); // Success confirm.run(this, () -> { for (UUID uuid : uuids) { if (uuid != DBFunc.EVERYONE) { - if (!plot.removeMember(uuid)) { - if (plot.getDenied().contains(uuid)) { - plot.removeDenied(uuid); + if (!currentPlot.removeMember(uuid)) { + if (currentPlot.getDenied().contains(uuid)) { + currentPlot.removeDenied(uuid); } } } - plot.addTrusted(uuid); - EventUtil.manager.callTrusted(player, plot, uuid, true); + currentPlot.addTrusted(uuid); + EventUtil.manager.callTrusted(player, currentPlot, uuid, true); MainUtil.sendMessage(player, Captions.TRUSTED_ADDED); } }, null); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Unlink.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Unlink.java index 3a4d034eb..abca00a79 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Unlink.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Unlink.java @@ -8,8 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.*; @CommandDeclaration(command = "unlink", aliases = {"u", "unmerge"}, - description = "Unlink a mega-plot", usage = "/plot unlink [createroads]", - requiredType = RequiredType.NONE, category = CommandCategory.SETTINGS, confirmation = true) + description = "Unlink a mega-plot", usage = "/plot unlink [createroads]", requiredType = RequiredType.PLAYER, category = CommandCategory.SETTINGS, confirmation = true) public class Unlink extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java index d262ca343..e8ebfa642 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java @@ -14,8 +14,8 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import java.util.*; @CommandDeclaration(command = "visit", permission = "plots.visit", - description = "Visit someones plot", usage = "/plot visit [|||] [#]", - aliases = {"v", "tp", "teleport", "goto", "home", "h"}, requiredType = RequiredType.NONE, + description = "Visit someones plot", usage = "/plot visit [|||] [#]", aliases = { + "v", "tp", "teleport", "goto", "home", "h"}, requiredType = RequiredType.PLAYER, category = CommandCategory.TELEPORT) public class Visit extends Command { public Visit() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 0b161b082..88ac6dc31 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -920,15 +920,15 @@ public class Plot { } if (this.area.TERRAIN != 3 && createRoad) { for (Plot current : plots) { - if (current.getMerged(1)) { + if (current.getMerged(Direction.EAST)) { manager.createRoadEast(current.area, current); - if (current.getMerged(2)) { + if (getMerged(Direction.SOUTH)) { manager.createRoadSouth(current.area, current); - if (current.getMerged(5)) { + if (getMerged(Direction.SOUTHEAST)) { manager.createRoadSouthEast(current.area, current); } } - } else if (current.getMerged(2)) { + } else if (getMerged(Direction.SOUTH)) { manager.createRoadSouth(current.area, current); } } @@ -1624,11 +1624,11 @@ public class Plot { if (!this.isMerged()) { return top; } - if (this.getMerged(Direction.SOUTH.getIndex())) { - top.setZ(this.getRelative(Direction.SOUTH.getIndex()).getBottomAbs().getZ() - 1); + if (this.getMerged(Direction.SOUTH)) { + top.setZ(this.getRelative(Direction.SOUTH).getBottomAbs().getZ() - 1); } - if (this.getMerged(Direction.EAST.getIndex())) { - top.setX(this.getRelative(Direction.SOUTH.getIndex()).getBottomAbs().getX() - 1); + if (this.getMerged(Direction.EAST)) { + top.setX(this.getRelative(Direction.SOUTH).getBottomAbs().getX() - 1); } return top; } @@ -1645,11 +1645,11 @@ public class Plot { if (!this.isMerged()) { return bot; } - if (this.getMerged(Direction.NORTH.getIndex())) { - bot.setZ(this.getRelative(Direction.NORTH.getIndex()).getTopAbs().getZ() + 1); + if (this.getMerged(Direction.NORTH)) { + bot.setZ(this.getRelative(Direction.NORTH).getTopAbs().getZ() + 1); } - if (this.getMerged(Direction.WEST.getIndex())) { - bot.setX(this.getRelative(Direction.WEST.getIndex()).getTopAbs().getX() + 1); + if (this.getMerged(Direction.WEST)) { + bot.setX(this.getRelative(Direction.WEST).getTopAbs().getX() + 1); } return bot; } @@ -1678,7 +1678,7 @@ public class Plot { if (this.area.TERRAIN == 3) { return; } - Plot other = this.getRelative(Direction.EAST.getIndex()); + Plot other = this.getRelative(Direction.EAST); Location bot = other.getBottomAbs(); Location top = this.getTopAbs(); Location pos1 = new Location(this.getWorldName(), top.getX(), 0, bot.getZ()); @@ -2147,7 +2147,7 @@ public class Plot { if (this.area.TERRAIN == 3) { return; } - Plot other = this.getRelative(2); + Plot other = this.getRelative(Direction.SOUTH); Location bot = other.getBottomAbs(); Location top = this.getTopAbs(); Location pos1 = new Location(this.getWorldName(), bot.getX(), 0, top.getZ()); @@ -2192,8 +2192,8 @@ public class Plot { } visited.add(current); Set plots; - if ((dir == -1 || dir == 0) && !current.getMerged(0)) { - Plot other = current.getRelative(0); + if ((dir == -1 || dir == 0) && !getMerged(Direction.NORTH)) { + Plot other = current.getRelative(Direction.NORTH); if (other != null && other.isOwner(uuid) && ( other.getBasePlot(false).equals(current.getBasePlot(false)) || (plots = other.getConnectedPlots()).size() <= max && frontier @@ -2204,8 +2204,8 @@ public class Plot { toReturn = true; } } - if (max >= 0 && (dir == -1 || dir == 1) && !current.getMerged(1)) { - Plot other = current.getRelative(1); + if (max >= 0 && (dir == -1 || dir == 1) && !current.getMerged(Direction.EAST)) { + Plot other = current.getRelative(Direction.EAST); if (other != null && other.isOwner(uuid) && ( other.getBasePlot(false).equals(current.getBasePlot(false)) || (plots = other.getConnectedPlots()).size() <= max && frontier @@ -2216,8 +2216,8 @@ public class Plot { toReturn = true; } } - if (max >= 0 && (dir == -1 || dir == 2) && !current.getMerged(2)) { - Plot other = current.getRelative(2); + if (max >= 0 && (dir == -1 || dir == 2) && !getMerged(Direction.SOUTH)) { + Plot other = current.getRelative(Direction.SOUTH); if (other != null && other.isOwner(uuid) && ( other.getBasePlot(false).equals(current.getBasePlot(false)) || (plots = other.getConnectedPlots()).size() <= max && frontier @@ -2228,8 +2228,8 @@ public class Plot { toReturn = true; } } - if (max >= 0 && (dir == -1 || dir == 3) && !current.getMerged(3)) { - Plot other = current.getRelative(3); + if (max >= 0 && (dir == -1 || dir == 3) && !getMerged(Direction.WEST)) { + Plot other = current.getRelative(Direction.WEST); if (other != null && other.isOwner(uuid) && ( other.getBasePlot(false).equals(current.getBasePlot(false)) || (plots = other.getConnectedPlots()).size() <= max && frontier @@ -2344,6 +2344,21 @@ public class Plot { return this.area.getPlotAbs(this.id.getRelative(direction)); } + /** + * Gets the plot in a relative direction
+ * 0 = north
+ * 1 = east
+ * 2 = south
+ * 3 = west
+ * Note: May be null if the partial plot area does not include the relative location + * + * @param direction + * @return + */ + public Plot getRelative(Direction direction) { + return this.area.getPlotAbs(this.id.getRelative(direction)); + } + /** * Gets a set of plots connected (and including) this plot
* - This result is cached globally @@ -2370,8 +2385,8 @@ public class Plot { tmpSet.add(this); Plot tmp; if (merged[0]) { - tmp = this.area.getPlotAbs(this.id.getRelative(0)); - if (!tmp.getMerged(2)) { + tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH)); + if (!tmp.getMerged(Direction.SOUTH)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(this.owner)) { @@ -2386,8 +2401,8 @@ public class Plot { frontier.add(tmp); } if (merged[1]) { - tmp = this.area.getPlotAbs(this.id.getRelative(1)); - if (!tmp.getMerged(3)) { + tmp = this.area.getPlotAbs(this.id.getRelative(Direction.EAST)); + if (!tmp.getMerged(Direction.WEST)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(this.owner)) { @@ -2402,8 +2417,8 @@ public class Plot { frontier.add(tmp); } if (merged[2]) { - tmp = this.area.getPlotAbs(this.id.getRelative(2)); - if (!tmp.getMerged(0)) { + tmp = this.area.getPlotAbs(this.id.getRelative(Direction.SOUTH)); + if (!tmp.getMerged(Direction.NORTH)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(this.owner)) { @@ -2418,8 +2433,8 @@ public class Plot { frontier.add(tmp); } if (merged[3]) { - tmp = this.area.getPlotAbs(this.id.getRelative(3)); - if (!tmp.getMerged(1)) { + tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST)); + if (!tmp.getMerged(Direction.EAST)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(this.owner)) { @@ -2446,28 +2461,28 @@ public class Plot { queuecache.remove(current); merged = current.getMerged(); if (merged[0]) { - tmp = current.area.getPlotAbs(current.id.getRelative(0)); + tmp = current.area.getPlotAbs(current.id.getRelative(Direction.NORTH)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); frontier.add(tmp); } } if (merged[1]) { - tmp = current.area.getPlotAbs(current.id.getRelative(1)); + tmp = current.area.getPlotAbs(current.id.getRelative(Direction.EAST)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); frontier.add(tmp); } } if (merged[2]) { - tmp = current.area.getPlotAbs(current.id.getRelative(2)); + tmp = current.area.getPlotAbs(current.id.getRelative(Direction.SOUTH)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); frontier.add(tmp); } } if (merged[3]) { - tmp = current.area.getPlotAbs(current.id.getRelative(3)); + tmp = current.area.getPlotAbs(current.id.getRelative(Direction.WEST)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); frontier.add(tmp); @@ -2516,7 +2531,8 @@ public class Plot { boolean tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(2) || visited.contains(plot.getId())) { + if (plot == null || !plot.getMerged(Direction.SOUTH) || visited + .contains(plot.getId())) { tmp = false; } } @@ -2529,7 +2545,8 @@ public class Plot { tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(3) || visited.contains(plot.getId())) { + if (plot == null || !plot.getMerged(Direction.WEST) || visited + .contains(plot.getId())) { tmp = false; } } @@ -2542,7 +2559,8 @@ public class Plot { tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(0) || visited.contains(plot.getId())) { + if (plot == null || !plot.getMerged(Direction.NORTH) || visited + .contains(plot.getId())) { tmp = false; } } @@ -2555,7 +2573,8 @@ public class Plot { tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(1) || visited.contains(plot.getId())) { + if (plot == null || !plot.getMerged(Direction.EAST) || visited + .contains(plot.getId())) { tmp = false; } } @@ -2569,14 +2588,14 @@ public class Plot { visited.addAll(MainUtil.getPlotSelectionIds(bot, top)); for (int x = bot.x; x <= top.x; x++) { Plot plot = this.area.getPlotAbs(new PlotId(x, top.y)); - if (plot.getMerged(2)) { + if (plot.getMerged(Direction.SOUTH)) { // south wedge Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); Location topabs = plot.getTopAbs(); regions.add(new RegionWrapper(botabs.getX(), topabs.getX(), topabs.getZ() + 1, toploc.getZ())); - if (plot.getMerged(5)) { + if (plot.getMerged(Direction.SOUTHEAST)) { regions.add( new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1, toploc.getZ())); @@ -2587,14 +2606,14 @@ public class Plot { for (int y = bot.y; y <= top.y; y++) { Plot plot = this.area.getPlotAbs(new PlotId(top.x, y)); - if (plot.getMerged(1)) { + if (plot.getMerged(Direction.EAST)) { // east wedge Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); Location topabs = plot.getTopAbs(); regions.add(new RegionWrapper(topabs.getX() + 1, toploc.getX(), botabs.getZ(), topabs.getZ())); - if (plot.getMerged(5)) { + if (plot.getMerged(Direction.SOUTHEAST)) { regions.add( new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1, toploc.getZ())); @@ -2776,7 +2795,7 @@ public class Plot { lesserPlot = greaterPlot; greaterPlot = tmp; } - if (!lesserPlot.getMerged(2)) { + if (!lesserPlot.getMerged(Direction.SOUTH)) { lesserPlot.clearRatings(); greaterPlot.clearRatings(); lesserPlot.setMerged(2, true); @@ -2784,13 +2803,13 @@ public class Plot { lesserPlot.mergeData(greaterPlot); if (removeRoads) { lesserPlot.removeRoadSouth(); - Plot diagonal = greaterPlot.getRelative(1); - if (diagonal.getMerged(7)) { + Plot diagonal = greaterPlot.getRelative(Direction.EAST); + if (diagonal.getMerged(Direction.NORTHWEST)) { lesserPlot.removeRoadSouthEast(); } - Plot below = greaterPlot.getRelative(3); - if (below.getMerged(4)) { - below.getRelative(0).removeRoadSouthEast(); + Plot below = greaterPlot.getRelative(Direction.WEST); + if (below.getMerged(Direction.NORTHEAST)) { + below.getRelative(Direction.NORTH).removeRoadSouthEast(); } } } @@ -2800,22 +2819,22 @@ public class Plot { lesserPlot = greaterPlot; greaterPlot = tmp; } - if (!lesserPlot.getMerged(1)) { + if (!lesserPlot.getMerged(Direction.EAST)) { lesserPlot.clearRatings(); greaterPlot.clearRatings(); lesserPlot.setMerged(1, true); greaterPlot.setMerged(3, true); lesserPlot.mergeData(greaterPlot); if (removeRoads) { - Plot diagonal = greaterPlot.getRelative(2); - if (diagonal.getMerged(7)) { + Plot diagonal = greaterPlot.getRelative(Direction.SOUTH); + if (diagonal.getMerged(Direction.NORTHWEST)) { lesserPlot.removeRoadSouthEast(); } lesserPlot.removeRoadEast(); } - Plot below = greaterPlot.getRelative(0); - if (below.getMerged(6)) { - below.getRelative(3).removeRoadSouthEast(); + Plot below = greaterPlot.getRelative(Direction.NORTH); + if (below.getMerged(Direction.SOUTHWEST)) { + below.getRelative(Direction.WEST).removeRoadSouthEast(); } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index 594da7962..f5cc16779 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -560,6 +560,7 @@ public abstract class PlotArea { return this.plots.entrySet().stream().anyMatch(entry -> entry.getValue().isOwner(uuid)); } + //todo check if this method is needed in this class public int getPlotCount(@Nullable final PlotPlayer player) { return player != null ? getPlotCount(player.getUUID()) : 0; } @@ -876,19 +877,19 @@ public abstract class PlotArea { Plot plot2; if (lx) { if (ly) { - if (!plot.getMerged(1) || !plot.getMerged(2)) { + if (!plot.getMerged(Direction.EAST) || !plot.getMerged(Direction.SOUTH)) { if (removeRoads) { plot.removeRoadSouthEast(); } } } - if (!plot.getMerged(1)) { + if (!plot.getMerged(Direction.EAST)) { plot2 = plot.getRelative(1, 0); plot.mergePlot(plot2, removeRoads); } } if (ly) { - if (!plot.getMerged(2)) { + if (!plot.getMerged(Direction.SOUTH)) { plot2 = plot.getRelative(0, 1); plot.mergePlot(plot2, removeRoads); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java index 1f883cb08..8c4b78445 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java @@ -86,6 +86,9 @@ public class PlotId { } } + public PlotId getRelative(Direction direction) { + return getRelative(direction.getIndex()); + } /** * Get the PlotId in a relative direction * 0 = north
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index f7fd8dc76..fa1a527fd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -1,5 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.util; +import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; @@ -576,7 +577,7 @@ public class MainUtil { * @param prefix If the message should be prefixed with the configured prefix * @return */ - public static boolean sendMessage(PlotPlayer player, String msg, boolean prefix) { + public static boolean sendMessage(CommandCaller player, String msg, boolean prefix) { if (!msg.isEmpty()) { if (player == null) { String message = (prefix ? Captions.PREFIX.s() : "") + msg; @@ -595,7 +596,7 @@ public class MainUtil { * @param caption the message to send * @return boolean success */ - public static boolean sendMessage(PlotPlayer player, Captions caption, String... args) { + public static boolean sendMessage(CommandCaller player, Captions caption, String... args) { return sendMessage(player, caption, (Object[]) args); } @@ -606,19 +607,17 @@ public class MainUtil { * @param caption the message to send * @return boolean success */ - public static boolean sendMessage(final PlotPlayer player, final Captions caption, + public static boolean sendMessage(final CommandCaller player, final Captions caption, final Object... args) { if (caption.s().isEmpty()) { return true; } - TaskManager.runTaskAsync(new Runnable() { - @Override public void run() { - String m = Captions.format(caption, args); - if (player == null) { - PlotSquared.log(m); - } else { - player.sendMessage(m); - } + TaskManager.runTaskAsync(() -> { + String m = Captions.format(caption, args); + if (player == null) { + PlotSquared.log(m); + } else { + player.sendMessage(m); } }); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java index c4716b8ef..c10d9507b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpMenu.java @@ -1,24 +1,24 @@ package com.github.intellectualsites.plotsquared.plot.util.helpmenu; import com.github.intellectualsites.plotsquared.commands.Command; +import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; import com.github.intellectualsites.plotsquared.plot.commands.MainCommand; -import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import java.util.List; public class HelpMenu { - public static final int PER_PAGE = 5; + private static final int PER_PAGE = 5; - private final PlotPlayer player; + private final CommandCaller commandCaller; private HelpPage page = new HelpPage(CommandCategory.INFO, 0, 0); private int maxPage; private CommandCategory commandCategory; private List commands; - public HelpMenu(PlotPlayer player) { - this.player = player; + public HelpMenu(CommandCaller commandCaller) { + this.commandCaller = commandCaller; } public HelpMenu setCategory(CommandCategory commandCategory) { @@ -27,7 +27,8 @@ public class HelpMenu { } public HelpMenu getCommands() { - this.commands = MainCommand.getInstance().getCommands(this.commandCategory, this.player); + this.commands = + MainCommand.getInstance().getCommands(this.commandCategory, this.commandCaller); return this; } @@ -52,7 +53,7 @@ public class HelpMenu { } public void render() { - this.page.render(this.player); + this.page.render(this.commandCaller); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java index ab0ac49a1..3f29aefb1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/helpmenu/HelpPage.java @@ -1,8 +1,8 @@ package com.github.intellectualsites.plotsquared.plot.util.helpmenu; +import com.github.intellectualsites.plotsquared.commands.CommandCaller; import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; @@ -21,7 +21,7 @@ public class HelpPage { .replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + ""); } - public void render(PlotPlayer player) { + public void render(CommandCaller player) { if (this.helpObjects.size() < 1) { MainUtil.sendMessage(player, Captions.NOT_VALID_NUMBER, "(0)"); } else {