use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException 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());
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException 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.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyWorldListener method newWorld.
private void newWorld(String worldName) {
//String worldName = event.getWorld().getName();
try {
TownyUniverse.getDataSource().newWorld(worldName);
TownyWorld world = TownyUniverse.getDataSource().getWorld(worldName);
if (world == null)
TownyMessaging.sendErrorMsg("Could not create data for " + worldName);
else {
if (!TownyUniverse.getDataSource().loadWorld(world)) {
// First time world has been noticed
TownyUniverse.getDataSource().saveWorld(world);
}
}
} catch (AlreadyRegisteredException e) {
// Allready loaded
} catch (NotRegisteredException e) {
TownyMessaging.sendErrorMsg("Could not create data for " + worldName);
e.printStackTrace();
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class NationCommand method nationAlly.
public void nationAlly(Player player, Nation nation, List<Nation> allies, boolean add) {
ArrayList<Nation> remove = new ArrayList<Nation>();
for (Nation targetNation : allies) try {
if (add && !nation.getAllies().contains(targetNation)) {
if (!targetNation.hasEnemy(nation)) {
// We are not set as an enemy so we can set as ally.
nation.addAlly(targetNation);
TownyMessaging.sendNationMessage(targetNation, String.format(TownySettings.getLangString("msg_added_ally"), nation.getName()));
} else {
// We are set as an enemy so can't ally.
remove.add(targetNation);
TownyMessaging.sendNationMessage(nation, String.format(TownySettings.getLangString("msg_unable_ally_enemy"), targetNation.getName()));
}
} else if (nation.getAllies().contains(targetNation)) {
nation.removeAlly(targetNation);
TownyMessaging.sendNationMessage(targetNation, String.format(TownySettings.getLangString("msg_removed_ally"), nation.getName()));
// Remove any mirrored ally settings from the target nation
if (targetNation.hasAlly(nation))
nationAlly(player, targetNation, Arrays.asList(nation), false);
}
} catch (AlreadyRegisteredException e) {
remove.add(targetNation);
} catch (NotRegisteredException e) {
remove.add(targetNation);
}
for (Nation newAlly : remove) allies.remove(newAlly);
if (allies.size() > 0) {
String msg = "";
for (Nation newAlly : allies) msg += newAlly.getName() + ", ";
msg = msg.substring(0, msg.length() - 2);
if (add)
msg = String.format(TownySettings.getLangString("msg_allied_nations"), player.getName(), msg);
else
msg = String.format(TownySettings.getLangString("msg_broke_alliance"), player.getName(), msg);
TownyMessaging.sendNationMessage(nation, ChatTools.color(msg));
TownyUniverse.getDataSource().saveNations();
plugin.resetCache();
} else
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyFormatter method getTaxStatus.
/**
* Returns the tax info this resident will have to pay at the next new day.
*
* @param resident
* @return tax status message
*/
public static List<String> getTaxStatus(Resident resident) {
List<String> out = new ArrayList<String>();
Town town = null;
double plotTax = 0.0;
out.add(ChatTools.formatTitle(getFormattedName(resident) + ((BukkitTools.isOnline(resident.getName())) ? Colors.LightGreen + " (Online)" : "")));
if (resident.hasTown()) {
try {
town = resident.getTown();
out.add(Colors.Green + "Owner of: " + Colors.LightGreen + resident.getTownBlocks().size() + " plots");
if (TownyPerms.getResidentPerms(resident).containsKey("towny.tax_exempt")) {
out.add(Colors.Green + "Staff are exempt from paying town taxes.");
} else {
if (town.isTaxPercentage()) {
out.add(Colors.Green + "Town Tax: " + Colors.LightGreen + (resident.getHoldingBalance() * town.getTaxes() / 100));
} else {
out.add(Colors.Green + "Town Tax: " + Colors.LightGreen + town.getTaxes());
if ((resident.getTownBlocks().size() > 0)) {
for (TownBlock townBlock : new ArrayList<TownBlock>(resident.getTownBlocks())) {
plotTax += townBlock.getType().getTax(townBlock.getTown());
}
out.add(Colors.Green + "Total Plot Taxes: " + Colors.LightGreen + plotTax);
}
out.add(Colors.Green + "Total Tax to pay: " + Colors.LightGreen + (town.getTaxes() + plotTax));
}
}
} catch (NotRegisteredException e) {
// Failed to fetch town
} catch (EconomyException e) {
// Economy failed
}
}
return out;
}
Aggregations