From 4ac89455b037ce4cf76aac96311015ee1b522632 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Thu, 23 Jan 2014 13:07:26 -0600 Subject: [PATCH] Add the JailClearCommand back, this time releasing all the prisoners. --- .../jail/command/CommandHandler.java | 2 + .../command/commands/JailClearCommand.java | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/main/java/com/graywolf336/jail/command/commands/JailClearCommand.java diff --git a/src/main/java/com/graywolf336/jail/command/CommandHandler.java b/src/main/java/com/graywolf336/jail/command/CommandHandler.java index 903f52d..1729f6a 100644 --- a/src/main/java/com/graywolf336/jail/command/CommandHandler.java +++ b/src/main/java/com/graywolf336/jail/command/CommandHandler.java @@ -13,6 +13,7 @@ import com.graywolf336.jail.JailManager; import com.graywolf336.jail.command.commands.CellCreateCommand; import com.graywolf336.jail.command.commands.HandCuffCommand; import com.graywolf336.jail.command.commands.JailCheckCommand; +import com.graywolf336.jail.command.commands.JailClearCommand; import com.graywolf336.jail.command.commands.JailClearForceCommand; import com.graywolf336.jail.command.commands.JailCommand; import com.graywolf336.jail.command.commands.JailCreateCommand; @@ -149,6 +150,7 @@ public class CommandHandler { load(CellCreateCommand.class); load(HandCuffCommand.class); load(JailCheckCommand.class); + load(JailClearCommand.class); load(JailClearForceCommand.class); load(JailCommand.class); load(JailCreateCommand.class); diff --git a/src/main/java/com/graywolf336/jail/command/commands/JailClearCommand.java b/src/main/java/com/graywolf336/jail/command/commands/JailClearCommand.java new file mode 100644 index 0000000..93f85c8 --- /dev/null +++ b/src/main/java/com/graywolf336/jail/command/commands/JailClearCommand.java @@ -0,0 +1,53 @@ +package com.graywolf336.jail.command.commands; + +import org.bukkit.command.CommandSender; + +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; + +@CommandInfo( + maxArgs = 1, + minimumArgs = 0, + needsPlayer = false, + pattern = "jailclear|jclear", + permission = "jail.command.jailclear", + usage = "/jailclear (Jail name)" + ) +public class JailClearCommand implements Command { + + // If Jail is specified unjails all the prisoners from that Jail (new feature) otherwise it unjails all the prisoners from all the jails + public boolean execute(JailManager jm, CommandSender sender, String... args) { + if(args.length == 1) { + Jail j = jm.getJail(args[0]); + + if(j != null) { + for(Prisoner p : j.getAllPrisoners()) { + jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayerExact(p.getName()), p); + } + + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSCLEARED, j.getName())); + }else { + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[0])); + } + }else { + if(jm.getJails().size() == 0) { + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS)); + }else { + for(Jail j : jm.getJails()) { + for(Prisoner p : j.getAllPrisoners()) { + jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayerExact(p.getName()), p); + } + } + + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSCLEARED, + jm.getPlugin().getJailIO().getLanguageString(LangString.ALLJAILS))); + } + } + + return true; + } +}