When unjailing someone, if they've never been online and have time

remaining then forcefully remove them.
This commit is contained in:
graywolf336 2014-01-28 22:20:33 -06:00
parent 2acfbf098e
commit cab6d7fdf9
4 changed files with 30 additions and 5 deletions

View File

@ -389,4 +389,17 @@ public class PrisonerManager {
player.sendMessage(pl.getJailIO().getLanguageString(LangString.UNJAILED)); player.sendMessage(pl.getJailIO().getLanguageString(LangString.UNJAILED));
} }
public void forceUnJail(Jail jail, Cell cell, Player player, Prisoner prisoner) {
if(player == null) {
//Player is offline, we just forcefully remove them from the database
pl.getJailIO().removePrisoner(jail, cell, prisoner);
}else {
try {
unJail(jail, cell, player, prisoner);
} catch (Exception e) {
releasePrisoner(player, prisoner);
}
}
}
} }

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
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.enums.LangString; import com.graywolf336.jail.enums.LangString;
@ -25,18 +26,26 @@ public class UnjailCommand implements Command {
//Check if the player is jailed //Check if the player is jailed
if(jm.isPlayerJailed(args[0])) { if(jm.isPlayerJailed(args[0])) {
Jail j = jm.getJailPlayerIsIn(args[0]); Jail j = jm.getJailPlayerIsIn(args[0]);
Prisoner pris = j.getPrisoner(args[0]);
Player p = jm.getPlugin().getServer().getPlayerExact(args[0]); Player p = jm.getPlugin().getServer().getPlayerExact(args[0]);
//Check if the player is on the server or not //Check if the player is on the server or not
if(p == null) { if(p == null) {
//Check if the player has offline pending and their remaining time is above 0, if so then
//forceably unjail them
if(pris.isOfflinePending() && pris.getRemainingTime() != 0L) {
jm.getPlugin().getPrisonerManager().forceUnJail(j, j.getCellPrisonerIsIn(args[0]), p, pris);
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
}else {
//The player is not, so we'll set the remaining time to zero and do it when they login next //The player is not, so we'll set the remaining time to zero and do it when they login next
j.getPrisoner(args[0]).setRemainingTime(0L); pris.setRemainingTime(0L);
j.getPrisoner(args[0]).setOfflinePending(true); pris.setOfflinePending(true);
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0])); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0]));
}
}else { }else {
//Player is online, so let's try unjailing them //Player is online, so let's try unjailing them
try { try {
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(args[0]), p, j.getPrisoner(args[0])); jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(args[0]), p, pris);
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(ChatColor.RED + e.getMessage()); sender.sendMessage(ChatColor.RED + e.getMessage());
} }

View File

@ -38,6 +38,8 @@ public enum LangString {
CELLNOTEMPTY ("jailing"), CELLNOTEMPTY ("jailing"),
/** The message sent when someone is jailed without a reason. */ /** The message sent when someone is jailed without a reason. */
DEFAULTJAILEDREASON ("jailing"), DEFAULTJAILEDREASON ("jailing"),
/** The message sent when someone is unjailed yet they never came online and so they were forcefully unjailed. */
FORCEUNJAILED ("jailing"),
/** The message sent when players are jailed without a reason. */ /** The message sent when players are jailed without a reason. */
JAILED ("jailing"), JAILED ("jailing"),
/** The message sent when players are jailed with a reason. */ /** The message sent when players are jailed with a reason. */

View File

@ -32,6 +32,7 @@ language:
cantbejailed: '&cThat player can not be jailed.' cantbejailed: '&cThat player can not be jailed.'
cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.' cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.'
defaultjailedreason: 'Breaking the rules.' defaultjailedreason: 'Breaking the rules.'
forceunjailed: '&c%0% was jailed but never came online and was forcefully unjailed.'
jailed: '&cYou have been jailed!' jailed: '&cYou have been jailed!'
jailedwithreason: '&cYou have been jailed for: %0%' jailedwithreason: '&cYou have been jailed for: %0%'
muted: '&cStop talking, you are in jail.' muted: '&cStop talking, you are in jail.'