From fe7cb9f5a57ed7479998af64967ee4243509ed68 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Sat, 15 Mar 2014 14:40:50 -0500 Subject: [PATCH] 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/ --- .../com/graywolf336/jail/beans/Prisoner.java | 17 +++++- .../graywolf336/jail/command/JailHandler.java | 2 + .../command/subcommands/JailTimeCommand.java | 55 +++++++++++++++++++ .../graywolf336/jail/enums/LangString.java | 2 + src/main/resources/en.yml | 1 + 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java diff --git a/src/main/java/com/graywolf336/jail/beans/Prisoner.java b/src/main/java/com/graywolf336/jail/beans/Prisoner.java index 9b48aac..90f6396 100644 --- a/src/main/java/com/graywolf336/jail/beans/Prisoner.java +++ b/src/main/java/com/graywolf336/jail/beans/Prisoner.java @@ -11,7 +11,7 @@ import org.bukkit.Location; * * @author graywolf336 * @since 2.x.x - * @version 3.0.0 + * @version 3.0.1 */ public class Prisoner { 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. * * @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; + 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. */ diff --git a/src/main/java/com/graywolf336/jail/command/JailHandler.java b/src/main/java/com/graywolf336/jail/command/JailHandler.java index 7fb0f0b..52f63e8 100644 --- a/src/main/java/com/graywolf336/jail/command/JailHandler.java +++ b/src/main/java/com/graywolf336/jail/command/JailHandler.java @@ -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); diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java new file mode 100644 index 0000000..1efae8a --- /dev/null +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java @@ -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