Add a new command /jail time which has easy access for add/subtract

time from a prisoner's sentence.

This command could be useful for commandblocks or something else, as it
does not need a player context. This closes Bukkit Dev Ticket:
http://dev.bukkit.org/bukkit-plugins/jail/tickets/432/
This commit is contained in:
graywolf336
2014-03-15 14:40:50 -05:00
parent 3e3f2d432e
commit fe7cb9f5a5
5 changed files with 75 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import com.graywolf336.jail.command.subcommands.JailStatusCommand;
import com.graywolf336.jail.command.subcommands.JailStopCommand;
import com.graywolf336.jail.command.subcommands.JailTeleInCommand;
import com.graywolf336.jail.command.subcommands.JailTeleOutCommand;
import com.graywolf336.jail.command.subcommands.JailTimeCommand;
import com.graywolf336.jail.command.subcommands.JailTransferAllCommand;
import com.graywolf336.jail.command.subcommands.JailTransferCommand;
import com.graywolf336.jail.command.subcommands.JailVersionCommand;
@ -187,6 +188,7 @@ public class JailHandler {
load(JailStopCommand.class);
load(JailTeleInCommand.class);
load(JailTeleOutCommand.class);
load(JailTimeCommand.class);
load(JailTransferAllCommand.class);
load(JailTransferCommand.class);
load(JailVersionCommand.class);

View File

@ -0,0 +1,55 @@
package com.graywolf336.jail.command.subcommands;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.LangString;
@CommandInfo(
maxArgs = 3,
minimumArgs = 2,
needsPlayer = false,
pattern = "time|t",
permission = "jail.command.jailtime",
usage = "/jail time <add|remove|show> <player> <time>"
)
public class JailTimeCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
if(jm.isPlayerJailed(args[2])) {
Prisoner p = jm.getPrisoner(args[2]);
switch(args.length) {
case 3:
if(args[1].equalsIgnoreCase("show")) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
new String[] { p.getName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
}else {
return false;
}
break;
case 4:
if(args[1].equalsIgnoreCase("add")) {
p.addTime(Util.getTime(args[3]));
}else if(args[1].equalsIgnoreCase("remove")) {
p.subtractTime(Util.getTime(args[3]));
}else {
return false;
}
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
new String[] { p.getName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
break;
default:
return false;
}
}else {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
}
return true;
}
}