Finish up the confirmations for #3.
This commit is contained in:
parent
82a40c5d8e
commit
52456edc6b
@ -2,11 +2,13 @@ package com.graywolf336.jail;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.beans.Cell;
|
||||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||||
import com.graywolf336.jail.beans.CreationPlayer;
|
import com.graywolf336.jail.beans.CreationPlayer;
|
||||||
import com.graywolf336.jail.beans.Jail;
|
import com.graywolf336.jail.beans.Jail;
|
||||||
@ -296,6 +298,101 @@ public class JailManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a jail's cell, checking everything is setup right for it to be deleted.
|
||||||
|
*
|
||||||
|
* @param jail Name of the jail to delete a cell in.
|
||||||
|
* @param cell Name of the cell to delete.
|
||||||
|
* @return The resulting message to be sent to the caller of this method.
|
||||||
|
*/
|
||||||
|
public String deleteJailCell(String jail, String cell) {
|
||||||
|
//Check if the jail name provided is a valid jail
|
||||||
|
if(isValidJail(jail)) {
|
||||||
|
Jail j = getJail(jail);
|
||||||
|
|
||||||
|
//check if the cell is a valid cell
|
||||||
|
if(j.isValidCell(cell)) {
|
||||||
|
if(j.getCell(cell).hasPrisoner()) {
|
||||||
|
//The cell has a prisoner, so tell them to first transfer the prisoner
|
||||||
|
//or release the prisoner
|
||||||
|
return getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVALUNSUCCESSFUL, new String[] { cell, jail });
|
||||||
|
}else {
|
||||||
|
j.removeCell(cell);
|
||||||
|
return getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVED, new String[] { cell, jail });
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//No cell found by the provided name in the stated jail
|
||||||
|
return getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { cell, jail });
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//No jail found by the provided name
|
||||||
|
return getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, jail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all the cells in a jail, returns a list of Strings.
|
||||||
|
*
|
||||||
|
* @param jail The name of the jail to delete all the jails in.
|
||||||
|
* @return An array of strings of messages to send.
|
||||||
|
*/
|
||||||
|
public String[] deleteAllJailCells(String jail) {
|
||||||
|
LinkedList<String> msgs = new LinkedList<String>();
|
||||||
|
|
||||||
|
//Check if the jail name provided is a valid jail
|
||||||
|
if(isValidJail(jail)) {
|
||||||
|
Jail j = getJail(jail);
|
||||||
|
|
||||||
|
if(j.getCellCount() == 0) {
|
||||||
|
//There are no cells in this jail, thus we can't delete them.
|
||||||
|
msgs.add(getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, j.getName()));
|
||||||
|
}else {
|
||||||
|
//Keep a local copy of the hashset so that we don't get any CMEs.
|
||||||
|
HashSet<Cell> cells = new HashSet<Cell>(j.getCells());
|
||||||
|
|
||||||
|
for(Cell c : cells) {
|
||||||
|
if(c.hasPrisoner()) {
|
||||||
|
//The cell has a prisoner, so tell them to first transfer the prisoner
|
||||||
|
//or release the prisoner
|
||||||
|
msgs.add(getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVALUNSUCCESSFUL, new String[] { c.getName(), j.getName() }));
|
||||||
|
}else {
|
||||||
|
j.removeCell(c.getName());
|
||||||
|
msgs.add(getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVED, new String[] { c.getName(), j.getName() }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//No jail found by the provided name
|
||||||
|
msgs.add(getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, jail));
|
||||||
|
}
|
||||||
|
|
||||||
|
return msgs.toArray(new String[msgs.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a jail while doing some checks to verify it can be deleted.
|
||||||
|
*
|
||||||
|
* @param jail The name of the jail to delete.
|
||||||
|
* @return The resulting message to be sent to the caller of this method.
|
||||||
|
*/
|
||||||
|
public String deleteJail(String jail) {
|
||||||
|
//Check if the jail name provided is a valid jail
|
||||||
|
if(isValidJail(jail)) {
|
||||||
|
//check if the jail doesn't contain prisoners
|
||||||
|
if(getJail(jail).getAllPrisoners().size() == 0) {
|
||||||
|
//There are no prisoners, so we can delete it
|
||||||
|
removeJail(jail);
|
||||||
|
return getPlugin().getJailIO().getLanguageString(LangString.JAILREMOVED, jail);
|
||||||
|
}else {
|
||||||
|
//The jail has prisoners, they need to release them first
|
||||||
|
return getPlugin().getJailIO().getLanguageString(LangString.JAILREMOVALUNSUCCESSFUL, jail);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//No jail found by the provided name
|
||||||
|
return getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, jail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the player is creating a jail or a cell.
|
* Returns whether or not the player is creating a jail or a cell.
|
||||||
*
|
*
|
||||||
|
@ -44,6 +44,36 @@ public class JailConfirmCommand implements Command{
|
|||||||
sender.sendMessage(msg2);
|
sender.sendMessage(msg2);
|
||||||
jm.removeConfirming(sender.getName());
|
jm.removeConfirming(sender.getName());
|
||||||
break;
|
break;
|
||||||
|
case DELETECELL:
|
||||||
|
//Copy the original arguments for easy access
|
||||||
|
String[] cArgs3 = jm.getOriginalArgs(sender.getName());
|
||||||
|
//delete a cell from a jail with the given arguments
|
||||||
|
String msg3 = jm.deleteJailCell(cArgs3[1], cArgs3[2]);
|
||||||
|
//Send the message we got back
|
||||||
|
sender.sendMessage(msg3);
|
||||||
|
jm.removeConfirming(sender.getName());
|
||||||
|
break;
|
||||||
|
case DELETECELLS:
|
||||||
|
//Copy the original arguments for easy access
|
||||||
|
String[] cArgs4 = jm.getOriginalArgs(sender.getName());
|
||||||
|
//delete a cell from a jail with the given arguments
|
||||||
|
String[] msgs4 = jm.deleteAllJailCells(cArgs4[1]);
|
||||||
|
//Send the messages we got back
|
||||||
|
for(String s : msgs4) {
|
||||||
|
sender.sendMessage(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
jm.removeConfirming(sender.getName());
|
||||||
|
break;
|
||||||
|
case DELETE:
|
||||||
|
//Copy the original arguments for easy access
|
||||||
|
String[] cArgs5 = jm.getOriginalArgs(sender.getName());
|
||||||
|
//delete a cell from a jail with the given arguments
|
||||||
|
String msg5 = jm.deleteJail(cArgs5[1]);
|
||||||
|
//Send the message we got back
|
||||||
|
sender.sendMessage(msg5);
|
||||||
|
jm.removeConfirming(sender.getName());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHING));
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHING));
|
||||||
jm.removeConfirming(sender.getName());
|
jm.removeConfirming(sender.getName());
|
||||||
|
@ -3,9 +3,10 @@ package com.graywolf336.jail.command.subcommands;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.graywolf336.jail.JailManager;
|
import com.graywolf336.jail.JailManager;
|
||||||
import com.graywolf336.jail.beans.Jail;
|
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||||
import com.graywolf336.jail.command.Command;
|
import com.graywolf336.jail.command.Command;
|
||||||
import com.graywolf336.jail.command.CommandInfo;
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
import com.graywolf336.jail.enums.Confirmation;
|
||||||
import com.graywolf336.jail.enums.LangString;
|
import com.graywolf336.jail.enums.LangString;
|
||||||
|
|
||||||
@CommandInfo(
|
@CommandInfo(
|
||||||
@ -18,27 +19,11 @@ import com.graywolf336.jail.enums.LangString;
|
|||||||
)
|
)
|
||||||
public class JailDeleteCellCommand implements Command {
|
public class JailDeleteCellCommand implements Command {
|
||||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||||
//Check if the jail name provided is a valid jail
|
if(jm.isConfirming(sender.getName())) {
|
||||||
if(jm.isValidJail(args[1])) {
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||||
Jail j = jm.getJail(args[1]);
|
|
||||||
|
|
||||||
//check if the cell is a valid cell
|
|
||||||
if(j.isValidCell(args[2])) {
|
|
||||||
if(j.getCell(args[2]).hasPrisoner()) {
|
|
||||||
//The cell has a prisoner, so tell them to first transfer the prisoner
|
|
||||||
//or release the prisoner
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVALUNSUCCESSFUL, new String[] { args[2], args[1] }));
|
|
||||||
}else {
|
}else {
|
||||||
j.removeCell(args[2]);
|
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELL));
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVED, new String[] { args[2], args[1] }));
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||||
}
|
|
||||||
}else {
|
|
||||||
//No cell found by the provided name in the stated jail
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { args[2], args[1] }));
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
//No jail found by the provided name
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package com.graywolf336.jail.command.subcommands;
|
package com.graywolf336.jail.command.subcommands;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.graywolf336.jail.JailManager;
|
import com.graywolf336.jail.JailManager;
|
||||||
import com.graywolf336.jail.beans.Cell;
|
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||||
import com.graywolf336.jail.beans.Jail;
|
|
||||||
import com.graywolf336.jail.command.Command;
|
import com.graywolf336.jail.command.Command;
|
||||||
import com.graywolf336.jail.command.CommandInfo;
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
import com.graywolf336.jail.enums.Confirmation;
|
||||||
import com.graywolf336.jail.enums.LangString;
|
import com.graywolf336.jail.enums.LangString;
|
||||||
|
|
||||||
@CommandInfo(
|
@CommandInfo(
|
||||||
@ -21,31 +19,11 @@ import com.graywolf336.jail.enums.LangString;
|
|||||||
)
|
)
|
||||||
public class JailDeleteCellsCommand implements Command {
|
public class JailDeleteCellsCommand implements Command {
|
||||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||||
//Check if the jail name provided is a valid jail
|
if(jm.isConfirming(sender.getName())) {
|
||||||
if(jm.isValidJail(args[1])) {
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||||
Jail j = jm.getJail(args[1]);
|
|
||||||
|
|
||||||
if(j.getCellCount() == 0) {
|
|
||||||
//There are no cells in this jail, thus we can't delete them.
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, args[1]));
|
|
||||||
}else {
|
}else {
|
||||||
//Keep a local copy of the hashset so that we don't get any CMEs.
|
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELLS));
|
||||||
HashSet<Cell> cells = new HashSet<Cell>(j.getCells());
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||||
|
|
||||||
for(Cell c : cells) {
|
|
||||||
if(c.hasPrisoner()) {
|
|
||||||
//The cell has a prisoner, so tell them to first transfer the prisoner
|
|
||||||
//or release the prisoner
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVALUNSUCCESSFUL, new String[] { c.getName(), args[1] }));
|
|
||||||
}else {
|
|
||||||
j.removeCell(c.getName());
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVED, new String[] { args[2], args[1] }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
//No jail found by the provided name
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,8 +3,10 @@ package com.graywolf336.jail.command.subcommands;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.graywolf336.jail.JailManager;
|
import com.graywolf336.jail.JailManager;
|
||||||
|
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||||
import com.graywolf336.jail.command.Command;
|
import com.graywolf336.jail.command.Command;
|
||||||
import com.graywolf336.jail.command.CommandInfo;
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
import com.graywolf336.jail.enums.Confirmation;
|
||||||
import com.graywolf336.jail.enums.LangString;
|
import com.graywolf336.jail.enums.LangString;
|
||||||
|
|
||||||
@CommandInfo(
|
@CommandInfo(
|
||||||
@ -17,20 +19,11 @@ import com.graywolf336.jail.enums.LangString;
|
|||||||
)
|
)
|
||||||
public class JailDeleteCommand implements Command {
|
public class JailDeleteCommand implements Command {
|
||||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||||
//Check if the jail name provided is a valid jail
|
if(jm.isConfirming(sender.getName())) {
|
||||||
if(jm.isValidJail(args[1])) {
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||||
//check if the jail doesn't contain prisoners
|
|
||||||
if(jm.getJail(args[1]).getAllPrisoners().size() == 0) {
|
|
||||||
//There are no prisoners, so we can delete it
|
|
||||||
jm.removeJail(args[1]);
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILREMOVED, args[1]));
|
|
||||||
}else {
|
}else {
|
||||||
//The jail has prisoners, they need to release them first
|
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETE));
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILREMOVALUNSUCCESSFUL, args[1]));
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||||
}
|
|
||||||
}else {
|
|
||||||
//No jail found by the provided name
|
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user