First attempt at working on the transferring of prisoners

This commit is contained in:
graywolf336
2014-02-04 13:30:12 -06:00
parent d0e41ed908
commit d0312afc66
14 changed files with 332 additions and 6 deletions

View File

@ -27,6 +27,7 @@ import com.graywolf336.jail.command.jcommands.RemoveCell;
import com.graywolf336.jail.command.jcommands.Stop;
import com.graywolf336.jail.command.jcommands.TeleIn;
import com.graywolf336.jail.command.jcommands.TeleOut;
import com.graywolf336.jail.command.jcommands.Transfer;
import com.graywolf336.jail.command.jcommands.Version;
import com.graywolf336.jail.command.subcommands.JailCellCreateCommand;
import com.graywolf336.jail.command.subcommands.JailCheckCommand;
@ -42,6 +43,7 @@ import com.graywolf336.jail.command.subcommands.JailRemoveCellCommand;
import com.graywolf336.jail.command.subcommands.JailStopCommand;
import com.graywolf336.jail.command.subcommands.JailTeleInCommand;
import com.graywolf336.jail.command.subcommands.JailTeleOutCommand;
import com.graywolf336.jail.command.subcommands.JailTransferCommand;
import com.graywolf336.jail.command.subcommands.JailVersionCommand;
import com.graywolf336.jail.enums.LangString;
@ -197,6 +199,7 @@ public class JailHandler {
load(JailStopCommand.class);
load(JailTeleInCommand.class);
load(JailTeleOutCommand.class);
load(JailTransferCommand.class);
load(JailVersionCommand.class);
//Puts the commands in the HashMap
@ -224,6 +227,8 @@ public class JailHandler {
addCmds.put("teleportin", new TeleIn());
addCmds.put("teleout", new TeleOut());
addCmds.put("teleportout", new TeleOut());
addCmds.put("transfer", new Transfer());
addCmds.put("trans", new Transfer());
addCmds.put("version", new Version());
addCmds.put("ver", new Version());
addCmds.put("v", new Version());

View File

@ -1,4 +1,4 @@
package com.graywolf336.jail.command.jcommands;
package com.graywolf336.jail.command.commands.params;
import java.util.ArrayList;
import java.util.List;

View File

@ -0,0 +1,45 @@
package com.graywolf336.jail.command.commands.params;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.Parameter;
public class Transferring {
@Parameter
private List<String> parameters = new ArrayList<String>();
@Parameter(names = { "-player", "-p", "-prisoner" }, description = "The name of the player we are jailing.")
private String player = "";
@Parameter(names = { "-jail", "-j", "-prison" }, description = "The jail we are sending the player to.")
private String jail = "";
@Parameter(names = { "-cell", "-c"}, description = "The cell in the jail we are sending them to.")
private String cell = "";
/** Returns the parameters. */
public List<String> parameters() {
return parameters;
}
/** Returns the player parameter. */
public String player() {
return player;
}
/** Returns the jail parameter. */
public String jail() {
return jail;
}
/** Sets the jail parameter. */
public void setJail(String jail) {
this.jail = jail;
}
/** Returns the cell parameter. */
public String cell() {
return cell;
}
}

View File

@ -0,0 +1,13 @@
package com.graywolf336.jail.command.jcommands;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
@Parameters(commandDescription = "Transfers a player to another jail.")
public class Transfer {
@Parameter
private List<String> parameters = new ArrayList<String>();
}

View File

@ -17,7 +17,7 @@ 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.command.jcommands.Jailing;
import com.graywolf336.jail.command.commands.params.Jailing;
import com.graywolf336.jail.enums.LangString;
import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
@ -63,6 +63,14 @@ public class JailCommand implements Command {
return true;
}
//Check if they've actually given us a player to jail
if(params.player().isEmpty()) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.JAILING));
return true;
}else {
jm.getPlugin().debug("We are getting ready to handle jailing: " + params.jail());
}
//Check if the given player is already jailed or not
if(jm.isPlayerJailed(params.player())) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED));

View File

@ -0,0 +1,101 @@
package com.graywolf336.jail.command.subcommands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
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;
import com.graywolf336.jail.command.commands.params.Transferring;
import com.graywolf336.jail.enums.LangString;
@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;
}
//Parse the command
Transferring params = new Transferring();
try {
new JCommander(params, args);
}catch(ParameterException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
return true;
}
//Verify they gave us a player and if so check if they're jailed
if(params.player().isEmpty()) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING));
return true;
}else if(!jm.isPlayerJailed(params.player())) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.player()));
return true;
}
jm.getPlugin().debug("Checking everything before we transfer: " + params.player());
//If they didn't provide a jail, tell them we need one
if(params.jail().isEmpty()) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAJAIL, LangString.TRANSFERRING));
return true;
}else {
//Check if the jail they did provide exists
if(jm.getJail(params.jail()) == null) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.jail()));
return true;
}
}
Jail target = jm.getJail(params.jail());
Cell targetCell = null;
//Check if they provided a cell and if so does it exist
if(!params.cell().isEmpty()) {
if(target.getCell(params.cell()) == null) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, params.cell()));
return true;
}else {
//Store the cell for easy of access and also check if it already is full
targetCell = target.getCell(params.cell());
if(targetCell.hasPrisoner()) {
//If the cell has a prisoner, don't allow jailing them to that particular cell
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.cell()));
//But suggest the first empty cell we find
Cell suggestedCell = jm.getJail(params.jail()).getFirstEmptyCell();
if(suggestedCell != null) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.jail(), suggestedCell.getName() }));
}else {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.jail()));
}
return true;
}
}
}
jm.getPlugin().debug("Sending the transferring off, jail and cell check all came out clean.");
//Start the transferring of the prisoner
jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.player()),
jm.getJailPlayerIsIn(params.player()).getCellPrisonerIsIn(params.player()),
target, targetCell, jm.getPrisoner(params.player()));
return true;
}
}