From cab6d7fdf92154e347fd44d7a0e7a29a4f559daf Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Tue, 28 Jan 2014 22:20:33 -0600 Subject: [PATCH] When unjailing someone, if they've never been online and have time remaining then forcefully remove them. --- .../com/graywolf336/jail/PrisonerManager.java | 13 +++++++++++++ .../jail/command/commands/UnjailCommand.java | 19 ++++++++++++++----- .../graywolf336/jail/enums/LangString.java | 2 ++ src/main/resources/en.yml | 1 + 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index 927e5b9..f72b02b 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -389,4 +389,17 @@ public class PrisonerManager { 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); + } + } + } } diff --git a/src/main/java/com/graywolf336/jail/command/commands/UnjailCommand.java b/src/main/java/com/graywolf336/jail/command/commands/UnjailCommand.java index c29f6a4..7c006f9 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/UnjailCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/UnjailCommand.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import com.graywolf336.jail.JailManager; import com.graywolf336.jail.beans.Jail; +import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.enums.LangString; @@ -25,18 +26,26 @@ public class UnjailCommand implements Command { //Check if the player is jailed if(jm.isPlayerJailed(args[0])) { Jail j = jm.getJailPlayerIsIn(args[0]); + Prisoner pris = j.getPrisoner(args[0]); Player p = jm.getPlugin().getServer().getPlayerExact(args[0]); //Check if the player is on the server or not if(p == null) { - //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); - j.getPrisoner(args[0]).setOfflinePending(true); - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0])); + //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 + pris.setRemainingTime(0L); + pris.setOfflinePending(true); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0])); + } }else { //Player is online, so let's try unjailing them 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) { sender.sendMessage(ChatColor.RED + e.getMessage()); } diff --git a/src/main/java/com/graywolf336/jail/enums/LangString.java b/src/main/java/com/graywolf336/jail/enums/LangString.java index d320b52..3a43396 100644 --- a/src/main/java/com/graywolf336/jail/enums/LangString.java +++ b/src/main/java/com/graywolf336/jail/enums/LangString.java @@ -38,6 +38,8 @@ public enum LangString { CELLNOTEMPTY ("jailing"), /** The message sent when someone is jailed without a reason. */ 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. */ JAILED ("jailing"), /** The message sent when players are jailed with a reason. */ diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index 2f9add0..01f5195 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -32,6 +32,7 @@ language: cantbejailed: '&cThat player can not be jailed.' cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.' defaultjailedreason: 'Breaking the rules.' + forceunjailed: '&c%0% was jailed but never came online and was forcefully unjailed.' jailed: '&cYou have been jailed!' jailedwithreason: '&cYou have been jailed for: %0%' muted: '&cStop talking, you are in jail.'