Add the unjailforce command

This commit is contained in:
graywolf336 2014-02-03 18:44:38 -06:00
parent b1f4b7bb41
commit d0e41ed908
6 changed files with 62 additions and 4 deletions

View File

@ -137,6 +137,18 @@ public class JailManager {
return this.jails.get(name) != null; return this.jails.get(name) != null;
} }
/**
* Gets the {@link Jail jail} the given prisoner is in.
*
* @param prisoner The prisoner data for the prisoner we are checking
* @return The jail the player is in, <strong>CAN BE NULL</strong>.
*/
public Jail getJailPrisonerIsIn(Prisoner prisoner) {
if(prisoner == null) return null;
return getJailPlayerIsIn(prisoner.getName());
}
/** /**
* Gets the {@link Jail jail} the given player is in. * Gets the {@link Jail jail} the given player is in.
* *

View File

@ -390,6 +390,13 @@ public class PrisonerManager {
player.sendMessage(pl.getJailIO().getLanguageString(LangString.UNJAILED)); player.sendMessage(pl.getJailIO().getLanguageString(LangString.UNJAILED));
} }
/** Forcefully releases a {@link Prisoner prisoner} from {@link Jail}. */
public void forceRelease(Prisoner prisoner) {
Jail j = pl.getJailManager().getJailPrisonerIsIn(prisoner);
forceUnJail(j, j.getCellPrisonerIsIn(prisoner.getName()), pl.getServer().getPlayerExact(prisoner.getName()), prisoner);
}
/** Forcefully unjails a {@link Prisoner prisoner} from {@link Jail}. */
public void forceUnJail(Jail jail, Cell cell, Player player, Prisoner prisoner) { public void forceUnJail(Jail jail, Cell cell, Player player, Prisoner prisoner) {
if(player == null) { if(player == null) {
//Player is offline, we just forcefully remove them from the database //Player is offline, we just forcefully remove them from the database

View File

@ -12,7 +12,8 @@ import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.command.commands.HandCuffCommand; import com.graywolf336.jail.command.commands.HandCuffCommand;
import com.graywolf336.jail.command.commands.UnHandCuffCommand; import com.graywolf336.jail.command.commands.UnHandCuffCommand;
import com.graywolf336.jail.command.commands.UnjailCommand; import com.graywolf336.jail.command.commands.UnJailForceCommand;
import com.graywolf336.jail.command.commands.UnJailCommand;
import com.graywolf336.jail.enums.LangString; import com.graywolf336.jail.enums.LangString;
/** /**
@ -138,7 +139,8 @@ public class CommandHandler {
private void loadCommands() { private void loadCommands() {
load(HandCuffCommand.class); load(HandCuffCommand.class);
load(UnHandCuffCommand.class); load(UnHandCuffCommand.class);
load(UnjailCommand.class); load(UnJailCommand.class);
load(UnJailForceCommand.class);
} }
private void load(Class<? extends Command> c) { private void load(Class<? extends Command> c) {

View File

@ -20,7 +20,7 @@ import com.graywolf336.jail.enums.Settings;
permission = "jail.command.unjail", permission = "jail.command.unjail",
usage = "/unjail [player]" usage = "/unjail [player]"
) )
public class UnjailCommand implements Command { public class UnJailCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) { public boolean execute(JailManager jm, CommandSender sender, String... args) {
//Check if the player is jailed //Check if the player is jailed

View File

@ -0,0 +1,37 @@
package com.graywolf336.jail.command.commands;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.LangString;
import com.graywolf336.jail.enums.Settings;
@CommandInfo(
maxArgs = 1,
minimumArgs = 1,
needsPlayer = false,
pattern = "unjailforce|ujf",
permission = "jail.command.unjailforce",
usage = "/unjailforce [player]"
)
public class UnJailForceCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) {
//Check if the player is jailed
if(jm.isPlayerJailed(args[0])) {
jm.getPlugin().getPrisonerManager().forceRelease(jm.getPrisoner(args[0]));
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILING.getPath())) {
jm.getPlugin().getLogger().info(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() }));
}
}else {
//The player is not currently jailed
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
}
return true;
}
}

View File

@ -32,7 +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.' forceunjailed: '&c%0% 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.'