Add deletecell and deletecells.
The deletion of cells is very spammy, might have to change later on down the road.
This commit is contained in:
parent
3dc89a60c8
commit
94111955a4
@ -6,6 +6,7 @@ import java.util.HashSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -152,8 +153,26 @@ public class Jail {
|
||||
return this.cells.get(name);
|
||||
}
|
||||
|
||||
/** Checks if the given name is a valid cell. */
|
||||
public boolean isValidCell(String name) {
|
||||
return this.cells.get(name) != null;
|
||||
}
|
||||
|
||||
/** Removes the cell from the jail. */
|
||||
public void removeCell(String name) {
|
||||
//Clear the chest and reset the sign
|
||||
this.cells.get(name).getChest().getInventory().clear();
|
||||
|
||||
//For each sign, clear the lines on the sign
|
||||
for(SimpleLocation s : this.cells.get(name).getSigns()) {
|
||||
if(s.getLocation().getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) s.getLocation().getBlock();
|
||||
for(int i = 0; i < 4; i++) {
|
||||
sign.setLine(i, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.cells.remove(name);
|
||||
}
|
||||
|
||||
@ -188,6 +207,29 @@ public class Jail {
|
||||
return new HashSet<Cell>(this.cells.values());
|
||||
}
|
||||
|
||||
/** Gets the closest cell to the provided location, via the teleport in location of the cells. */
|
||||
public Cell getNearestCell(Location loc) {
|
||||
Cell cell = null;
|
||||
double distance = -1;
|
||||
|
||||
for(Cell c : getCells()) {
|
||||
//Check if the worlds are the same, if not we can't calculate anything
|
||||
if(c.getTeleport().getWorld().getName().equalsIgnoreCase(loc.getWorld().getName())) {
|
||||
//They are in the same world
|
||||
double dist = c.getTeleport().distance(loc);
|
||||
if (dist < distance || distance < 0) {
|
||||
cell = c;
|
||||
distance = dist;
|
||||
}
|
||||
}else {
|
||||
//If they aren't, return the first cell found.
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
/** Clears all the prisoners from this Jail. */
|
||||
public void clearPrisoners() {
|
||||
//Remove the prisoners from all the cells
|
||||
|
@ -16,6 +16,8 @@ import com.graywolf336.jail.command.subcommands.JailClearCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearForceCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailMuteCommand;
|
||||
@ -167,6 +169,8 @@ public class JailHandler {
|
||||
load(JailClearForceCommand.class);
|
||||
load(JailCommand.class);
|
||||
load(JailCreateCommand.class);
|
||||
load(JailDeleteCellCommand.class);
|
||||
load(JailDeleteCellsCommand.class);
|
||||
load(JailListCellsCommand.class);
|
||||
load(JailListCommand.class);
|
||||
load(JailMuteCommand.class);
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecell|dc",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecell <jail> <cell>"
|
||||
)
|
||||
public class JailDeleteCellCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
//Check if the jail name provided is a valid jail
|
||||
if(jm.isValidJail(args[1])) {
|
||||
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 {
|
||||
j.removeCell(args[2]);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVED, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}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;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
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;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecells|dcs",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecells <jail>"
|
||||
)
|
||||
public class JailDeleteCellsCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
//Check if the jail name provided is a valid jail
|
||||
if(jm.isValidJail(args[1])) {
|
||||
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 {
|
||||
//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
|
||||
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;
|
||||
}
|
||||
}
|
@ -106,6 +106,8 @@ public enum LangString {
|
||||
|
||||
/** Part message of any messages which require 'all the jails' or such. */
|
||||
ALLJAILS ("general"),
|
||||
/** The message sent to the sender whenever they try to remove a cell but was unsuccessful due to a prisoner. */
|
||||
CELLREMOVALUNSUCCESSFUL ("general"),
|
||||
/** The message sent whenever a cell is successfully removed. */
|
||||
CELLREMOVED ("general"),
|
||||
/** The simple word jailing to be put in other parts. */
|
||||
|
@ -9,6 +9,7 @@ language:
|
||||
moving: 'trying to escape'
|
||||
general:
|
||||
alljails: 'all the jails'
|
||||
cellremovalunsuccessful: '&cThe removal of cell %0% from jail %1% was unsuccessful because there is a prisoner in there still. Release or transfer before trying to remove the cell again.'
|
||||
cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'
|
||||
jailing: '&9jailing'
|
||||
jailremoved: '&9Jail %0% has been successfully removed.'
|
||||
|
Loading…
Reference in New Issue
Block a user