use of com.palmergames.bukkit.towny.object.SpawnPointLocation in project Towny by TownyAdvanced.
the class PlotCommand method parsePlotJailCell.
private void parsePlotJailCell(Player player, TownBlock townBlock, String[] args) {
if (args.length == 0 || args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help"))
HelpMenu.PLOT_JAILCELL.send(player);
try {
if (!TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_COMMAND_PLOT_JAILCELL.getNode()))
throw new TownyException("msg_err_command_disable");
// Fail if the resident isn't registered. (Very unlikely.)
Resident resident = TownyAPI.getInstance().getResident(player.getUniqueId());
if (resident == null)
return;
// Fail if we're not in a jail plot.
if (townBlock == null || !townBlock.isJail())
throw new TownyException("msg_err_location_is_not_within_a_jail_plot");
// Test we are allowed to work on this plot, and able to set a jail spawn.
// If this fails it will trigger a TownyException.
plotTestOwner(resident, townBlock);
Jail jail = townBlock.getJail();
if (args.length > 0) {
if (args[0].equalsIgnoreCase("add")) {
jail.addJailCell(player.getLocation());
TownyMessaging.sendMsg(player, Translatable.of("msg_jail_cell_set"));
jail.save();
} else if (args[0].equalsIgnoreCase("remove")) {
if (!jail.hasCells())
throw new TownyException(Translatable.of("msg_err_this_jail_has_no_cells"));
if (jail.getCellMap().size() == 1)
throw new TownyException(Translatable.of("msg_err_you_cannot_remove_the_last_cell"));
SpawnPointLocation cellLoc = SpawnPointLocation.parseSpawnPointLocation(player.getLocation());
if (!jail.hasJailCell(cellLoc))
throw new TownyException(Translatable.of("msg_err_no_cell_found_at_this_location"));
jail.removeJailCell(player.getLocation());
TownyMessaging.sendMsg(player, Translatable.of("msg_jail_cell_removed"));
jail.save();
} else {
HelpMenu.PLOT_JAILCELL.send(player);
}
}
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage(player));
}
}
Aggregations