use of com.palmergames.bukkit.towny.object.WorldCoord 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.object.WorldCoord 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.object.WorldCoord in project Towny by ElgarL.
the class CombatUtil method isPvPPlot.
/**
* Return true if both attacker and defender are in Arena Plots.
*
* @param attacker
* @param defender
* @return true if both players in an Arena plot.
*/
public static boolean isPvPPlot(Player attacker, Player defender) {
if ((attacker != null) && (defender != null)) {
TownBlock attackerTB, defenderTB;
try {
attackerTB = new WorldCoord(attacker.getWorld().getName(), Coord.parseCoord(attacker)).getTownBlock();
defenderTB = new WorldCoord(defender.getWorld().getName(), Coord.parseCoord(defender)).getTownBlock();
if (defenderTB.getType().equals(TownBlockType.ARENA) && attackerTB.getType().equals(TownBlockType.ARENA))
return true;
} catch (NotRegisteredException e) {
// Not a Town owned Plot
}
}
return false;
}
use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerBedEnter.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (!TownySettings.getBedUse())
return;
boolean isOwner = false;
boolean isInnPlot = false;
try {
Resident resident = TownyUniverse.getDataSource().getResident(event.getPlayer().getName());
WorldCoord worldCoord = new WorldCoord(event.getPlayer().getWorld().getName(), Coord.parseCoord(event.getBed().getLocation()));
TownBlock townblock = worldCoord.getTownBlock();
isOwner = townblock.isOwner(resident);
isInnPlot = townblock.getType() == TownBlockType.INN;
if (resident.hasNation() && townblock.getTown().hasNation()) {
Nation residentNation = resident.getTown().getNation();
Nation townblockNation = townblock.getTown().getNation();
if (townblockNation.hasEnemy(residentNation)) {
event.setCancelled(true);
TownyMessaging.sendErrorMsg(event.getPlayer(), "You cannot sleep in an enemy's Inn.");
return;
}
}
} catch (NotRegisteredException e) {
// Wilderness as it error'd getting a townblock.
}
if (!isOwner && !isInnPlot) {
event.setCancelled(true);
TownyMessaging.sendErrorMsg(event.getPlayer(), "You do not own the land this bed occupies and it is not an Inn plot.");
}
}
use of com.palmergames.bukkit.towny.object.WorldCoord in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerMove.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
/*
* Abort if we havn't really moved
*/
if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ() && event.getFrom().getBlockY() == event.getTo().getBlockY()) {
return;
}
Player player = event.getPlayer();
Location to = event.getTo();
Location from;
PlayerCache cache = plugin.getCache(player);
try {
from = cache.getLastLocation();
} catch (NullPointerException e) {
from = event.getFrom();
}
// Prevent fly/double jump cheats
if (!(event instanceof PlayerTeleportEvent)) {
if (TownySettings.isUsingCheatProtection() && (player.getGameMode() != GameMode.CREATIVE) && !TownyUniverse.getPermissionSource().has(player, PermissionNodes.CHEAT_BYPASS.getNode())) {
try {
if (TownyUniverse.getDataSource().getWorld(player.getWorld().getName()).isUsingTowny())
if ((from.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) && (player.getFallDistance() == 0) && (player.getVelocity().getY() <= -0.6) && (player.getLocation().getY() > 0)) {
// plugin.sendErrorMsg(player, "Cheat Detected!");
Location blockLocation = from;
// find the first non air block below us
while ((blockLocation.getBlock().getType() == Material.AIR) && (blockLocation.getY() > 0)) blockLocation.setY(blockLocation.getY() - 1);
// set to 1 block up so we are not sunk in the
// ground
blockLocation.setY(blockLocation.getY() + 1);
// Update the cache for this location (same
// WorldCoord).
cache.setLastLocation(blockLocation);
player.teleport(blockLocation);
return;
}
} catch (NotRegisteredException e1) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
return;
}
}
}
try {
TownyWorld fromWorld = TownyUniverse.getDataSource().getWorld(from.getWorld().getName());
WorldCoord fromCoord = new WorldCoord(fromWorld.getName(), Coord.parseCoord(from));
TownyWorld toWorld = TownyUniverse.getDataSource().getWorld(to.getWorld().getName());
WorldCoord toCoord = new WorldCoord(toWorld.getName(), Coord.parseCoord(to));
if (!fromCoord.equals(toCoord))
onPlayerMoveChunk(player, fromCoord, toCoord, from, to, event);
else {
// plugin.sendDebugMsg(" From: " + fromCoord);
// plugin.sendDebugMsg(" To: " + toCoord);
// plugin.sendDebugMsg(" " + from.toString());
// plugin.sendDebugMsg(" " + to.toString());
}
} catch (NotRegisteredException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
// Update the cached players current location
cache.setLastLocation(to);
// plugin.updateCache(player);
// plugin.sendDebugMsg("onBlockMove: " + player.getName() + ": ");
// plugin.sendDebugMsg(" " + from.toString());
// plugin.sendDebugMsg(" " + to.toString());
}
Aggregations