From 58bc007b3e91194ea41da214f544bddc60782a6f Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Tue, 11 Feb 2014 20:34:35 -0600 Subject: [PATCH 1/3] Remove all reference to jcommands and use jewelcli. This commit also cleans up the jail command to be quicker as the old way I was doing it just didn't work nor was it good to go for production. This method also utilizes the CommandInfo's pattern to match subcommands, like it was meant to be used for. Completely untested. --- pom.xml | 6 - .../jail/command/CommandHandler.java | 2 + .../graywolf336/jail/command/JailHandler.java | 123 +++++------------- .../jail/command/commands/jewels/Jailing.java | 27 ++++ .../command/commands/jewels/Transfer.java | 15 +++ .../jail/command/commands/params/Jailing.java | 105 --------------- .../command/commands/params/Transferring.java | 45 ------- .../jail/command/jcommands/CellCreate.java | 13 -- .../jail/command/jcommands/Check.java | 13 -- .../jail/command/jcommands/Clear.java | 13 -- .../jail/command/jcommands/ClearForce.java | 13 -- .../jail/command/jcommands/Create.java | 13 -- .../command/jcommands/JailFoundation.java | 8 -- .../jail/command/jcommands/JailList.java | 13 -- .../jail/command/jcommands/ListCells.java | 13 -- .../jail/command/jcommands/Mute.java | 13 -- .../jail/command/jcommands/Reload.java | 13 -- .../jail/command/jcommands/RemoveCell.java | 13 -- .../jail/command/jcommands/Stop.java | 13 -- .../jail/command/jcommands/TeleIn.java | 13 -- .../jail/command/jcommands/TeleOut.java | 13 -- .../jail/command/jcommands/Transfer.java | 13 -- .../jail/command/jcommands/Version.java | 13 -- .../jail/command/jewel/Jailing.java | 16 --- .../jail/command/subcommands/JailCommand.java | 84 +++++++----- .../subcommands/JailTransferCommand.java | 50 +++---- .../graywolf336/jail/TestCommandParams.java | 35 ----- .../com/graywolf336/jail/TestJCommander.java | 36 ----- .../java/com/graywolf336/jail/TestJewel.java | 28 ---- 29 files changed, 153 insertions(+), 622 deletions(-) create mode 100644 src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java create mode 100644 src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java delete mode 100644 src/main/java/com/graywolf336/jail/command/commands/params/Jailing.java delete mode 100644 src/main/java/com/graywolf336/jail/command/commands/params/Transferring.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/CellCreate.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Check.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Clear.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/ClearForce.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Create.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/JailFoundation.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/JailList.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/ListCells.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Mute.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Reload.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/RemoveCell.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Stop.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/TeleIn.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/TeleOut.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Transfer.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jcommands/Version.java delete mode 100644 src/main/java/com/graywolf336/jail/command/jewel/Jailing.java delete mode 100644 src/test/java/test/java/com/graywolf336/jail/TestCommandParams.java delete mode 100644 src/test/java/test/java/com/graywolf336/jail/TestJCommander.java delete mode 100644 src/test/java/test/java/com/graywolf336/jail/TestJewel.java diff --git a/pom.xml b/pom.xml index 07fdd40..db752be 100644 --- a/pom.xml +++ b/pom.xml @@ -67,12 +67,6 @@ jar - - com.beust - jcommander - 1.32 - - com.lexicalscope.jewelcli jewelcli diff --git a/src/main/java/com/graywolf336/jail/command/CommandHandler.java b/src/main/java/com/graywolf336/jail/command/CommandHandler.java index aed961e..805e25a 100644 --- a/src/main/java/com/graywolf336/jail/command/CommandHandler.java +++ b/src/main/java/com/graywolf336/jail/command/CommandHandler.java @@ -58,11 +58,13 @@ public class CommandHandler { public void handleCommand(JailManager jailmanager, CommandSender sender, String command, String[] args) { List matches = getMatches(command); + //If no matches were found, send them the unknown command message. if(matches.size() == 0) { sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.UNKNOWNCOMMAND, command)); return; } + //If more than one command was found, send them each command's help message. if(matches.size() > 1) { for(Command c : matches) showUsage(sender, c); diff --git a/src/main/java/com/graywolf336/jail/command/JailHandler.java b/src/main/java/com/graywolf336/jail/command/JailHandler.java index e4ca59b..015bd01 100644 --- a/src/main/java/com/graywolf336/jail/command/JailHandler.java +++ b/src/main/java/com/graywolf336/jail/command/JailHandler.java @@ -1,7 +1,6 @@ package com.graywolf336.jail.command; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; @@ -9,26 +8,8 @@ import java.util.Map.Entry; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.beust.jcommander.JCommander; -import com.beust.jcommander.ParameterException; import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailManager; -import com.graywolf336.jail.command.jcommands.CellCreate; -import com.graywolf336.jail.command.jcommands.Check; -import com.graywolf336.jail.command.jcommands.Clear; -import com.graywolf336.jail.command.jcommands.ClearForce; -import com.graywolf336.jail.command.jcommands.Create; -import com.graywolf336.jail.command.jcommands.JailFoundation; -import com.graywolf336.jail.command.jcommands.JailList; -import com.graywolf336.jail.command.jcommands.ListCells; -import com.graywolf336.jail.command.jcommands.Mute; -import com.graywolf336.jail.command.jcommands.Reload; -import com.graywolf336.jail.command.jcommands.RemoveCell; -import com.graywolf336.jail.command.jcommands.Stop; -import com.graywolf336.jail.command.jcommands.TeleIn; -import com.graywolf336.jail.command.jcommands.TeleOut; -import com.graywolf336.jail.command.jcommands.Transfer; -import com.graywolf336.jail.command.jcommands.Version; import com.graywolf336.jail.command.subcommands.JailCellCreateCommand; import com.graywolf336.jail.command.subcommands.JailCheckCommand; import com.graywolf336.jail.command.subcommands.JailClearCommand; @@ -49,45 +30,16 @@ import com.graywolf336.jail.enums.LangString; public class JailHandler { private LinkedHashMap commands; - private HashMap addCmds; public JailHandler(JailMain plugin) { commands = new LinkedHashMap(); - addCmds = new HashMap(); loadCommands(); plugin.getLogger().info("Loaded " + commands.size() + " sub-commands of /jail."); } public void handleCommand(JailManager jm, CommandSender sender, String... args) { - if(args.length == 0) { - parseCommand(jm, sender, getMatches("jail").get(0), args); - }else { - JailFoundation foundation = new JailFoundation(); - JCommander jc = new JCommander(foundation); - - for(Entry e : addCmds.entrySet()) { - jc.addCommand(e.getKey(), e.getValue()); - } - - try { - jc.parse(args); - - List matches = getMatches(jc.getParsedCommand()); - - if(matches.size() == 0) { - //There should only be one for /jail - parseCommand(jm, sender, getMatches("jail").get(0), args); - } else if(matches.size() > 1) { - for(Command c : matches) - showUsage(sender, c); - }else { - parseCommand(jm, sender, matches.get(0), args); - } - }catch(ParameterException e) { - parseCommand(jm, sender, getMatches("jail").get(0), args); - } - } + } /** @@ -109,21 +61,49 @@ public class JailHandler { * @param command The name of the command. * @param args The arguments passed to the command. */ - public boolean parseCommand(JailManager jailmanager, CommandSender sender, Command c, String[] args) { + public boolean parseCommand(JailManager jailmanager, CommandSender sender, String[] args) { + Command c = null; + + //If they didn't provide any arguments (aka just: /jail) then we will need to send them some help + if(args.length == 0) { + //TODO: Create the help page(s) + c = getMatches("jail").get(0); + + }else { + //Get the matches from the first argument passed + List matches = getMatches(args[0]); + + if(matches.size() == 0) { + //No matches found, thus it is more likely than not they are trying to jail someone + c = getMatches("jail").get(0); + + } else if(matches.size() > 1) { + //If there was found more than one match + //then let's send the usage of each match to the sender + for(Command cmd : matches) + showUsage(sender, cmd); + return true; + + }else { + //Only one match was found, so let's continue + c = matches.get(0); + } + } + CommandInfo i = c.getClass().getAnnotation(CommandInfo.class); // First, let's check if the sender has permission for the command. if(!sender.hasPermission(i.permission())) { jailmanager.getPlugin().debug("Sender has no permission."); sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION)); - return false; + return true; } // Next, let's check if we need a player and then if the sender is actually a player if(i.needsPlayer() && !(sender instanceof Player)) { jailmanager.getPlugin().debug("Sender is not a player."); sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED)); - return false; + return true; } // Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage. @@ -131,7 +111,7 @@ public class JailHandler { if(args.length - 1 < i.minimumArgs()) { jailmanager.getPlugin().debug("Sender didn't provide enough arguments."); showUsage(sender, c); - return false; + return true; } // Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args. @@ -139,7 +119,7 @@ public class JailHandler { if(i.maxArgs() != -1 && i.maxArgs() < args.length - 1) { jailmanager.getPlugin().debug("Sender provided too many arguments."); showUsage(sender, c); - return false; + return true; } // Since everything has been checked and we're all clear, let's execute it. @@ -147,7 +127,7 @@ public class JailHandler { try { if(!c.execute(jailmanager, sender, args)) { showUsage(sender, c); - return false; + return true; }else { return true; } @@ -155,7 +135,7 @@ public class JailHandler { e.printStackTrace(); jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage()); showUsage(sender, c); - return false; + return true; } } @@ -201,37 +181,6 @@ public class JailHandler { load(JailTeleOutCommand.class); load(JailTransferCommand.class); load(JailVersionCommand.class); - - //Puts the commands in the HashMap - addCmds.put("cellcreate", new CellCreate()); - addCmds.put("cc", new CellCreate()); - addCmds.put("check", new Check()); - addCmds.put("clear", new Clear()); - addCmds.put("clearforce", new ClearForce()); - addCmds.put("cf", new ClearForce()); - addCmds.put("create", new Create()); - addCmds.put("list", new JailList()); - addCmds.put("l", new JailList()); - addCmds.put("listcells", new ListCells()); - addCmds.put("lc", new ListCells()); - addCmds.put("mute", new Mute()); - addCmds.put("m", new Mute()); - addCmds.put("reload", new Reload()); - addCmds.put("r", new Reload()); - addCmds.put("removecell", new RemoveCell()); - addCmds.put("rcell", new RemoveCell()); - addCmds.put("rc", new RemoveCell()); - addCmds.put("stop", new Stop()); - addCmds.put("s", new Stop()); - addCmds.put("telein", new TeleIn()); - addCmds.put("teleportin", new TeleIn()); - addCmds.put("teleout", new TeleOut()); - addCmds.put("teleportout", new TeleOut()); - addCmds.put("transfer", new Transfer()); - addCmds.put("trans", new Transfer()); - addCmds.put("version", new Version()); - addCmds.put("ver", new Version()); - addCmds.put("v", new Version()); } private void load(Class c) { diff --git a/src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java b/src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java new file mode 100644 index 0000000..777516e --- /dev/null +++ b/src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java @@ -0,0 +1,27 @@ +package com.graywolf336.jail.command.commands.jewels; + +import java.util.List; + +import com.lexicalscope.jewel.cli.Option; + +public interface Jailing { + + @Option(longName={"player", "pl"}, shortName="p", description = "the player's name") + public String getPlayer(); + + @Option(longName={"time", "length"}, shortName="t", description = "the amount of time") + public String getTime(); + + @Option(longName={"jail", "prison"}, shortName="j", description = "the jail") + public String getJail(); + + @Option(longName={"cell"}, shortName="c", description = "the cell") + public String getCell(); + + @Option(longName={"muted", "canttalk"}, shortName="m", description = "whether the prisoner is muted or not") + public boolean isMuted(); + + @Option(longName={"reason"}, shortName="r", description = "the reason this player is being jailed") + public List getReason(); + +} diff --git a/src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java b/src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java new file mode 100644 index 0000000..17e5870 --- /dev/null +++ b/src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java @@ -0,0 +1,15 @@ +package com.graywolf336.jail.command.commands.jewels; + +import com.lexicalscope.jewel.cli.Option; + +public interface Transfer { + + @Option(longName={"player", "pl"}, shortName="p", description = "the player's name") + public String getPlayer(); + + @Option(longName={"jail", "prison"}, shortName="j", description = "the jail") + public String getJail(); + + @Option(longName={"cell"}, shortName="c", description = "the cell") + public String getCell(); +} diff --git a/src/main/java/com/graywolf336/jail/command/commands/params/Jailing.java b/src/main/java/com/graywolf336/jail/command/commands/params/Jailing.java deleted file mode 100644 index 71543fb..0000000 --- a/src/main/java/com/graywolf336/jail/command/commands/params/Jailing.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.graywolf336.jail.command.commands.params; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; - -/** - * Contains all the parameters from the jail command. - * - * @author graywolf336 - * @version 1.0.1 - * @since 3.0.0 - */ -public class Jailing { - @Parameter - private List parameters = new ArrayList(); - - @Parameter(names = { "-player", "-p", "-prisoner" }, description = "The name of the player we are jailing.") - private String player = ""; - - @Parameter(names = { "-time", "-t", "-length" }, description = "The length of the jailing sentence.") - private String time = ""; - - @Parameter(names = { "-jail", "-j", "-prison" }, description = "The jail we are sending the player to.") - private String jail = ""; - - @Parameter(names = { "-cell", "-c"}, description = "The cell in the jail we are sending them to.") - private String cell = ""; - - @Parameter(names = { "-muted", "-m" }, description = "Whether they can talk or not.") - private boolean muted = false; - - @Parameter(names = { "-reason", "-r" }, description = "The reason this player is being jailed for.", variableArity = true) - private List reason = new ArrayList(); - - /** Returns the parameters. */ - public List parameters() { - return parameters; - } - - /** Returns the player parameter. */ - public String player() { - return player; - } - - /** Returns the time parameter. */ - public String time() { - return time; - } - - /** Sets the time parameter. */ - public void setTime(String time) { - this.time = time; - } - - /** Returns the jail parameter. */ - public String jail() { - return jail; - } - - /** Sets the jail parameter. */ - public void setJail(String jail) { - this.jail = jail; - } - - /** Returns the cell parameter. */ - public String cell() { - return cell; - } - - /** Returns the muted parameter. */ - public boolean muted() { - return muted; - } - - /** Sets the muted parameter. */ - public void setMuted(boolean muted) { - this.muted = muted; - } - - /** Returns the reason compressed into one string. */ - public String reason() { - String r = ""; - - for(String s : reason) { - if(r.isEmpty()) { - r = s; - }else { - r += " " + s; - } - } - - return r; - } - - /** Sets the reason. */ - public void setReason(String r) { - String[] rs = r.split(" "); - - for(String s : rs) { - reason.add(s); - } - } -} diff --git a/src/main/java/com/graywolf336/jail/command/commands/params/Transferring.java b/src/main/java/com/graywolf336/jail/command/commands/params/Transferring.java deleted file mode 100644 index 170c744..0000000 --- a/src/main/java/com/graywolf336/jail/command/commands/params/Transferring.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.graywolf336.jail.command.commands.params; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; - -public class Transferring { - @Parameter - private List parameters = new ArrayList(); - - @Parameter(names = { "-player", "-p", "-prisoner" }, description = "The name of the player we are jailing.") - private String player = ""; - - @Parameter(names = { "-jail", "-j", "-prison" }, description = "The jail we are sending the player to.") - private String jail = ""; - - @Parameter(names = { "-cell", "-c"}, description = "The cell in the jail we are sending them to.") - private String cell = ""; - - /** Returns the parameters. */ - public List parameters() { - return parameters; - } - - /** Returns the player parameter. */ - public String player() { - return player; - } - - /** Returns the jail parameter. */ - public String jail() { - return jail; - } - - /** Sets the jail parameter. */ - public void setJail(String jail) { - this.jail = jail; - } - - /** Returns the cell parameter. */ - public String cell() { - return cell; - } -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/CellCreate.java b/src/main/java/com/graywolf336/jail/command/jcommands/CellCreate.java deleted file mode 100644 index 04e157a..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/CellCreate.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Starts the creation of cells in the specified jail.") -public class CellCreate { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Check.java b/src/main/java/com/graywolf336/jail/command/jcommands/Check.java deleted file mode 100644 index 99227e4..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Check.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Checks if a player is jailed and if so gives the sender information about the jailing.") -public class Check { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Clear.java b/src/main/java/com/graywolf336/jail/command/jcommands/Clear.java deleted file mode 100644 index bd6aa7b..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Clear.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Unjails all the prisoners from all the jails or the specified jail.") -public class Clear { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/ClearForce.java b/src/main/java/com/graywolf336/jail/command/jcommands/ClearForce.java deleted file mode 100644 index 5afe014..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/ClearForce.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Starts the creation process of creating a jail.") -public class ClearForce { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Create.java b/src/main/java/com/graywolf336/jail/command/jcommands/Create.java deleted file mode 100644 index cc3a20d..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Create.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Starts the creation process of creating a jail.") -public class Create { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/JailFoundation.java b/src/main/java/com/graywolf336/jail/command/jcommands/JailFoundation.java deleted file mode 100644 index 8b595eb..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/JailFoundation.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import com.beust.jcommander.Parameter; - -public class JailFoundation { - @Parameter(names = { "-v", "-verbose" }) - public boolean verbose = false; -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/JailList.java b/src/main/java/com/graywolf336/jail/command/jcommands/JailList.java deleted file mode 100644 index 0c57a05..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/JailList.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Lists all the jails in the system.") -public class JailList { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/ListCells.java b/src/main/java/com/graywolf336/jail/command/jcommands/ListCells.java deleted file mode 100644 index 3147cfd..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/ListCells.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Lists all the cells in a certain jail.") -public class ListCells { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Mute.java b/src/main/java/com/graywolf336/jail/command/jcommands/Mute.java deleted file mode 100644 index a8b1146..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Mute.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Mutes a player who is in jail.") -public class Mute { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Reload.java b/src/main/java/com/graywolf336/jail/command/jcommands/Reload.java deleted file mode 100644 index c6d2d96..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Reload.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Reloads the plugin and data and all.") -public class Reload { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/RemoveCell.java b/src/main/java/com/graywolf336/jail/command/jcommands/RemoveCell.java deleted file mode 100644 index e87e56a..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/RemoveCell.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Removes the cell from the jail.") -public class RemoveCell { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Stop.java b/src/main/java/com/graywolf336/jail/command/jcommands/Stop.java deleted file mode 100644 index f361eae..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Stop.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Stop the creations of anything.") -public class Stop { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/TeleIn.java b/src/main/java/com/graywolf336/jail/command/jcommands/TeleIn.java deleted file mode 100644 index 88db871..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/TeleIn.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Teleports a player to the in of jail.") -public class TeleIn { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/TeleOut.java b/src/main/java/com/graywolf336/jail/command/jcommands/TeleOut.java deleted file mode 100644 index d49d5e7..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/TeleOut.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Teleports the player to the teleport out location.") -public class TeleOut { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Transfer.java b/src/main/java/com/graywolf336/jail/command/jcommands/Transfer.java deleted file mode 100644 index 9972672..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Transfer.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Transfers a player to another jail.") -public class Transfer { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jcommands/Version.java b/src/main/java/com/graywolf336/jail/command/jcommands/Version.java deleted file mode 100644 index 7f92904..0000000 --- a/src/main/java/com/graywolf336/jail/command/jcommands/Version.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.graywolf336.jail.command.jcommands; - -import java.util.ArrayList; -import java.util.List; - -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(commandDescription = "Shows the version of the plugin.") -public class Version { - @Parameter - private List parameters = new ArrayList(); -} diff --git a/src/main/java/com/graywolf336/jail/command/jewel/Jailing.java b/src/main/java/com/graywolf336/jail/command/jewel/Jailing.java deleted file mode 100644 index 3d46a1b..0000000 --- a/src/main/java/com/graywolf336/jail/command/jewel/Jailing.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.graywolf336.jail.command.jewel; - -import java.util.List; - -import com.lexicalscope.jewel.cli.Option; - -public interface Jailing { - @Option(shortName={"player", "pl", "p"}) - String getPlayer(); - - @Option(shortName="c") - String getCell(); - - @Option(shortName="r") - List getReason(); -} diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java index f09552e..2fdbafd 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java @@ -8,8 +8,6 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.beust.jcommander.JCommander; -import com.beust.jcommander.ParameterException; import com.graywolf336.jail.JailManager; import com.graywolf336.jail.Util; import com.graywolf336.jail.beans.Cell; @@ -17,10 +15,12 @@ import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.CommandInfo; -import com.graywolf336.jail.command.commands.params.Jailing; +import com.graywolf336.jail.command.commands.jewels.Jailing; import com.graywolf336.jail.enums.LangString; import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.events.PrePrisonerJailedEvent; +import com.lexicalscope.jewel.cli.ArgumentValidationException; +import com.lexicalscope.jewel.cli.CliFactory; @CommandInfo( maxArgs = -1, @@ -56,26 +56,26 @@ public class JailCommand implements Command { //has a name which is one of our subcommands if(!arguments.contains("-p")) arguments.add(0, "-p"); - Jailing params = new Jailing(); + Jailing params = null; try { - new JCommander(params, arguments.toArray(new String[arguments.size()])); - }catch(ParameterException e) { + params = CliFactory.parseArguments(Jailing.class, args); + }catch(ArgumentValidationException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); return true; } //Check if they've actually given us a player to jail - if(params.player().isEmpty()) { + if(params.getPlayer().isEmpty()) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.JAILING)); return true; }else { - jm.getPlugin().debug("We are getting ready to handle jailing: " + params.player()); + jm.getPlugin().debug("We are getting ready to handle jailing: " + params.getPlayer()); } //Check if the given player is already jailed or not - if(jm.isPlayerJailed(params.player())) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED, params.player())); + if(jm.isPlayerJailed(params.getPlayer())) { + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED, params.getPlayer())); return true; } @@ -83,12 +83,12 @@ public class JailCommand implements Command { //from the config and if that isn't there then we default to thirty minutes. Long time = 10L; try { - if(params.time().isEmpty()) { + if(params.getTime().isEmpty()) { time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m")); - }else if(params.time() == String.valueOf(-1)) { + }else if(params.getTime() == String.valueOf(-1)) { time = -1L; }else { - time = Util.getTime(params.time()); + time = Util.getTime(params.getTime()); } }catch(Exception e) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NUMBERFORMATINCORRECT)); @@ -98,35 +98,37 @@ public class JailCommand implements Command { //Check the jail params. If it is empty, let's get the default jail //from the config. If that is nearest, let's make a call to getting the nearest jail to //the sender but otherwise if it isn't nearest then let's set it to the default jail - //which is defined in the config. After that is done, we set the name of it in the params - //so that we can keep consistency. - if(params.jail().isEmpty()) { + //which is defined in the config. + String jailName = ""; + if(params.getJail().isEmpty()) { String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath()); if(dJail.equalsIgnoreCase("nearest")) { - params.setJail(jm.getNearestJail(sender).getName()); + jailName = jm.getNearestJail(sender).getName(); }else { - params.setJail(jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath())); + jailName = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath()); } - }else if(jm.getJail(params.jail()) == null) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.jail())); + }else if(jm.getJail(params.getJail()) == null) { + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail())); return true; + }else { + jailName = params.getJail(); } //Check if the cell is defined, and if so check to be sure it exists. - if(!params.cell().isEmpty()) { - if(jm.getJail(params.jail()).getCell(params.cell()) == null) { + if(!params.getCell().isEmpty()) { + if(jm.getJail(params.getJail()).getCell(params.getCell()) == null) { //There is no cell by that name - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.cell(), params.jail() })); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() })); return true; - }else if(jm.getJail(params.jail()).getCell(params.cell()).hasPrisoner()) { + }else if(jm.getJail(params.getJail()).getCell(params.getCell()).hasPrisoner()) { //If the cell has a prisoner, don't allow jailing them to that particular cell - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.cell())); - Cell suggestedCell = jm.getJail(params.jail()).getFirstEmptyCell(); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell())); + Cell suggestedCell = jm.getJail(params.getJail()).getFirstEmptyCell(); if(suggestedCell != null) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.jail(), suggestedCell.getName() })); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getJail(), suggestedCell.getName() })); }else { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.jail())); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getJail())); } return true; @@ -134,16 +136,26 @@ public class JailCommand implements Command { } //If the jailer gave no reason, then let's get the default reason - if(params.reason().isEmpty()) { - params.setReason(jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON)); + String reason = ""; + if(params.getReason().isEmpty()) { + reason = jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON); + }else { + StringBuilder sb = new StringBuilder(); + for(String s : params.getReason()) { + sb.append(s).append(' '); + } + + sb.deleteCharAt(sb.length() - 1); + reason = sb.toString(); } //If the config has automatic muting, then let's set them as muted + boolean muted = params.isMuted(); if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath())) { - params.setMuted(true); + muted = true; } - Player p = jm.getPlugin().getServer().getPlayer(params.player()); + Player p = jm.getPlugin().getServer().getPlayer(params.getPlayer()); //If the player instance is not null and the player has the permission //'jail.cantbejailed' then don't allow this to happen @@ -153,9 +165,9 @@ public class JailCommand implements Command { } //Get the jail instance from the name of jail in the params. - Jail j = jm.getJail(params.jail()); - Cell c = j.getCell(params.cell()); - Prisoner pris = new Prisoner(params.player(), params.muted(), time, sender.getName(), params.reason()); + Jail j = jm.getJail(jailName); + Cell c = j.getCell(params.getCell()); + Prisoner pris = new Prisoner(params.getPlayer(), muted, time, sender.getName(), reason); //call the event PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, pris.getJailer()); @@ -164,7 +176,7 @@ public class JailCommand implements Command { //check if the event is cancelled if(event.isCancelled()) { if(event.getCancelledMessage().isEmpty()) - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, params.player())); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, params.getPlayer())); else sender.sendMessage(event.getCancelledMessage()); diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java index 54cb123..ce56f86 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java @@ -3,15 +3,15 @@ package com.graywolf336.jail.command.subcommands; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import com.beust.jcommander.JCommander; -import com.beust.jcommander.ParameterException; import com.graywolf336.jail.JailManager; import com.graywolf336.jail.beans.Cell; import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.CommandInfo; -import com.graywolf336.jail.command.commands.params.Transferring; +import com.graywolf336.jail.command.commands.jewels.Transfer; import com.graywolf336.jail.enums.LangString; +import com.lexicalscope.jewel.cli.ArgumentValidationException; +import com.lexicalscope.jewel.cli.CliFactory; @CommandInfo( maxArgs = 6, @@ -29,59 +29,59 @@ public class JailTransferCommand implements Command { } //Parse the command - Transferring params = new Transferring(); + Transfer params = null; try { - new JCommander(params, args); - }catch(ParameterException e) { + params = CliFactory.parseArguments(Transfer.class, args); + }catch(ArgumentValidationException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); return true; } //Verify they gave us a player and if so check if they're jailed - if(params.player().isEmpty()) { + if(params.getPlayer().isEmpty()) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING)); return true; - }else if(!jm.isPlayerJailed(params.player())) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.player())); + }else if(!jm.isPlayerJailed(params.getPlayer())) { + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.getPlayer())); return true; } - jm.getPlugin().debug("Checking everything before we transfer: " + params.player()); + jm.getPlugin().debug("Checking everything before we transfer: " + params.getPlayer()); //If they didn't provide a jail, tell them we need one - if(params.jail().isEmpty()) { + if(params.getJail().isEmpty()) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAJAIL, LangString.TRANSFERRING)); return true; }else { //Check if the jail they did provide exists - if(jm.getJail(params.jail()) == null) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.jail())); + if(jm.getJail(params.getJail()) == null) { + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail())); return true; } } - Jail target = jm.getJail(params.jail()); + Jail target = jm.getJail(params.getJail()); Cell targetCell = null; //Check if they provided a cell and if so does it exist - if(!params.cell().isEmpty()) { - if(target.getCell(params.cell()) == null) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, params.cell())); + if(!params.getCell().isEmpty()) { + if(target.getCell(params.getCell()) == null) { + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, params.getCell())); return true; }else { //Store the cell for easy of access and also check if it already is full - targetCell = target.getCell(params.cell()); + targetCell = target.getCell(params.getCell()); if(targetCell.hasPrisoner()) { //If the cell has a prisoner, don't allow jailing them to that particular cell - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.cell())); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell())); //But suggest the first empty cell we find - Cell suggestedCell = jm.getJail(params.jail()).getFirstEmptyCell(); + Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell(); if(suggestedCell != null) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.jail(), suggestedCell.getName() })); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getCell(), suggestedCell.getName() })); }else { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.jail())); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getCell())); } return true; @@ -92,9 +92,9 @@ public class JailTransferCommand implements Command { jm.getPlugin().debug("Sending the transferring off, jail and cell check all came out clean."); //Start the transferring of the prisoner - jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.player()), - jm.getJailPlayerIsIn(params.player()).getCellPrisonerIsIn(params.player()), - target, targetCell, jm.getPrisoner(params.player())); + jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.getPlayer()), + jm.getJailPlayerIsIn(params.getPlayer()).getCellPrisonerIsIn(params.getPlayer()), + target, targetCell, jm.getPrisoner(params.getPlayer())); return true; } diff --git a/src/test/java/test/java/com/graywolf336/jail/TestCommandParams.java b/src/test/java/test/java/com/graywolf336/jail/TestCommandParams.java deleted file mode 100644 index 85d4d8a..0000000 --- a/src/test/java/test/java/com/graywolf336/jail/TestCommandParams.java +++ /dev/null @@ -1,35 +0,0 @@ -package test.java.com.graywolf336.jail; - -import junit.framework.Assert; - -import org.junit.Test; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.ParameterException; -import com.graywolf336.jail.command.commands.params.Jailing; - -public class TestCommandParams { - - @Test - public void TestJailCommand() { - Jailing jail = new Jailing(); - //"/jail [-p name] (-t time) (-j JailName) (-c CellName) (-m Muted) (-r A reason for jailing)" - String[] params = { "-p", "graywolf336", "-t", "30", "-j", "den", "-c", "cell_01", "-m", "-r", "He", "was", "a", "very", "bad", "boy." }; - new JCommander(jail, params); - - Assert.assertEquals("The player is not the one we provided.", "graywolf336", jail.player()); - Assert.assertEquals("The time doesn't match what we gave.", "30", jail.time()); - Assert.assertEquals("The jail is not the one we specified.", "den", jail.jail()); - Assert.assertEquals("The cell doesn't match up.", "cell_01", jail.cell()); - Assert.assertEquals("The muted is false.", true, jail.muted()); - Assert.assertEquals("Jailed reason didn't match up.", "He was a very bad boy.", jail.reason()); - } - - @Test(expected=ParameterException.class) - public void TestFailedJailCommand() { - Jailing jail = new Jailing(); - String[] params = { "-t", "30", "-j", "den", "-c", "cell_01", "-m true", "-r", "He", "was", "a", "very", "bad", "boy." }; - - new JCommander(jail, params); - } -} diff --git a/src/test/java/test/java/com/graywolf336/jail/TestJCommander.java b/src/test/java/test/java/com/graywolf336/jail/TestJCommander.java deleted file mode 100644 index 50a7a1e..0000000 --- a/src/test/java/test/java/com/graywolf336/jail/TestJCommander.java +++ /dev/null @@ -1,36 +0,0 @@ -package test.java.com.graywolf336.jail; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; - -import org.junit.Test; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; - -@Parameters(separators = ":") -public class TestJCommander { - @Parameter - public List parameters = new ArrayList(); - - @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity") - public Integer verbose = 1; - - @Parameter(names = "-groups", description = "Comma-separated list of group names to be run") - public String groups; - - @Parameter(names = "-debug", description = "Debug mode") - public boolean debug = false; - - @Test - public void testJCommander() { - String[] args = { "-log:2", "-groups:unit" }; - new JCommander(this, args); - - Assert.assertEquals(this.verbose.intValue(), 2); - Assert.assertEquals(this.groups.toLowerCase(), "unit"); - } -} diff --git a/src/test/java/test/java/com/graywolf336/jail/TestJewel.java b/src/test/java/test/java/com/graywolf336/jail/TestJewel.java deleted file mode 100644 index 9d02431..0000000 --- a/src/test/java/test/java/com/graywolf336/jail/TestJewel.java +++ /dev/null @@ -1,28 +0,0 @@ -package test.java.com.graywolf336.jail; - -import junit.framework.Assert; - -import org.junit.Test; - -import com.graywolf336.jail.command.jewel.Jailing; -import com.lexicalscope.jewel.cli.CliFactory; - -public class TestJewel { - @Test - public void testJewel() { - String[] args = { "--player", "graywolf336", "-c", "testing", "-r", "This", "is", "a", "reason" }; - Jailing j = CliFactory.parseArguments(Jailing.class, args); - - Assert.assertEquals("graywolf336", j.getPlayer()); - Assert.assertEquals("testing", j.getCell()); - - StringBuilder sb = new StringBuilder(); - for(String s : j.getReason()) { - sb.append(s).append(' '); - } - - sb.deleteCharAt(sb.length() - 1); - - Assert.assertEquals("This is a reason", sb.toString()); - } -} From 48a7435fbe94a457b59388476df4fd32c04ab9b6 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Tue, 11 Feb 2014 20:44:19 -0600 Subject: [PATCH 2/3] Fix the tests failing and also fix the jail command not doing anything. --- .../java/com/graywolf336/jail/JailMain.java | 2 +- .../graywolf336/jail/command/JailHandler.java | 4 --- .../jail/command/commands/jewels/Jailing.java | 7 ++++- .../jail/command/subcommands/JailCommand.java | 2 +- .../com/graywolf336/jail/JewelCommands.java | 28 +++++++++++++++++++ 5 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/test/java/test/java/com/graywolf336/jail/JewelCommands.java diff --git a/src/main/java/com/graywolf336/jail/JailMain.java b/src/main/java/com/graywolf336/jail/JailMain.java index 60bd2f4..2bb7d99 100644 --- a/src/main/java/com/graywolf336/jail/JailMain.java +++ b/src/main/java/com/graywolf336/jail/JailMain.java @@ -118,7 +118,7 @@ public class JailMain extends JavaPlugin { */ public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { if(command.getName().equalsIgnoreCase("jail")) { - jh.handleCommand(jm, sender, args); + jh.parseCommand(jm, sender, args); }else { cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args); } diff --git a/src/main/java/com/graywolf336/jail/command/JailHandler.java b/src/main/java/com/graywolf336/jail/command/JailHandler.java index 015bd01..db5330f 100644 --- a/src/main/java/com/graywolf336/jail/command/JailHandler.java +++ b/src/main/java/com/graywolf336/jail/command/JailHandler.java @@ -37,10 +37,6 @@ public class JailHandler { plugin.getLogger().info("Loaded " + commands.size() + " sub-commands of /jail."); } - - public void handleCommand(JailManager jm, CommandSender sender, String... args) { - - } /** * Handles the given command and checks that the command is in valid form. diff --git a/src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java b/src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java index 777516e..a7dc5ff 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java +++ b/src/main/java/com/graywolf336/jail/command/commands/jewels/Jailing.java @@ -19,9 +19,14 @@ public interface Jailing { public String getCell(); @Option(longName={"muted", "canttalk"}, shortName="m", description = "whether the prisoner is muted or not") - public boolean isMuted(); + public boolean getMuted(); @Option(longName={"reason"}, shortName="r", description = "the reason this player is being jailed") public List getReason(); + public boolean isTime(); + public boolean isJail(); + public boolean isCell(); + public boolean isMuted(); + public boolean isReason(); } diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java index 2fdbafd..83656b8 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java @@ -150,7 +150,7 @@ public class JailCommand implements Command { } //If the config has automatic muting, then let's set them as muted - boolean muted = params.isMuted(); + boolean muted = params.getMuted(); if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath())) { muted = true; } diff --git a/src/test/java/test/java/com/graywolf336/jail/JewelCommands.java b/src/test/java/test/java/com/graywolf336/jail/JewelCommands.java new file mode 100644 index 0000000..99519ed --- /dev/null +++ b/src/test/java/test/java/com/graywolf336/jail/JewelCommands.java @@ -0,0 +1,28 @@ +package test.java.com.graywolf336.jail; + +import junit.framework.Assert; + +import org.junit.Test; + +import com.graywolf336.jail.command.commands.jewels.Jailing; +import com.lexicalscope.jewel.cli.CliFactory; + +public class JewelCommands { + @Test + public void testJewel() { + String[] args = { "--player", "graywolf336", "-c", "testing", "-r", "This", "is", "a", "reason" }; + Jailing j = CliFactory.parseArguments(Jailing.class, args); + + Assert.assertEquals("graywolf336", j.getPlayer()); + Assert.assertEquals("testing", j.getCell()); + + StringBuilder sb = new StringBuilder(); + for(String s : j.getReason()) { + sb.append(s).append(' '); + } + + sb.deleteCharAt(sb.length() - 1); + + Assert.assertEquals("This is a reason", sb.toString()); + } +} \ No newline at end of file From 87bb9feecb8ff618870ab07ab3186ad5a775219c Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Tue, 11 Feb 2014 20:46:23 -0600 Subject: [PATCH 3/3] Make all the arguments optional on the transfer, we handle that ourself. This way we handle it ourself for language purposes. --- .../graywolf336/jail/command/commands/jewels/Transfer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java b/src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java index 17e5870..33fe388 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java +++ b/src/main/java/com/graywolf336/jail/command/commands/jewels/Transfer.java @@ -12,4 +12,8 @@ public interface Transfer { @Option(longName={"cell"}, shortName="c", description = "the cell") public String getCell(); + + public boolean isPlayer(); + public boolean isJail(); + public boolean isCell(); }