Let's start some work on the jail command.

This commit is contained in:
graywolf336 2013-12-19 11:13:07 -06:00
parent f8192aa2a8
commit 17ac609a0f
3 changed files with 41 additions and 6 deletions

View File

@ -1,12 +1,15 @@
package com.graywolf336.jail.command.commands; package com.graywolf336.jail.command.commands;
import java.util.concurrent.TimeUnit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.beust.jcommander.JCommander; import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.command.parameters.JailParameters; import com.graywolf336.jail.command.parameters.JailParameters;
@ -22,24 +25,31 @@ import com.graywolf336.jail.command.parameters.JailParameters;
public class JailCommand implements Command { public class JailCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) { public boolean execute(JailManager jm, CommandSender sender, String... args) {
if(jm.getJails().size() == 0) {
sender.sendMessage(ChatColor.RED + "No jails found.");
return true;
}
JailParameters params = new JailParameters(); JailParameters params = new JailParameters();
try { try {
new JCommander(params, args); new JCommander(params, args);
}catch(ParameterException e) { }catch(ParameterException e) {
sender.sendMessage(e.getMessage()); sender.sendMessage(ChatColor.RED + e.getMessage());
return true; return true;
} }
Long time = Long.parseLong(params.time());
Player p = jm.getPlugin().getServer().getPlayer(params.player()); Player p = jm.getPlugin().getServer().getPlayer(params.player());
Prisoner pris = new Prisoner(params.player(), params.muted(), TimeUnit.MILLISECONDS.convert(time, TimeUnit.MINUTES));
//Player is not online //Player is not online
if(p == null) { if(p == null) {
sender.sendMessage(params.player() + " is offline and will be jailed for " + params.time() + " minutes in the jail " + params.jail() + "in the cell " + params.cell() + " and will be muted: " + params.muted() + "."); sender.sendMessage(pris.getName() + " is offline and will be jailed for " + pris.getRemainingTime() + " milliseconds in the jail " + params.jail() + "in the cell " + params.cell() + " and will be muted: " + pris.isMuted() + ".");
}else { }else {
//Player *is* online //Player *is* online
sender.sendMessage(params.player() + " is online and will be jailed for " + params.time() + " minutes in the jail " + params.jail() + "in the cell " + params.cell() + " and will be muted: " + params.muted() + "."); sender.sendMessage(pris.getName() + " is online and will be jailed for " + pris.getRemainingTime() + " milliseconds in the jail " + params.jail() + "in the cell " + params.cell() + " and will be muted: " + pris.isMuted() + ".");
} }
return true; return true;

View File

@ -16,7 +16,7 @@ public class JailParameters {
@Parameter @Parameter
private List<String> parameters = new ArrayList<String>(); private List<String> parameters = new ArrayList<String>();
@Parameter(names = { "-p", "-player", "-prisoner" }, description = "The name of the player we are jailing.") @Parameter(names = { "-p", "-player", "-prisoner" }, description = "The name of the player we are jailing.", required = true)
private String player = ""; private String player = "";
@Parameter(names = { "-t", "-time", "-length" }, description = "The length of the jailing sentence.") @Parameter(names = { "-t", "-time", "-length" }, description = "The length of the jailing sentence.")
@ -49,11 +49,21 @@ public class JailParameters {
return time; return time;
} }
/** Sets the time parameter. */
public void setTime(String time) {
this.time = time;
}
/** Returns the jail parameter. */ /** Returns the jail parameter. */
public String jail() { public String jail() {
return jail; return jail;
} }
/** Sets the jail parameter. */
public void setJail(String jail) {
this.jail = jail;
}
/** Returns the cell parameter. */ /** Returns the cell parameter. */
public String cell() { public String cell() {
return cell; return cell;
@ -64,6 +74,11 @@ public class JailParameters {
return muted; return muted;
} }
/** Sets the muted parameter. */
public void setMuted(boolean muted) {
this.muted = muted;
}
/** Returns the reason compressed into one string. */ /** Returns the reason compressed into one string. */
public String reason() { public String reason() {
String r = ""; String r = "";

View File

@ -5,6 +5,8 @@ import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import com.beust.jcommander.JCommander; import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import com.graywolf336.jail.command.parameters.JailParameters; import com.graywolf336.jail.command.parameters.JailParameters;
public class TestCommandParams { public class TestCommandParams {
@ -23,4 +25,12 @@ public class TestCommandParams {
Assert.assertEquals("The muted is false.", true, jail.muted()); 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()); Assert.assertEquals("Jailed reason didn't match up.", "He was a very bad boy.", jail.reason());
} }
@Test(expected=ParameterException.class)
public void TestFailedJailCommand() {
JailParameters jail = new JailParameters();
String[] params = { "-t", "30", "-j", "den", "-c", "cell_01", "-m", "-r", "He", "was", "a", "very", "bad", "boy." };
new JCommander(jail, params);
}
} }