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 e2afc8f..1bd4684 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 @@ -11,6 +11,9 @@ public interface Jailing { @Option(longName={"time", "length"}, shortName="t", description = "the amount of time") public String getTime(); + + @Option(longName={"forever", "eternity", "infinite"}, shortName="i", description = "jail the player for eternity") + public boolean getInfinite(); @Option(longName={"jail", "prison"}, shortName="j", description = "the jail") public String getJail(); @@ -27,6 +30,7 @@ public interface Jailing { @Option(longName={"reason"}, shortName="r", description = "the reason this player is being jailed") public List getReason(); + public boolean isInfinite(); public boolean isTime(); public boolean isJail(); public boolean isCell(); 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 467086c..3bc2b9d 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java @@ -83,17 +83,21 @@ 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.isTime()) { - time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.DEFAULTTIME.getPath(), "30m")); - }else if(params.getTime() == String.valueOf(-1)) { - time = -1L; - }else { + if(params.isTime()) { time = Util.getTime(params.getTime()); + }else { + time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.DEFAULTTIME.getPath(), "30m")); } }catch(Exception e) { sender.sendMessage(Lang.NUMBERFORMATINCORRECT.get()); return true; } + + //Check if they provided the infinite argument + //if so, then set the time jailed forever + if(params.isInfinite()) { + time = -1L; + } //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 diff --git a/src/test/java/test/java/com/graywolf336/jail/TestJailCommandInfo.java b/src/test/java/test/java/com/graywolf336/jail/TestJailCommandInfo.java index 85cf84c..a90450a 100644 --- a/src/test/java/test/java/com/graywolf336/jail/TestJailCommandInfo.java +++ b/src/test/java/test/java/com/graywolf336/jail/TestJailCommandInfo.java @@ -161,6 +161,27 @@ public class TestJailCommandInfo { assertEquals("This is a reason", sb.toString()); } + + @Test + public void testForInfiniteJailTime() { + String[] args = { "-p", "graywolf336", "-j", "hardcore", "-iamr", "This", "should", "be", "a", "reason." }; + Jailing j = CliFactory.parseArguments(Jailing.class, args); + + assertEquals("The player parsed doesn't match.", "graywolf336", j.getPlayer()); + assertTrue("No jail was parsed.", j.isJail()); + assertEquals("The jail parsed doesn't match.", "hardcore", j.getJail()); + assertTrue("The time isn't infinite.", j.isInfinite()); + assertTrue("The any cell wasn't parsed.", j.isAnyCell()); + assertTrue("The player wouldn't be muted.", j.isMuted()); + assertTrue("The reason wasn't provided?", j.isReason()); + StringBuilder sb = new StringBuilder(); + for(String s : j.getReason()) { + sb.append(s).append(' '); + } + + sb.deleteCharAt(sb.length() - 1); + assertEquals("The reason doesn't match.", "This should be a reason.", sb.toString()); + } @Test public void testTransferForJailAndCell() {