use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyEntityListener method onEntityDamageByEntityEvent.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
if (plugin.isError()) {
return;
}
TownyWorld townyWorld = null;
Entity entity = event.getEntity();
if (entity instanceof ArmorStand) {
String damager = event.getDamager().getType().name();
if (damager == "PRIMED_TNT" || damager == "WITHER_SKULL" || damager == "FIREBALL" || damager == "SMALL_FIREBALL" || damager == "LARGE_FIREBALL" || damager == "WITHER") {
try {
townyWorld = TownyUniverse.getDataSource().getWorld(entity.getWorld().getName());
} catch (NotRegisteredException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!locationCanExplode(townyWorld, entity.getLocation())) {
event.setCancelled(true);
return;
}
}
if (event.getDamager() instanceof Projectile) {
try {
townyWorld = TownyUniverse.getDataSource().getWorld(entity.getWorld().getName());
} catch (NotRegisteredException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Object remover = event.getDamager();
remover = ((Projectile) remover).getShooter();
if (remover instanceof Monster) {
event.setCancelled(true);
} else if (remover instanceof Player) {
Player player = (Player) remover;
// Get destroy permissions (updates if none exist)
boolean bDestroy = PlayerCacheUtil.getCachePermission(player, entity.getLocation(), 416, (byte) 0, TownyPermission.ActionType.DESTROY);
// Allow the removal if we are permitted
if (bDestroy)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
event.setCancelled(true);
}
}
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class TownyEntityListener method onCreatureSpawn.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
if (event.getEntity() instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) event.getEntity();
Location loc = event.getLocation();
Coord coord = Coord.parseCoord(loc);
TownyWorld townyWorld = null;
try {
townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
} catch (NotRegisteredException e) {
// Failed to fetch a world
return;
}
// remove from world if set to remove mobs globally
if (townyWorld.isUsingTowny())
if (!townyWorld.hasWorldMobs() && ((MobRemovalTimerTask.isRemovingWorldEntity(livingEntity) || ((livingEntity instanceof Villager) && !((Villager) livingEntity).isAdult() && (TownySettings.isRemovingVillagerBabiesWorld()))))) {
if (plugin.isCitizens2()) {
if (!CitizensAPI.getNPCRegistry().isNPC(livingEntity)) {
// TownyMessaging.sendDebugMsg("onCreatureSpawn world: Canceled "
// + event.getEntityType().name() +
// " from spawning within "+coord.toString()+".");
event.setCancelled(true);
}
} else
event.setCancelled(true);
}
// remove from towns if in the list and set to remove
try {
TownBlock townBlock = townyWorld.getTownBlock(coord);
if (townyWorld.isUsingTowny() && !townyWorld.isForceTownMobs()) {
if (!townBlock.getTown().hasMobs() && !townBlock.getPermissions().mobs) {
if ((MobRemovalTimerTask.isRemovingTownEntity(livingEntity) || ((livingEntity instanceof Villager) && !((Villager) livingEntity).isAdult() && (TownySettings.isRemovingVillagerBabiesTown())))) {
if (plugin.isCitizens2()) {
if (!CitizensAPI.getNPCRegistry().isNPC(livingEntity)) {
// TownyMessaging.sendDebugMsg("onCreatureSpawn town: Canceled "
// + event.getEntityType().name() +
// " from spawning within "+coord.toString()+".");
event.setCancelled(true);
}
} else
event.setCancelled(true);
}
}
}
} catch (TownyException x) {
}
}
}
use of com.palmergames.bukkit.towny.exceptions.NotRegisteredException in project Towny by ElgarL.
the class DailyTimerTask method collectTownTaxes.
/**
* Collect taxes due to the town from it's residents.
*
* @param nation
* @throws EconomyException
*/
protected void collectTownTaxes(Town town) throws EconomyException {
// Resident Tax
if (town.getTaxes() > 0) {
List<Resident> residents = new ArrayList<Resident>(town.getResidents());
ListIterator<Resident> residentItr = residents.listIterator();
Resident resident = null;
while (residentItr.hasNext()) {
resident = residentItr.next();
/*
* Only collect resident tax from this resident if it really
* still exists. We are running in an Async thread so MUST
* verify all objects.
*/
if (TownyUniverse.getDataSource().hasResident(resident.getName())) {
if (TownyPerms.getResidentPerms(resident).containsKey("towny.tax_exempt") || resident.isNPC()) {
try {
TownyMessaging.sendResidentMessage(resident, TownySettings.getTaxExemptMsg());
} catch (TownyException e) {
// Player is not online
}
continue;
} else if (town.isTaxPercentage()) {
double cost = resident.getHoldingBalance() * town.getTaxes() / 100;
resident.payTo(cost, town, "Town Tax (Percentage)");
/*
* Don't send individual message anymore to ease up on
* the lag. try {
* TownyMessaging.sendResidentMessage(resident,
* TownySettings.getPayedResidentTaxMsg() + cost); }
* catch (TownyException e) { // Player is not online }
*/
} else if (!resident.payTo(town.getTaxes(), town, "Town Tax")) {
TownyMessaging.sendTownMessage(town, TownySettings.getCouldntPayTaxesMsg(resident, "town"));
try {
// reset this resident and remove him from the town.
resident.clear();
TownyUniverse.getDataSource().saveTown(town);
} catch (EmptyTownException e) {
// No mayor so remove the town.
TownyUniverse.getDataSource().removeTown(town);
}
TownyUniverse.getDataSource().saveResident(resident);
}
// else
/*
* Don't send individual message anymore to ease up on the
* lag. try { TownyMessaging.sendResidentMessage(resident,
* TownySettings.getPayedResidentTaxMsg() +
* town.getTaxes()); } catch (TownyException e) { // Player
* is not online }
*/
}
}
}
// Plot Tax
if (town.getPlotTax() > 0 || town.getCommercialPlotTax() > 0 || town.getEmbassyPlotTax() > 0) {
// Hashtable<Resident, Integer> townPlots = new Hashtable<Resident,
// Integer>();
// Hashtable<Resident, Double> townTaxes = new Hashtable<Resident,
// Double>();
List<TownBlock> townBlocks = new ArrayList<TownBlock>(town.getTownBlocks());
ListIterator<TownBlock> townBlockItr = townBlocks.listIterator();
TownBlock townBlock = null;
while (townBlockItr.hasNext()) {
townBlock = townBlockItr.next();
if (!townBlock.hasResident())
continue;
try {
Resident resident = townBlock.getResident();
/*
* Only collect plot tax from this resident if it really
* still exists. We are running in an Async thread so MUST
* verify all objects.
*/
if (TownyUniverse.getDataSource().hasResident(resident.getName())) {
if (TownyPerms.getResidentPerms(resident).containsKey("towny.tax_exempt") || resident.isNPC()) {
continue;
}
if (!resident.payTo(townBlock.getType().getTax(town), town, String.format("Plot Tax (%s)", townBlock.getType()))) {
TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_couldnt_pay_plot_taxes"), resident));
townBlock.setResident(null);
townBlock.setPlotPrice(-1);
// Set the plot permissions to mirror the towns.
townBlock.setType(townBlock.getType());
TownyUniverse.getDataSource().saveResident(resident);
TownyUniverse.getDataSource().saveTownBlock(townBlock);
}
// else {
// townPlots.put(resident,
// (townPlots.containsKey(resident) ?
// townPlots.get(resident) : 0) + 1);
// townTaxes.put(resident,
// (townTaxes.containsKey(resident) ?
// townTaxes.get(resident) : 0) +
// townBlock.getType().getTax(town));
// }
}
} catch (NotRegisteredException e) {
}
}
/*
* Don't send individual message anymore to ease up on the lag. for
* (Resident resident : townPlots.keySet()) { try { int numPlots =
* townPlots.get(resident); double totalCost =
* townTaxes.get(resident);
* TownyMessaging.sendResidentMessage(resident,
* String.format(TownySettings.getLangString("msg_payed_plot_cost"),
* totalCost, numPlots, town.getName())); } catch (TownyException e)
* { // Player is not online } }
*/
}
}
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.");
}
}
Aggregations