Remove all reference to jcommands and use jewelcli.
This commit also cleans up the jail command to be quicker as the old way I was doing it just didn't work nor was it good to go for production. This method also utilizes the CommandInfo's pattern to match subcommands, like it was meant to be used for. Completely untested.
This commit is contained in:
@@ -3,15 +3,15 @@ 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.command.commands.jewels.Transfer;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 6,
|
||||
@@ -29,59 +29,59 @@ public class JailTransferCommand implements Command {
|
||||
}
|
||||
|
||||
//Parse the command
|
||||
Transferring params = new Transferring();
|
||||
Transfer params = null;
|
||||
|
||||
try {
|
||||
new JCommander(params, args);
|
||||
}catch(ParameterException e) {
|
||||
params = CliFactory.parseArguments(Transfer.class, args);
|
||||
}catch(ArgumentValidationException 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()) {
|
||||
if(params.getPlayer().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()));
|
||||
}else if(!jm.isPlayerJailed(params.getPlayer())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Checking everything before we transfer: " + params.player());
|
||||
jm.getPlugin().debug("Checking everything before we transfer: " + params.getPlayer());
|
||||
|
||||
//If they didn't provide a jail, tell them we need one
|
||||
if(params.jail().isEmpty()) {
|
||||
if(params.getJail().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()));
|
||||
if(jm.getJail(params.getJail()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Jail target = jm.getJail(params.jail());
|
||||
Jail target = jm.getJail(params.getJail());
|
||||
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()));
|
||||
if(!params.getCell().isEmpty()) {
|
||||
if(target.getCell(params.getCell()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, params.getCell()));
|
||||
return true;
|
||||
}else {
|
||||
//Store the cell for easy of access and also check if it already is full
|
||||
targetCell = target.getCell(params.cell());
|
||||
targetCell = target.getCell(params.getCell());
|
||||
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()));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
|
||||
//But suggest the first empty cell we find
|
||||
Cell suggestedCell = jm.getJail(params.jail()).getFirstEmptyCell();
|
||||
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.jail(), suggestedCell.getName() }));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getCell(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.jail()));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getCell()));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -92,9 +92,9 @@ public class JailTransferCommand implements Command {
|
||||
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()));
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.getPlayer()),
|
||||
jm.getJailPlayerIsIn(params.getPlayer()).getCellPrisonerIsIn(params.getPlayer()),
|
||||
target, targetCell, jm.getPrisoner(params.getPlayer()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user