From e1c8dcc4be96702a481cdc5417c1c4043d5b089c Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sun, 26 Jul 2015 20:50:54 +0200 Subject: [PATCH] Starting to convert commands to a smarter system :3 --- .../plot/commands/Add.java | 26 ++- .../plot/commands/Auto.java | 18 +- .../plot/commands/Buy.java | 4 +- .../plot/commands/CommandCategory.java | 58 +++++++ .../plot/commands/DebugUUID.java | 29 ++-- .../plot/commands/Delete.java | 22 ++- .../plot/commands/Deny.java | 23 ++- .../plot/commands/Disable.java | 39 ----- .../plot/commands/Download.java | 16 +- .../plot/commands/Help.java | 17 +- .../plot/commands/Home.java | 19 +- .../plot/commands/Inbox.java | 17 +- .../plot/commands/Info.java | 21 ++- .../plot/commands/Inventory.java | 73 -------- .../plot/commands/Kick.java | 17 +- .../plot/commands/Load.java | 19 +- .../plot/commands/MainCommand.java | 29 ++-- .../plot/commands/Merge.java | 22 ++- .../plot/commands/Move.java | 29 ++-- .../plot/commands/MusicSubcommand.java | 16 +- .../plot/commands/Purge.java | 39 +++-- .../plot/commands/Rate.java | 22 ++- .../plot/commands/RegenAllRoads.java | 32 ++-- .../plot/commands/Reload.java | 21 ++- .../plot/commands/Remove.java | 116 +++++++------ .../plot/commands/Save.java | 16 +- .../plot/commands/SetOwner.java | 25 ++- .../plot/commands/Setup.java | 22 ++- .../plot/commands/SubCommand.java | 162 +----------------- .../plot/commands/Swap.java | 22 +-- .../plot/commands/TP.java | 26 ++- .../plot/commands/Target.java | 39 +++-- .../plot/commands/Template.java | 37 ++-- .../plot/commands/Toggle.java | 29 +++- .../plot/commands/Trim.java | 22 ++- .../plot/commands/Trust.java | 25 ++- .../plot/commands/Unclaim.java | 18 +- .../plot/commands/Undeny.java | 74 ++++---- .../plot/commands/Unlink.java | 24 +-- .../plot/commands/Untrust.java | 76 ++++---- .../plot/commands/Update.java | 33 ++-- .../plot/commands/Visit.java | 59 +++---- .../plot/commands/WE_Anywhere.java | 34 ++-- .../plot/commands/callers/ConsoleCaller.java | 36 ++++ .../commands/callers/PlotPlayerCaller.java | 44 +++++ .../plot/commands/list.java | 20 ++- .../plot/commands/plugin.java | 18 +- .../plot/util/MainUtil.java | 19 ++ .../intellectualsites/commands/Argument.java | 84 +++++++++ .../intellectualsites/commands/Command.java | 140 +++++++++++++++ .../commands/CommandDeclaration.java | 27 +++ .../commands/CommandHandlingOutput.java | 31 ++++ .../commands/CommandManager.java | 115 +++++++++++++ .../commands/callers/CommandCaller.java | 19 ++ .../commands/callers/SystemCaller.java | 29 ++++ .../commands/test/CommandTest.java | 48 ++++++ .../commands/util/StringUtil.java | 52 ++++++ 57 files changed, 1443 insertions(+), 726 deletions(-) create mode 100644 src/main/java/com/intellectualcrafters/plot/commands/CommandCategory.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/commands/Disable.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/commands/Inventory.java create mode 100644 src/main/java/com/intellectualcrafters/plot/commands/callers/ConsoleCaller.java create mode 100644 src/main/java/com/intellectualcrafters/plot/commands/callers/PlotPlayerCaller.java create mode 100644 src/main/java/com/intellectualsites/commands/Argument.java create mode 100644 src/main/java/com/intellectualsites/commands/Command.java create mode 100644 src/main/java/com/intellectualsites/commands/CommandDeclaration.java create mode 100644 src/main/java/com/intellectualsites/commands/CommandHandlingOutput.java create mode 100644 src/main/java/com/intellectualsites/commands/CommandManager.java create mode 100644 src/main/java/com/intellectualsites/commands/callers/CommandCaller.java create mode 100644 src/main/java/com/intellectualsites/commands/callers/SystemCaller.java create mode 100644 src/main/java/com/intellectualsites/commands/test/CommandTest.java create mode 100644 src/main/java/com/intellectualsites/commands/util/StringUtil.java diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Add.java b/src/main/java/com/intellectualcrafters/plot/commands/Add.java index bf0699d7a..ef77fadf3 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Add.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Add.java @@ -31,26 +31,38 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; +@CommandDeclaration( + command = "add", + aliases = {"a"}, + description = "Allow a user to build while you are online", + usage = "/plot add ", + category = CommandCategory.ACTIONS, + permission = "plots.add", + requiredType = PlotPlayer.class +) public class Add extends SubCommand { + public Add() { - super(Command.ADD, "Allow a user to build while you are online", "add ", CommandCategory.ACTIONS, true); + requiredArguments = new Argument[] { + Argument.PlayerName + }; } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - if (args.length != 1) { - MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot add "); - return true; - } + public boolean onCommand(CommandCaller caller, String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final Location loc = plr.getLocation(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { MainUtil.sendMessage(plr, C.PLOT_UNOWNED); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 651fb99b8..f619f22cb 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -33,11 +33,19 @@ import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "auto", + permission = "plots.auto", + category = CommandCategory.CLAIMING, + requiredType = PlotPlayer.class, + description = "Claim the nearest plot", + aliases = {"a"}, + usage = "/plot auto" +) public class Auto extends SubCommand { - public Auto() { - super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true); - } public static PlotId getNextPlot(final PlotId id, final int step) { final int absX = Math.abs(id.x); @@ -68,9 +76,9 @@ public class Auto extends SubCommand { } } - // TODO auto claim a mega plot with schematic @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(CommandCaller caller, String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); String world; int size_x = 1; int size_z = 1; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index 6cb6e8664..3b04c8687 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -36,9 +36,7 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; -/** - * @author Citymonstret - */ + public class Buy extends SubCommand { public Buy() { super(Command.BUY, "Buy the plot you are standing on", "b", CommandCategory.CLAIMING, true); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/CommandCategory.java b/src/main/java/com/intellectualcrafters/plot/commands/CommandCategory.java new file mode 100644 index 000000000..b9cc06fd2 --- /dev/null +++ b/src/main/java/com/intellectualcrafters/plot/commands/CommandCategory.java @@ -0,0 +1,58 @@ +package com.intellectualcrafters.plot.commands; + +/** + * CommandCategory + * + * @author Citymonstret + * @author Empire92 + */ +public enum CommandCategory { + /** + * Claiming Commands + * + * Such as: /plot claim + */ + CLAIMING("Claiming"), + /** + * Teleportation Commands + * + * Such as: /plot visit + */ + TELEPORT("Teleportation"), + /** + * Action Commands + * + * Such as: /plot clear + */ + ACTIONS("Actions"), + /** + * Information Commands + * + * Such as: /plot info + */ + INFO("Information"), + /** + * Debug Commands + * + * Such as: /plot debug + */ + DEBUG("Debug"); + /** + * The category name (Readable) + */ + private final String name; + + /** + * Constructor + * + * @param name readable name + */ + CommandCategory(final String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } +} diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java index 7e4509ab3..6f68fb0d7 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java @@ -28,6 +28,9 @@ import java.util.HashSet; import java.util.Map.Entry; import java.util.UUID; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import org.bukkit.Bukkit; import com.intellectualcrafters.plot.PS; @@ -48,22 +51,26 @@ import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; +@CommandDeclaration( + command = "uuidconvert", + permission = "plots.admin", + description = "Debug UUID conversion", + usage = "/plot uuidconvert ", + requiredType = PS.class, + category = CommandCategory.DEBUG +) public class DebugUUID extends SubCommand { + public DebugUUID() { - super("uuidconvert", "plots.admin", "Debug uuid conversion", "debuguuid", "debuguuid", CommandCategory.DEBUG, false); + requiredArguments = new Argument[] { + Argument.String + }; } @Override - public boolean execute(final PlotPlayer player, final String... args) { - if (player != null) { - MainUtil.sendMessage(player, C.NOT_CONSOLE); - return false; - } - if (args.length == 0) { - MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert "); - return false; - } - + public boolean onCommand(final CommandCaller caller, final String[] args) { + PlotPlayer player = null; + UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper(); UUIDWrapper newWrapper = null; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index a8a4296a7..03af02c39 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -32,15 +32,24 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +import com.plotsquared.bukkit.util.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; +@CommandDeclaration( + command = "delete", + permission = "plots.delete", + description = "Delete a plot", + usage = "/plot delete", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Delete extends SubCommand { - public Delete() { - super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final Location loc = plr.getLocation(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { @@ -49,10 +58,9 @@ public class Delete extends SubCommand { if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); } - if ((((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUIDWrapper().getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { + if (((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUIDWrapper().getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { return !sendMessage(plr, C.NO_PLOT_PERMS); } - assert plot != null; final PlotWorld pWorld = PS.get().getPlotWorld(plot.world); if (MainUtil.runners.containsKey(plot)) { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); @@ -61,7 +69,7 @@ public class Delete extends SubCommand { Runnable runnable = new Runnable() { @Override public void run() { - if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) { + if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) { final double c = pWorld.SELL_PRICE; if (c > 0d) { EconHandler.manager.depositMoney(plr, c); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java index f8d9d6646..b6e7e740d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java @@ -31,21 +31,32 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; +@CommandDeclaration( + command = "deny", + aliases = {"d"}, + description = "Deny a user from a plot", + usage = "/plot deny ", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Deny extends SubCommand { + public Deny() { - super(Command.DENY, "Deny a user from a plot", "deny ", CommandCategory.ACTIONS, true); + requiredArguments = new Argument[] { + Argument.PlayerName + }; } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - if (args.length != 1) { - MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot deny "); - return true; - } + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final Location loc = plr.getLocation(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Disable.java b/src/main/java/com/intellectualcrafters/plot/commands/Disable.java deleted file mode 100644 index e6414df76..000000000 --- a/src/main/java/com/intellectualcrafters/plot/commands/Disable.java +++ /dev/null @@ -1,39 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -// PlotSquared - A plot manager and world generator for the Bukkit API / -// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / -// / -// This program is free software; you can redistribute it and/or modify / -// it under the terms of the GNU General Public License as published by / -// the Free Software Foundation; either version 3 of the License, or / -// (at your option) any later version. / -// / -// This program is distributed in the hope that it will be useful, / -// but WITHOUT ANY WARRANTY; without even the implied warranty of / -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / -// GNU General Public License for more details. / -// / -// You should have received a copy of the GNU General Public License / -// along with this program; if not, write to the Free Software Foundation, / -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / -// / -// You can contact us via: support@intellectualsites.com / -//////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.commands; - -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.object.PlotPlayer; - -public class Disable extends SubCommand { - public static String downloads, version; - - public Disable() { - super("disable", "plots.admin", "Disable PlotSquared", "disable", "unload", CommandCategory.DEBUG, false); - } - - @Override - public boolean execute(final PlotPlayer plr, final String... args) { - PS.log("&cDisabling PlotSquared and all dependencies!"); - PS.get().IMP.disable(); - return true; - } -} diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Download.java b/src/main/java/com/intellectualcrafters/plot/commands/Download.java index e729e4db5..e03671cd1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Download.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Download.java @@ -13,14 +13,22 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "download", + aliases = {"dl"}, + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class, + description = "Download your plot", + permission = "plots.download" +) public class Download extends SubCommand { - public Download() { - super(Command.DOWNLOAD, "Download your plot", "dl", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer plr, String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); if (!Settings.METRICS) { MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service"); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Help.java b/src/main/java/com/intellectualcrafters/plot/commands/Help.java index 0f4f72f9e..25215ac65 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Help.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Help.java @@ -7,15 +7,20 @@ */ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "help", + description = "Get this help menu", + permission = "", + aliases = {"he"}, + category = CommandCategory.INFO +) public class Help extends SubCommand { - public Help() { - super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false); - } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - return false; + public boolean onCommand(final CommandCaller caller, final String[] args) { + return true; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Home.java b/src/main/java/com/intellectualcrafters/plot/commands/Home.java index d5be8bf16..669a31b01 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Home.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Home.java @@ -27,14 +27,18 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; -/** - * @author Citymonstret - */ +@CommandDeclaration( + command = "home", + aliases = {"h"}, + description = "Go to your plot", + usage = "/plot home [id|alias]", + category = CommandCategory.TELEPORT, + requiredType = PlotPlayer.class +) public class Home extends SubCommand { - public Home() { - super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true); - } private Plot isAlias(final String a) { for (final Plot p : PS.get().getPlots()) { @@ -46,7 +50,8 @@ public class Home extends SubCommand { } @Override - public boolean execute(final PlotPlayer plr, String... args) { + public boolean onCommand(final CommandCaller caller, String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final ArrayList plots = PS.get().sortPlotsByWorld(PS.get().getPlots(plr)); if (plots.size() == 1) { MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0)); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index e27d196c8..ad60d654a 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -23,6 +23,8 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; import java.util.List; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; @@ -35,10 +37,15 @@ import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; +@CommandDeclaration( + command = "inbox", + description = "Review the comments for a plot", + usage = "/plot inbox [inbox] [delete |clear|page]", + permission = "plots.inbox", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Inbox extends SubCommand { - public Inbox() { - super(Command.INBOX, "Review the comments for a plot", "inbox [inbox] [delete |clear|page]", CommandCategory.ACTIONS, true); - } public void displayComments(PlotPlayer player, List oldComments, int page) { if (oldComments == null || oldComments.size() == 0) { @@ -79,7 +86,9 @@ public class Inbox extends SubCommand { } @Override - public boolean execute(final PlotPlayer player, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer player = (PlotPlayer) caller.getSuperCaller(); + final Plot plot = MainUtil.getPlot(player.getLocation()); if (args.length == 0) { sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete |clear|page]"); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/src/main/java/com/intellectualcrafters/plot/commands/Info.java index c7eb83650..892c0e378 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -25,7 +25,10 @@ import java.util.Collection; import java.util.UUID; import java.util.regex.Matcher; +import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller; import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; @@ -43,14 +46,14 @@ import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; -/** - * @author Citymonstret - */ -@SuppressWarnings({ "javadoc" }) +@CommandDeclaration( + command = "info", + aliases = {"i"}, + description = "Display plot info", + usage = "/plot info ", + category = CommandCategory.INFO +) public class Info extends SubCommand { - public Info() { - super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false); - } public static String getPlayerList(final Collection uuids) { ArrayList l = new ArrayList<>(uuids); @@ -84,7 +87,9 @@ public class Info extends SubCommand { } @Override - public boolean execute(final PlotPlayer player, String... args) { + public boolean onCommand(final CommandCaller caller, String[] args) { + final PlotPlayer player = caller instanceof PlotPlayerCaller ? (PlotPlayer) caller.getSuperCaller() : null; + String arg = null; Plot plot; if (args.length > 0) arg = args[0] + ""; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java b/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java deleted file mode 100644 index 61e102c68..000000000 --- a/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java +++ /dev/null @@ -1,73 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -// PlotSquared - A plot manager and world generator for the Bukkit API / -// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / -// / -// This program is free software; you can redistribute it and/or modify / -// it under the terms of the GNU General Public License as published by / -// the Free Software Foundation; either version 3 of the License, or / -// (at your option) any later version. / -// / -// This program is distributed in the hope that it will be useful, / -// but WITHOUT ANY WARRANTY; without even the implied warranty of / -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / -// GNU General Public License for more details. / -// / -// You should have received a copy of the GNU General Public License / -// along with this program; if not, write to the Free Software Foundation, / -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / -// / -// You can contact us via: support@intellectualsites.com / -//////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.commands; - -import java.util.ArrayList; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import com.intellectualcrafters.plot.config.C; -import com.plotsquared.bukkit.object.BukkitPlayer; -import com.intellectualcrafters.plot.object.PlotPlayer; - -public class Inventory extends SubCommand { - public Inventory() { - super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true); - } - - @Override - public boolean execute(final PlotPlayer plr, final String... args) { - final ArrayList cmds = new ArrayList<>(); - for (final SubCommand cmd : MainCommand.subCommands) { - if (cmd.permission.hasPermission(plr)) { - cmds.add(cmd); - } - } - final int size = 9 * (int) Math.ceil(cmds.size() / 9.0); - final org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null, size, "PlotSquared Commands"); - for (final SubCommand cmd : cmds) { - inventory.addItem(getItem(cmd)); - } - ((BukkitPlayer) plr).player.openInventory(inventory); - return true; - } - - private ItemStack getItem(final SubCommand cmd) { - final ItemStack stack = new ItemStack(Material.COMMAND); - final ItemMeta meta = stack.getItemMeta(); - { - meta.setDisplayName(ChatColor.GREEN + cmd.cmd + ChatColor.DARK_GRAY + " [" + ChatColor.GREEN + cmd.alias + ChatColor.DARK_GRAY + "]"); - meta.setLore(new ArrayList() { - { - add(C.INVENTORY_CATEGORY.s().replace("{category}", cmd.category.toString())); - add(C.INVENTORY_DESC.s().replace("{desc}", cmd.description)); - add(C.INVENTORY_USAGE.s().replace("{usage}", "/plot " + cmd.usage)); - } - }); - } - stack.setItemMeta(meta); - return stack; - } -} diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index 97a1953f3..ce4927ed5 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -27,16 +27,23 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; -@SuppressWarnings({ "unused", "deprecation", "javadoc" }) +@CommandDeclaration( + command = "kick", + aliases = {"k"}, + description = "Kick a player from your plot", + permission = "plots.kick", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Kick extends SubCommand { - public Kick() { - super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final Location loc = plr.getLocation(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Load.java b/src/main/java/com/intellectualcrafters/plot/commands/Load.java index b56ca3341..17066b782 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Load.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Load.java @@ -3,9 +3,7 @@ package com.intellectualcrafters.plot.commands; import java.net.MalformedURLException; import java.net.URL; import java.util.List; -import java.util.UUID; -import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -18,14 +16,23 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "load", + aliases = {"restore"}, + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class, + description = "Load your plot", + permission = "plots.load", + usage = "/plot restore" +) public class Load extends SubCommand { - public Load() { - super(Command.LOAD, "Load your plot", "restore", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer plr, String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); if (!Settings.METRICS) { MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service"); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index f8dfeebf4..de7cf2791 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -28,31 +28,24 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringComparison; +import com.intellectualsites.commands.CommandManager; /** * PlotSquared command class * * @author Citymonstret */ -public class MainCommand { - /** - * Main Permission Node - */ - private final static SubCommand[] _subCommands = new SubCommand[] { }; - public final static ArrayList subCommands = new ArrayList() { - { - addAll(Arrays.asList(_subCommands)); - } - }; - +public class MainCommand extends CommandManager { + public static boolean no_permission(final PlotPlayer player, final String permission) { MainUtil.sendMessage(player, C.NO_PERMISSION, permission); return false; } - public static List getCommands(final SubCommand.CommandCategory category, final PlotPlayer player) { + public static List getCommands(final CommandCategory category, final PlotPlayer player) { final List cmds = new ArrayList<>(); - for (final SubCommand c : subCommands) { + for (final Command c : commands) { + if (!c.requiredType ) if (!c.isPlayer || (player != null)) { if ((c.category.equals(category)) && c.permission.hasPermission(player)) { cmds.add(c); @@ -62,7 +55,7 @@ public class MainCommand { return cmds; } - public static List helpMenu(final PlotPlayer player, final SubCommand.CommandCategory category, int page) { + public static List helpMenu(final PlotPlayer player, final CommandCategory category, int page) { List commands; if (category != null) { commands = getCommands(category, player); @@ -109,15 +102,15 @@ public class MainCommand { if (args.length < 2) { final StringBuilder builder = new StringBuilder(); builder.append(C.HELP_INFO.s()); - for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) { + for (final CommandCategory category : CommandCategory.values()) { builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString())); } builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands")); return MainUtil.sendMessage(player, builder.toString()); } final String cat = args[1]; - SubCommand.CommandCategory cato = null; - for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) { + CommandCategory cato = null; + for (final CommandCategory category : CommandCategory.values()) { if (cat.equalsIgnoreCase(category.toString())) { cato = category; break; @@ -126,7 +119,7 @@ public class MainCommand { if ((cato == null) && !cat.equalsIgnoreCase("all")) { final StringBuilder builder = new StringBuilder(); builder.append(C.HELP_INFO.s()); - for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) { + for (final CommandCategory category : CommandCategory.values()) { builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString())); } return MainUtil.sendMessage(player, builder.toString(), false); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index f8b824b3f..def8182b8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -24,6 +24,9 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.PS; @@ -40,15 +43,23 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; -/** - * @author Citymonstret - */ +@CommandDeclaration( + command = "merge", + aliases = {"m"}, + description = "Merge the plot you are standing on, with another plot", + permission = "plots.merge", + usage = "/plot merge [direction]", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Merge extends SubCommand { public final static String[] values = new String[] { "north", "east", "south", "west" }; public final static String[] aliases = new String[] { "n", "e", "s", "w" }; public Merge() { - super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true); + requiredArguments = new Argument[] { + Argument.String + }; } public static String direction(float yaw) { @@ -74,7 +85,8 @@ public class Merge extends SubCommand { } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final Location loc = plr.getLocationFull(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/src/main/java/com/intellectualcrafters/plot/commands/Move.java index d0ce4adc8..36d77fd91 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -29,24 +29,29 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; -/** - * Created 2014-08-01 for PlotSquared - * - * @author Empire92 - */ +@CommandDeclaration( + command = "move", + description = "Move a plot", + aliases = {"debugmove"}, + permission = "plots.move", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Move extends SubCommand { + public Move() { - super(Command.MOVE, "Move a plot", "debugmove", CommandCategory.ACTIONS, true); + requiredArguments = new Argument[] { + Argument.PlotID + }; } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - if (args.length < 1) { - MainUtil.sendMessage(plr, C.NEED_PLOT_ID); - MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move "); - return false; - } + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final Location loc = plr.getLocation(); final Plot plot1 = MainUtil.getPlot(loc); if (plot1 == null) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java index 5ce4e9fec..5144d24b5 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java @@ -31,14 +31,22 @@ import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "music", + permission = "plots.music", + description = "Player music in a plot", + usage = "/plot music", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class MusicSubcommand extends SubCommand { - public MusicSubcommand() { - super("music", "plots.music", "Play music in plot", "music", "mus", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer player, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer player = (PlotPlayer) caller.getSuperCaller(); final Location loc = player.getLocation(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 85ddb1320..4f7b7381a 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -32,13 +32,18 @@ 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.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; -@SuppressWarnings({ "javadoc" }) +@CommandDeclaration( + command = "purge", + permission = "plots.admin", + description = "Purge all plots for a world", + category = CommandCategory.ACTIONS, + requiredType = PS.class +) public class Purge extends SubCommand { - public Purge() { - super("purge", "plots.admin", "Purge all plots for a world", "purge", "", CommandCategory.DEBUG, false); - } public PlotId getId(final String id) { try { @@ -50,49 +55,45 @@ public class Purge extends SubCommand { } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - if (plr != null) { - MainUtil.sendMessage(plr, (C.NOT_CONSOLE)); - return false; - } + public boolean onCommand(final CommandCaller caller, final String[] args) { if (args.length == 1) { final String arg = args[0].toLowerCase(); final PlotId id = getId(arg); if (id != null) { - MainUtil.sendMessage(plr, "/plot purge x;z &l"); + caller.message("/plot purxe x;z &l"); return false; } final UUID uuid = UUIDHandler.getUUID(args[0]); if (uuid != null) { - MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l"); + caller.message("/plot purge " + args[0] + " &l"); return false; } if (arg.equals("player")) { - MainUtil.sendMessage(plr, "/plot purge &l "); + caller.message("/plot purge &l "); return false; } if (arg.equals("unowned")) { - MainUtil.sendMessage(plr, "/plot purge unowned &l"); + caller.message("/plot purge unowned &l"); return false; } if (arg.equals("unknown")) { - MainUtil.sendMessage(plr, "/plot purge unknown &l"); + caller.message("/plot purge unknown &l"); return false; } if (arg.equals("all")) { - MainUtil.sendMessage(plr, "/plot purge all &l"); + caller.message("/plot purge all &l"); return false; } - MainUtil.sendMessage(plr, C.PURGE_SYNTAX); + caller.message(C.PURGE_SYNTAX); return false; } if (args.length != 2) { - MainUtil.sendMessage(plr, C.PURGE_SYNTAX); + caller.message(C.PURGE_SYNTAX); return false; } final String worldname = args[1]; if (!PS.get().getAllPlotsRaw().containsKey(worldname)) { - MainUtil.sendMessage(plr, "INVALID WORLD"); + caller.message("INVALID WORLD"); return false; } final String arg = args[0].toLowerCase(); @@ -159,7 +160,7 @@ public class Purge extends SubCommand { DBFunc.purge(worldname, ids); return finishPurge(length); } - MainUtil.sendMessage(plr, C.PURGE_SYNTAX); + caller.message(C.PURGE_SYNTAX); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 8f7418b68..b1b3a74cb 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -26,6 +26,8 @@ import java.util.Comparator; import java.util.Map.Entry; import java.util.UUID; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.mutable.MutableInt; import org.bukkit.Bukkit; @@ -44,17 +46,21 @@ import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; +@CommandDeclaration( + command = "rate", + permission = "plots.rate", + description = "Rate the plot", + usage = "/plot rate [#|next]", + aliases = {"rt"}, + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Rate extends SubCommand { - /* - * String cmd, String permission, String description, String usage, String - * alias, CommandCategory category - */ - public Rate() { - super("rate", "plots.rate", "Rate the plot", "rate [#|next]", "rt", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer player, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer player = (PlotPlayer) caller.getSuperCaller(); + if (args.length == 1) { if (args[0].equalsIgnoreCase("next")) { ArrayList plots = new ArrayList<>(PS.get().getPlots()); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java b/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java index ec98558e0..289676cc7 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java @@ -30,37 +30,43 @@ import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "regenallroads", + description = "Regenerate all roads in the map using the set road schematic", + aliases = {"rgar"}, + category = CommandCategory.DEBUG, + requiredType = PS.class, + permission = "plots.regenallroads" +) public class RegenAllRoads extends SubCommand { + public RegenAllRoads() { - super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false); + requiredArguments = new Argument[] { + Argument.String + }; } @Override - public boolean execute(final PlotPlayer player, final String... args) { - if (player != null) { - sendMessage(player, C.NOT_CONSOLE); - return false; - } - if (args.length < 1) { - sendMessage(player, C.NEED_PLOT_WORLD); - return false; - } + public boolean onCommand(final CommandCaller caller, final String[] args) { int height = 0; if (args.length == 2) { try { height = Integer.parseInt(args[1]); } catch (NumberFormatException e) { - sendMessage(player, C.NOT_VALID_NUMBER, "(0, 256)"); - sendMessage(player, C.COMMAND_SYNTAX, "/plot regenallroads [height]"); + caller.message(C.NOT_VALID_NUMBER, "(0, 256)"); + caller.message(C.COMMAND_SYNTAX, "/plot regenallroads [height]"); return false; } } final String name = args[0]; final PlotManager manager = PS.get().getPlotManager(name); if ((manager == null) || !(manager instanceof HybridPlotManager)) { - sendMessage(player, C.NOT_VALID_PLOT_WORLD); + caller.message(C.NOT_VALID_PLOT_WORLD); return false; } final List chunks = ChunkManager.manager.getChunkChunks(name); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Reload.java b/src/main/java/com/intellectualcrafters/plot/commands/Reload.java index a425d2ce1..05e3944f8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Reload.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Reload.java @@ -22,17 +22,22 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; + +@CommandDeclaration( + command = "reload", + permission = "plots.admin.command.reload", + description = "Reload configurations", + usage = "/plot reload", + category = CommandCategory.INFO +) public class Reload extends SubCommand { - public Reload() { - super("reload", "plots.admin.command.reload", "Reload configurations", "reload", CommandCategory.INFO, false); - } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { try { // The following won't affect world generation, as that has to be // loaded during startup unfortunately. @@ -43,9 +48,9 @@ public class Reload extends SubCommand { final PlotWorld plotworld = PS.get().getPlotWorld(pw); plotworld.loadDefaultConfiguration(PS.get().config.getConfigurationSection("worlds." + pw)); } - MainUtil.sendMessage(plr, C.RELOADED_CONFIGS); + caller.message(C.RELOADED_CONFIGS); } catch (final Exception e) { - MainUtil.sendMessage(plr, C.RELOAD_FAILED); + caller.message(C.RELOAD_FAILED); } return true; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java index 38cbdd076..85229325b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java @@ -30,16 +30,32 @@ 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.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler; +@CommandDeclaration( + command = "remove", + aliases = {"r"}, + description = "Remove a player from a plot", + usage = "/plot remove ", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class, + permission = "plots.remove" +) public class Remove extends SubCommand { + public Remove() { - super(Command.REMOVE, "Remove a player from a plot", "remove ", CommandCategory.ACTIONS, true); + requiredArguments = new Argument[] { + Argument.PlayerName + }; } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); if (args.length != 1) { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot remove "); return true; @@ -58,59 +74,61 @@ public class Remove extends SubCommand { return true; } int count = 0; - if (args[0].equals("unknown")) { - ArrayList toRemove = new ArrayList<>(); - HashSet all = new HashSet<>(); - all.addAll(plot.getMembers()); - all.addAll(plot.getTrusted()); - all.addAll(plot.getDenied()); - for (UUID uuid : all) { - if (UUIDHandler.getName(uuid) == null) { + switch (args[0]) { + case "unknown": { + ArrayList toRemove = new ArrayList<>(); + HashSet all = new HashSet<>(); + all.addAll(plot.getMembers()); + all.addAll(plot.getTrusted()); + all.addAll(plot.getDenied()); + for (UUID uuid : all) { + if (UUIDHandler.getName(uuid) == null) { + toRemove.add(uuid); + count++; + } + } + for (UUID uuid : toRemove) { + plot.removeDenied(uuid); + plot.removeTrusted(uuid); + plot.removeMember(uuid); + } + break; + } + case "*": { + ArrayList toRemove = new ArrayList<>(); + HashSet all = new HashSet<>(); + all.addAll(plot.getMembers()); + all.addAll(plot.getTrusted()); + all.addAll(plot.getDenied()); + for (UUID uuid : all) { toRemove.add(uuid); count++; } + for (UUID uuid : toRemove) { + plot.removeDenied(uuid); + plot.removeTrusted(uuid); + plot.removeMember(uuid); + } + break; } - for (UUID uuid : toRemove) { - plot.removeDenied(uuid); - plot.removeTrusted(uuid); - plot.removeMember(uuid); - } - } - else if (args[0].equals("*")){ - ArrayList toRemove = new ArrayList<>(); - HashSet all = new HashSet<>(); - all.addAll(plot.getMembers()); - all.addAll(plot.getTrusted()); - all.addAll(plot.getDenied()); - for (UUID uuid : all) { - toRemove.add(uuid); - count++; - } - for (UUID uuid : toRemove) { - plot.removeDenied(uuid); - plot.removeTrusted(uuid); - plot.removeMember(uuid); - } - } - else { - UUID uuid = UUIDHandler.getUUID(args[0]); - if (uuid != null) { - if (plot.getTrusted().contains(uuid)) { - if (plot.removeTrusted(uuid)) { - count++; + default: + UUID uuid = UUIDHandler.getUUID(args[0]); + if (uuid != null) { + if (plot.getTrusted().contains(uuid)) { + if (plot.removeTrusted(uuid)) { + count++; + } + } else if (plot.getMembers().contains(uuid)) { + if (plot.removeMember(uuid)) { + count++; + } + } else if (plot.getDenied().contains(uuid)) { + if (plot.removeDenied(uuid)) { + count++; + } } } - else if (plot.getMembers().contains(uuid)) { - if (plot.removeMember(uuid)) { - count++; - } - } - else if (plot.getDenied().contains(uuid)) { - if (plot.removeDenied(uuid)) { - count++; - } - } - } + break; } if (count == 0) { if (UUIDHandler.implementation instanceof SQLUUIDHandler) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Save.java b/src/main/java/com/intellectualcrafters/plot/commands/Save.java index d940d6e3a..23b20c4f2 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Save.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Save.java @@ -16,14 +16,22 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "save", + aliases = {"backup"}, + description = "Save your plot", + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class, + permission = "plots.save" +) public class Save extends SubCommand { - public Save() { - super(Command.SAVE, "Save your plot", "backup", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer plr, String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); if (!Settings.METRICS) { MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service"); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java b/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java index 43adc6908..ea35e823e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -33,24 +33,35 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; +@CommandDeclaration( + command = "setowner", + permission = "plots.set.owner", + description = "Set the plot owner", + usage = "/plot setowner ", + aliases = {"so"}, + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class SetOwner extends SubCommand { + public SetOwner() { - super("setowner", "plots.set.owner", "Set the plot owner", "setowner ", "so", CommandCategory.ACTIONS, true); + requiredArguments = new Argument[] { + Argument.PlayerName + }; } - /* - * private UUID getUUID(String string) { OfflinePlayer player = - * Bukkit.getOfflinePlayer(string); return ((player != null) && - * player.hasPlayedBefore()) ? UUIDHandler.getUUID(player) : null; } - */ private UUID getUUID(final String string) { return UUIDHandler.getUUID(string); } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller; final Location loc = plr.getLocation(); final Plot plot = MainUtil.getPlot(loc); if ((plot == null) || (plot.owner == null)) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index e5322c33f..a4b6387f6 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -25,6 +25,9 @@ import java.util.Arrays; import java.util.List; import java.util.Map.Entry; +import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import org.apache.commons.lang.StringUtils; import org.bukkit.generator.ChunkGenerator; @@ -39,11 +42,16 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.bukkit.util.SetupUtils; +@CommandDeclaration( + command = "setup", + permission = "plots.admin.command.setup", + description = "Setup wizard for plot worlds", + usage = "/plot setup", + aliases = {"create"}, + category = CommandCategory.ACTIONS +) public class Setup extends SubCommand { - public Setup() { - super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, false); - } - + public void displayGenerators(PlotPlayer plr) { StringBuffer message = new StringBuffer(); message.append("&6What generator do you want?"); @@ -65,7 +73,9 @@ public class Setup extends SubCommand { } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + PlotPlayer plr = (caller instanceof PlotPlayerCaller) ? (PlotPlayer) caller.getSuperCaller() : null; + // going through setup String name; if (plr == null) { @@ -208,7 +218,7 @@ public class Setup extends SubCommand { step.setValue(args[0]); object.setup_index++; if (object.setup_index == object.step.length) { - execute(plr, args); + onCommand(caller, args); return false; } step = object.step[object.setup_index]; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java index 3ba556281..f445218e2 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java @@ -20,9 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.Arrays; - import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; @@ -33,109 +30,12 @@ import com.intellectualcrafters.plot.util.MainUtil; * @author Citymonstret */ @SuppressWarnings({ "deprecation", "unused" }) -public abstract class SubCommand { - /** - * Command - */ - public final String cmd; - /** - * Permission node - */ - public final CommandPermission permission; - /** - * Simple description - */ - public final String description; - /** - * Aliases - */ - public final ArrayList alias; - /** - * Command usage - */ - public final String usage; +public abstract class SubCommand extends com.intellectualsites.commands.Command { + /** * The category */ - public final CommandCategory category; - /** - * Is this a player-online command? - */ - public final boolean isPlayer; - - /** - * @param cmd Command /plot {cmd} <-- That! - * @param permission Permission Node - * @param description Simple description - * @param usage Usage description: /plot command {args...} - * @param alias Command alias - * @param category CommandCategory. Pick whichever is closest to what you want. - */ - public SubCommand(final String cmd, final String permission, final String description, final String usage, final String alias, final CommandCategory category, final boolean isPlayer) { - this.cmd = cmd; - this.permission = new CommandPermission(permission); - this.description = description; - this.alias = new ArrayList(); - this.alias.add(alias); - this.usage = usage; - this.category = category; - this.isPlayer = isPlayer; - } - - /** - * @param cmd Command /plot {cmd} <-- That! - * @param permission Permission Node - * @param description Simple description - * @param usage Usage description: /plot command {args...} - * @param aliases Command aliases - * @param category CommandCategory. Pick whichever is closest to what you want. - */ - public SubCommand(final String cmd, final String permission, final String description, final String usage, final CommandCategory category, final boolean isPlayer, final String... aliases) { - this.cmd = cmd; - this.permission = new CommandPermission(permission); - this.description = description; - this.alias = new ArrayList(); - this.alias.addAll(Arrays.asList(aliases)); - this.usage = usage; - this.category = category; - this.isPlayer = isPlayer; - } - - /** - * @param command Command /plot {cmd} <-- That! - * @param description Simple description - * @param usage Usage description: /plot command {args...} - * @param category CommandCategory. Pick whichever closests to what you want. - */ - public SubCommand(final Command command, final String description, final String usage, final CommandCategory category, final boolean isPlayer) { - this.cmd = command.getCommand(); - this.permission = command.getPermission(); - this.alias = new ArrayList(); - this.alias.add(command.getAlias()); - this.description = description; - this.usage = usage; - this.category = category; - this.isPlayer = isPlayer; - } - - /** - * Execute. - * - * @param plr executor - * @param args arguments - * - * @return true on success, false on failure - */ - public abstract boolean execute(final PlotPlayer plr, final String... args); - - /** - * Execute the command as console - * - * @param args Arguments - */ - public void executeConsole(final String... args) { - this.execute(null, args); - } + public CommandCategory category; /** * Send a message @@ -150,61 +50,5 @@ public abstract class SubCommand { MainUtil.sendMessage(plr, c, args); return true; } - - /** - * CommandCategory - * - * @author Citymonstret - * @author Empire92 - */ - public enum CommandCategory { - /** - * Claiming Commands - * - * Such as: /plot claim - */ - CLAIMING("Claiming"), - /** - * Teleportation Commands - * - * Such as: /plot visit - */ - TELEPORT("Teleportation"), - /** - * Action Commands - * - * Such as: /plot clear - */ - ACTIONS("Actions"), - /** - * Information Commands - * - * Such as: /plot info - */ - INFO("Information"), - /** - * Debug Commands - * - * Such as: /plot debug - */ - DEBUG("Debug"); - /** - * The category name (Readable) - */ - private final String name; - /** - * Constructor - * - * @param name readable name - */ - CommandCategory(final String name) { - this.name = name; - } - - @Override - public String toString() { - return this.name; - } - } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Swap.java b/src/main/java/com/intellectualcrafters/plot/commands/Swap.java index ffdd46aa7..6dab78245 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Swap.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Swap.java @@ -33,19 +33,21 @@ import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; -/** - * Created 2014-08-01 for PlotSquared - * - * @author Empire92 - */ +@CommandDeclaration( + command = "swap", + description = "Swap two plots", + aliases = {"switch"}, + category = CommandCategory.ACTIONS, + requiredType = PlotPlayer.class +) public class Swap extends SubCommand { - public Swap() { - super(Command.SWAP, "Swap two plots", "switch", CommandCategory.ACTIONS, true); - } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); MainUtil.sendMessage(plr, "&cThis command has not been optimized for large selections yet. Please bug me if this becomes an issue."); if (args.length < 1) { MainUtil.sendMessage(plr, C.NEED_PLOT_ID); @@ -57,7 +59,7 @@ public class Swap extends SubCommand { if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } - if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) { + if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/TP.java b/src/main/java/com/intellectualcrafters/plot/commands/TP.java index 9eb5b19f8..0a9e536c1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/TP.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/TP.java @@ -20,6 +20,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.PS; @@ -32,20 +35,25 @@ import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.bukkit.util.bukkit.UUIDHandler; -/** - * @author Citymonstret - */ +@CommandDeclaration( + command = "tp", + description = "Teleport to a plot", + permission = "plots.tp", + usage = "/plot tp ", + requiredType = PlotPlayer.class, + category = CommandCategory.TELEPORT +) public class TP extends SubCommand { + public TP() { - super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true); + requiredArguments = new Argument[] { + Argument.String + }; } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - if (args.length < 1) { - MainUtil.sendMessage(plr, C.NEED_PLOT_ID); - return false; - } + public boolean onCommand(final CommandCaller caller, final String[] args) { + PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final String id = args[0]; PlotId plotid; final Location loc = plr.getLocation(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Target.java b/src/main/java/com/intellectualcrafters/plot/commands/Target.java index 8b5839461..0c47ac3b6 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Target.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Target.java @@ -26,31 +26,42 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualsites.commands.Argument; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; +@CommandDeclaration( + command = "target", + usage = "/plot target ", + description = "Target a plot with your compass", + permission = "plots.target", + requiredType = PlotPlayer.class, + category = CommandCategory.ACTIONS +) public class Target extends SubCommand { + public Target() { - super(Command.TARGET, "Target a plot with your compass", "target ", CommandCategory.ACTIONS, true); + requiredArguments = new Argument[] { + Argument.PlotID + }; } @Override - public boolean execute(final PlotPlayer plr, final String... args) { + public boolean onCommand(final CommandCaller caller, final String[] args) { + PlotPlayer plr = (PlotPlayer) caller.getSuperCaller(); final Location ploc = plr.getLocation(); if (!PS.get().isPlotWorld(ploc.getWorld())) { MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); return false; } - if (args.length == 1) { - final PlotId id = MainUtil.parseId(args[0]); - if (id == null) { - MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); - return false; - } - final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id); - plr.setCompassTarget(loc); - MainUtil.sendMessage(plr, C.COMPASS_TARGET); - return true; + final PlotId id = MainUtil.parseId(args[0]); + if (id == null) { + MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); + return false; } - MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot target "); - return false; + final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id); + plr.setCompassTarget(loc); + MainUtil.sendMessage(plr, C.COMPASS_TARGET); + return true; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Template.java b/src/main/java/com/intellectualcrafters/plot/commands/Template.java index 9d3341e97..789dcc2cb 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Template.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Template.java @@ -41,13 +41,19 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualsites.commands.CommandDeclaration; +import com.intellectualsites.commands.callers.CommandCaller; import com.plotsquared.bukkit.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; +@CommandDeclaration( + command = "template", + permission = "plots.admin", + description = "Create or use a world template", + usage = "/plot template [import|export]