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

@ -11,7 +11,7 @@ import org.bukkit.Location;
* *
* @author graywolf336 * @author graywolf336
* @since 2.x.x * @since 2.x.x
* @version 3.0.0 * @version 3.0.1
*/ */
public class Prisoner { public class Prisoner {
private String name, jailer, reason, inventory, armor; private String name, jailer, reason, inventory, armor;
@ -108,9 +108,22 @@ public class Prisoner {
* Adds the given time to the remaining time the prisoner has left. * Adds the given time to the remaining time the prisoner has left.
* *
* @param time to add to the prisoner's remaining time. * @param time to add to the prisoner's remaining time.
* @return the new remaining time the prisoner has
*/ */
public void addTime(long time) { public long addTime(long time) {
this.time += time; this.time += time;
return this.time;
}
/**
* Subtracts the given time from the remaining time the prisoner has left.
*
* @param time to subtract from the prisoner's remaining time.
* @return the new remaining time the prisoner has
*/
public long subtractTime(long time) {
this.time -= time;
return this.time;
} }
/** Gets whether the player is offline or not. */ /** Gets whether the player is offline or not. */

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.JailStopCommand;
import com.graywolf336.jail.command.subcommands.JailTeleInCommand; import com.graywolf336.jail.command.subcommands.JailTeleInCommand;
import com.graywolf336.jail.command.subcommands.JailTeleOutCommand; 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.JailTransferAllCommand;
import com.graywolf336.jail.command.subcommands.JailTransferCommand; import com.graywolf336.jail.command.subcommands.JailTransferCommand;
import com.graywolf336.jail.command.subcommands.JailVersionCommand; import com.graywolf336.jail.command.subcommands.JailVersionCommand;
@ -187,6 +188,7 @@ public class JailHandler {
load(JailStopCommand.class); load(JailStopCommand.class);
load(JailTeleInCommand.class); load(JailTeleInCommand.class);
load(JailTeleOutCommand.class); load(JailTeleOutCommand.class);
load(JailTimeCommand.class);
load(JailTransferAllCommand.class); load(JailTransferAllCommand.class);
load(JailTransferCommand.class); load(JailTransferCommand.class);
load(JailVersionCommand.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;
}
}

View File

@ -60,6 +60,8 @@ public enum LangString {
OFFLINEJAIL ("jailing"), OFFLINEJAIL ("jailing"),
/** The message sent to the jailer when they jail someone who is online. */ /** The message sent to the jailer when they jail someone who is online. */
ONLINEJAIL ("jailing"), ONLINEJAIL ("jailing"),
/** The message sent when finding out how much time a prisoner has. */
PRISONERSTIME ("jailing"),
/** The message sent to the prisoner when they try to do something but it is protected. */ /** The message sent to the prisoner when they try to do something but it is protected. */
PROTECTIONMESSAGE ("jailing"), PROTECTIONMESSAGE ("jailing"),
/** The message sent to the prisoner when they try to do something and it is protected, but no penalty. */ /** The message sent to the prisoner when they try to do something and it is protected, but no penalty. */

View File

@ -58,6 +58,7 @@ language:
nowunmuted: '&9%0% is now unmuted.' nowunmuted: '&9%0% is now unmuted.'
offlinejail: '&2%0% is offline and will be jailed when they next come online for %1% minutes.' offlinejail: '&2%0% is offline and will be jailed when they next come online for %1% minutes.'
onlinejail: '&2%0% was jailed for %1% minutes.' onlinejail: '&2%0% was jailed for %1% minutes.'
prisonerstime: '&2%0% has %1% minutes remaining.'
protectionmessage: '&c%0% minutes have been added to your time for %1%.' protectionmessage: '&c%0% minutes have been added to your time for %1%.'
protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.' protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.'
provideaplayer: '&cPlease provide a player when %0% &cthem.' provideaplayer: '&cPlease provide a player when %0% &cthem.'