2014-02-04 20:30:12 +01:00
|
|
|
package com.graywolf336.jail.command.subcommands;
|
|
|
|
|
2014-02-12 20:27:22 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-02-04 20:30:12 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
|
|
|
|
import com.graywolf336.jail.JailManager;
|
|
|
|
import com.graywolf336.jail.beans.Cell;
|
|
|
|
import com.graywolf336.jail.beans.Jail;
|
|
|
|
import com.graywolf336.jail.command.Command;
|
|
|
|
import com.graywolf336.jail.command.CommandInfo;
|
2014-02-12 03:34:35 +01:00
|
|
|
import com.graywolf336.jail.command.commands.jewels.Transfer;
|
2014-02-04 20:30:12 +01:00
|
|
|
import com.graywolf336.jail.enums.LangString;
|
2014-02-12 03:34:35 +01:00
|
|
|
import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
|
|
|
import com.lexicalscope.jewel.cli.CliFactory;
|
2014-02-04 20:30:12 +01:00
|
|
|
|
|
|
|
@CommandInfo(
|
|
|
|
maxArgs = 6,
|
|
|
|
minimumArgs = 2,
|
|
|
|
needsPlayer = false,
|
|
|
|
pattern = "transfer|trans",
|
|
|
|
permission = "jail.command.jailtransfer",
|
|
|
|
usage = "/jail transfer -p player -j jail -c cell"
|
|
|
|
)
|
|
|
|
public class JailTransferCommand implements Command {
|
|
|
|
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
|
|
|
if(jm.getJails().isEmpty()) {
|
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:27:22 +01:00
|
|
|
//Convert to a List<String> so we can edit the list
|
|
|
|
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
|
|
|
//remove the first argument of "transfer"
|
|
|
|
arguments.remove(0);
|
|
|
|
|
2014-02-04 20:30:12 +01:00
|
|
|
//Parse the command
|
2014-02-12 03:34:35 +01:00
|
|
|
Transfer params = null;
|
2014-02-04 20:30:12 +01:00
|
|
|
|
|
|
|
try {
|
2014-02-12 20:27:22 +01:00
|
|
|
params = CliFactory.parseArguments(Transfer.class, arguments.toArray(new String[arguments.size()]));
|
2014-02-12 03:34:35 +01:00
|
|
|
}catch(ArgumentValidationException e) {
|
2014-02-04 20:30:12 +01:00
|
|
|
sender.sendMessage(ChatColor.RED + e.getMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Verify they gave us a player and if so check if they're jailed
|
2014-02-12 20:14:32 +01:00
|
|
|
if(params.getPlayer() == null) {
|
2014-02-04 20:30:12 +01:00
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING));
|
|
|
|
return true;
|
2014-02-12 03:34:35 +01:00
|
|
|
}else if(!jm.isPlayerJailed(params.getPlayer())) {
|
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.getPlayer()));
|
2014-02-04 20:30:12 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-12 03:34:35 +01:00
|
|
|
jm.getPlugin().debug("Checking everything before we transfer: " + params.getPlayer());
|
2014-02-04 20:30:12 +01:00
|
|
|
|
|
|
|
//If they didn't provide a jail, tell them we need one
|
2014-02-12 20:14:32 +01:00
|
|
|
if(params.getJail() == null) {
|
2014-02-04 20:30:12 +01:00
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAJAIL, LangString.TRANSFERRING));
|
|
|
|
return true;
|
|
|
|
}else {
|
|
|
|
//Check if the jail they did provide exists
|
2014-02-12 03:34:35 +01:00
|
|
|
if(jm.getJail(params.getJail()) == null) {
|
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
2014-02-04 20:30:12 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 03:34:35 +01:00
|
|
|
Jail target = jm.getJail(params.getJail());
|
2014-02-04 20:30:12 +01:00
|
|
|
Cell targetCell = null;
|
|
|
|
|
|
|
|
//Check if they provided a cell and if so does it exist
|
2014-02-12 20:14:32 +01:00
|
|
|
if(params.getCell() != null) {
|
2014-02-12 03:34:35 +01:00
|
|
|
if(target.getCell(params.getCell()) == null) {
|
2014-02-12 20:48:45 +01:00
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() }));
|
2014-02-04 20:30:12 +01:00
|
|
|
return true;
|
|
|
|
}else {
|
|
|
|
//Store the cell for easy of access and also check if it already is full
|
2014-02-12 03:34:35 +01:00
|
|
|
targetCell = target.getCell(params.getCell());
|
2014-02-04 20:30:12 +01:00
|
|
|
if(targetCell.hasPrisoner()) {
|
|
|
|
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
2014-02-12 03:34:35 +01:00
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
2014-02-04 20:30:12 +01:00
|
|
|
|
|
|
|
//But suggest the first empty cell we find
|
2014-02-12 03:34:35 +01:00
|
|
|
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
2014-02-04 20:30:12 +01:00
|
|
|
if(suggestedCell != null) {
|
2014-02-12 03:34:35 +01:00
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getCell(), suggestedCell.getName() }));
|
2014-02-04 20:30:12 +01:00
|
|
|
}else {
|
2014-02-12 03:34:35 +01:00
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getCell()));
|
2014-02-04 20:30:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jm.getPlugin().debug("Sending the transferring off, jail and cell check all came out clean.");
|
|
|
|
|
|
|
|
//Start the transferring of the prisoner
|
2014-02-12 03:34:35 +01:00
|
|
|
jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.getPlayer()),
|
|
|
|
jm.getJailPlayerIsIn(params.getPlayer()).getCellPrisonerIsIn(params.getPlayer()),
|
|
|
|
target, targetCell, jm.getPrisoner(params.getPlayer()));
|
2014-02-04 20:30:12 +01:00
|
|
|
|
2014-02-12 20:42:45 +01:00
|
|
|
//Send the messages to the sender, if no cell then say that but if cell send that as well
|
|
|
|
if(targetCell == null) {
|
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETENOCELL, new String[] { params.getPlayer(), target.getName() }));
|
|
|
|
}else {
|
|
|
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETECELL, new String[] { params.getPlayer(), target.getName(), targetCell.getName() }));
|
|
|
|
}
|
|
|
|
|
2014-02-04 20:30:12 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|