use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class PlotClaim method residentUnclaim.
private boolean residentUnclaim(WorldCoord worldCoord) throws TownyException {
try {
TownBlock townBlock = worldCoord.getTownBlock();
townBlock.setResident(null);
townBlock.setPlotPrice(townBlock.getTown().getPlotTypePrice(townBlock.getType()));
// Set the plot permissions to mirror the towns.
townBlock.setType(townBlock.getType());
TownyUniverse.getDataSource().saveTownBlock(townBlock);
plugin.updateCache(worldCoord);
} catch (NotRegisteredException e) {
throw new TownyException(TownySettings.getLangString("msg_not_own_place"));
}
return true;
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class AreaSelectionUtil method selectWorldCoordAreaCircle.
public static List<WorldCoord> selectWorldCoordAreaCircle(TownBlockOwner owner, WorldCoord pos, String[] args) throws TownyException {
List<WorldCoord> out = new ArrayList<WorldCoord>();
if (pos.getTownyWorld().isClaimable()) {
if (args.length > 0) {
int r = 0, available = 0;
if (owner instanceof Town) {
Town town = (Town) owner;
available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
} else if (owner instanceof Resident) {
available = TownySettings.getMaxResidentPlots((Resident) owner);
}
if (args[0].equalsIgnoreCase("auto")) {
if (// Since: 0 - ceil(Pi * 0^2) >= 0 is a true statement.
available > 0)
while (available - Math.ceil(Math.PI * r * r) >= 0) r += 1;
} else {
try {
r = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
}
}
if (r > 1000)
r = 1000;
for (int z = -r; z <= r; z++) for (int x = -r; x <= r; x++) if ((x * x + z * z <= r * r) && (out.size() < available))
out.add(new WorldCoord(pos.getWorldName(), pos.getX() + x, pos.getZ() + z));
} else {
throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
}
}
return out;
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class AreaSelectionUtil method selectWorldCoordAreaRect.
public static List<WorldCoord> selectWorldCoordAreaRect(TownBlockOwner owner, WorldCoord pos, String[] args) throws TownyException {
List<WorldCoord> out = new ArrayList<WorldCoord>();
if (pos.getTownyWorld().isClaimable()) {
if (args.length > 0) {
int r = 0, available = 1000;
if (owner instanceof Town) {
Town town = (Town) owner;
available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
} else if (owner instanceof Resident) {
available = TownySettings.getMaxResidentPlots((Resident) owner);
}
if (args[0].equalsIgnoreCase("auto")) {
while (available - Math.pow((r + 1) * 2 - 1, 2) >= 0) r += 1;
} else {
try {
r = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
}
}
if (r > 1000)
r = 1000;
for (int z = -r; z <= r; z++) for (int x = -r; x <= r; x++) if (out.size() < available)
out.add(new WorldCoord(pos.getWorldName(), pos.getX() + x, pos.getZ() + z));
} else {
throw new TownyException(TownySettings.getLangString("msg_err_invalid_radius"));
}
}
return out;
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class TownyUniverse method getOnlineResidents.
public static List<Resident> getOnlineResidents(Player player, String[] names) {
List<Resident> invited = new ArrayList<Resident>();
for (String name : names) {
List<Player> matches = BukkitTools.matchPlayer(name);
if (matches.size() > 1) {
String line = "Multiple players selected";
for (Player p : matches) line += ", " + p.getName();
TownyMessaging.sendErrorMsg(player, line);
} else if (matches.size() == 1)
try {
Resident target = getDataSource().getResident(matches.get(0).getName());
invited.add(target);
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
}
}
return invited;
}
use of com.palmergames.bukkit.towny.exceptions.TownyException in project Towny by ElgarL.
the class TownyUniverse method getTownSpawnLocation.
public Location getTownSpawnLocation(Player player) throws TownyException {
try {
Resident resident = getDataSource().getResident(player.getName());
Town town = resident.getTown();
return town.getSpawn();
} catch (TownyException x) {
throw new TownyException("Unable to get spawn location");
}
}
Aggregations