use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class NationCommand method nationAdd.
public void nationAdd(Player player, String[] names) {
if (names.length < 1) {
TownyMessaging.sendErrorMsg(player, "Eg: /nation add [names]");
return;
}
Resident resident;
Nation nation;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
nation = resident.getTown().getNation();
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
nationAdd(player, nation, TownyUniverse.getDataSource().getTowns(names));
}
use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class ResidentCommand method residentSpawn.
/**
* Attempt to send player to bed spawn.
*
* @param player
*/
public void residentSpawn(Player player) {
boolean isTownyAdmin = TownyUniverse.getPermissionSource().isTownyAdmin(player);
Resident resident;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
Town town;
Location spawnLoc;
String notAffordMSG;
TownSpawnLevel townSpawnPermission;
// Set target town and affiliated messages.
town = resident.getTown();
notAffordMSG = TownySettings.getLangString("msg_err_cant_afford_tp");
if (TownySettings.getBedUse() && player.getBedSpawnLocation() != null) {
spawnLoc = player.getBedSpawnLocation();
} else {
spawnLoc = town.getSpawn();
}
if (isTownyAdmin) {
townSpawnPermission = TownSpawnLevel.ADMIN;
} else {
townSpawnPermission = TownSpawnLevel.TOWN_RESIDENT;
}
if (!isTownyAdmin) {
// Prevent spawn travel while in disallowed zones (if
// configured)
List<String> disallowedZones = TownySettings.getDisallowedTownSpawnZones();
if (!disallowedZones.isEmpty()) {
String inTown = null;
try {
Location loc = plugin.getCache(player).getLastLocation();
inTown = TownyUniverse.getTownName(loc);
} catch (NullPointerException e) {
inTown = TownyUniverse.getTownName(player.getLocation());
}
if (inTown == null && disallowedZones.contains("unclaimed"))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "the Wilderness"));
if (inTown != null && resident.hasNation() && TownyUniverse.getDataSource().getTown(inTown).hasNation()) {
Nation inNation = TownyUniverse.getDataSource().getTown(inTown).getNation();
Nation playerNation = resident.getTown().getNation();
if (inNation.hasEnemy(playerNation) && disallowedZones.contains("enemy"))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "Enemy areas"));
if (!inNation.hasAlly(playerNation) && !inNation.hasEnemy(playerNation) && disallowedZones.contains("neutral"))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "Neutral towns"));
}
}
}
double travelCost = townSpawnPermission.getCost();
// Check if need/can pay
if (travelCost > 0 && TownySettings.isUsingEconomy() && (resident.getHoldingBalance() < travelCost))
throw new TownyException(notAffordMSG);
// Used later to make sure the chunk we teleport to is loaded.
Chunk chunk = spawnLoc.getChunk();
// Essentials tests
boolean UsingESS = plugin.isEssentials();
if (UsingESS && !isTownyAdmin) {
try {
User user = plugin.getEssentials().getUser(player);
if (!user.isJailed()) {
Teleport teleport = user.getTeleport();
if (!chunk.isLoaded())
chunk.load();
// Cause an essentials exception if in cooldown.
teleport.cooldown(true);
teleport.teleport(spawnLoc, null);
}
} catch (Exception e) {
TownyMessaging.sendErrorMsg(player, "Error: " + e.getMessage());
// cooldown?
return;
}
}
// travel.
if (travelCost > 0 && TownySettings.isUsingEconomy() && resident.payTo(travelCost, town, String.format("Resident Spawn (%s)", townSpawnPermission))) {
// +
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_cost_spawn"), TownyEconomyHandler.getFormattedBalance(travelCost)));
// TownyEconomyObject.getEconomyCurrency()));
}
// If an Admin or Essentials teleport isn't being used, use our own.
if (isTownyAdmin) {
if (player.getVehicle() != null)
player.getVehicle().eject();
if (!chunk.isLoaded())
chunk.load();
player.teleport(spawnLoc, TeleportCause.COMMAND);
return;
}
if (!UsingESS) {
if (TownyTimerHandler.isTeleportWarmupRunning()) {
// Use teleport warmup
player.sendMessage(String.format(TownySettings.getLangString("msg_town_spawn_warmup"), TownySettings.getTeleportWarmupTime()));
plugin.getTownyUniverse().requestTeleport(player, spawnLoc, travelCost);
} else {
// Don't use teleport warmup
if (player.getVehicle() != null)
player.getVehicle().eject();
if (!chunk.isLoaded())
chunk.load();
player.teleport(spawnLoc, TeleportCause.COMMAND);
}
}
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
} catch (EconomyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
}
use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class DailyTimerTask method collectNationTaxes.
/**
* Collect taxes for all nations due from their member towns
*
* @throws EconomyException
*/
public void collectNationTaxes() throws EconomyException {
List<Nation> nations = new ArrayList<Nation>(TownyUniverse.getDataSource().getNations());
ListIterator<Nation> nationItr = nations.listIterator();
Nation nation = null;
while (nationItr.hasNext()) {
nation = nationItr.next();
/*
* Only collect tax for this nation if it really still exists.
* We are running in an Async thread so MUST verify all objects.
*/
if (TownyUniverse.getDataSource().hasNation(nation.getName()))
collectNationTaxes(nation);
}
universe.setChangedNotify(COLLECTED_NATION_TAX);
}
use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class OnPlayerLogin method warningMessage.
/**
* Send a warning message if the town or nation is due to be deleted.
*
* @param resident
*/
private void warningMessage(Resident resident) {
if (TownyEconomyHandler.isActive() && TownySettings.isTaxingDaily()) {
if (resident.hasTown()) {
try {
Town town = resident.getTown();
if (town.hasUpkeep()) {
double upkeep = TownySettings.getTownUpkeepCost(town);
try {
if ((upkeep > 0) && (!town.canPayFromHoldings(upkeep))) {
/*
* Warn that the town is due to be deleted.
*/
TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_warning_delete"), town.getName()));
}
} catch (EconomyException ex) {
// Economy error, so ignore it and try to continue.
}
}
if (town.hasNation()) {
Nation nation = town.getNation();
double upkeep = TownySettings.getNationUpkeepCost(nation);
try {
if ((upkeep > 0) && (!nation.canPayFromHoldings(upkeep))) {
/*
* Warn that the nation is due to be deleted.
*/
TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_warning_delete"), nation.getName()));
}
} catch (EconomyException ex) {
// Economy error, so ignore it and try to continue.
}
}
} catch (NotRegisteredException ex) {
// Should never reach here as we tested it beforehand.
}
}
}
}
use of com.palmergames.bukkit.towny.object.Nation in project Towny by ElgarL.
the class WarTimerTask method run.
@Override
public void run() {
//TODO: check if war has ended and end gracefully
if (!warEvent.isWarTime()) {
warEvent.end();
universe.clearWarEvent();
plugin.resetCache();
TownyMessaging.sendDebugMsg("War ended.");
return;
}
int numPlayers = 0;
for (Player player : BukkitTools.getOnlinePlayers()) {
if (player != null) {
numPlayers += 1;
TownyMessaging.sendDebugMsg("[War] " + player.getName() + ": ");
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
if (resident.hasNation()) {
Nation nation = resident.getTown().getNation();
TownyMessaging.sendDebugMsg("[War] hasNation");
if (nation.isNeutral()) {
if (warEvent.isWarringNation(nation))
warEvent.nationLeave(nation);
continue;
}
TownyMessaging.sendDebugMsg("[War] notNeutral");
if (!warEvent.isWarringNation(nation))
continue;
TownyMessaging.sendDebugMsg("[War] warringNation");
//TODO: Cache player coord & townblock
WorldCoord worldCoord = new WorldCoord(player.getWorld().getName(), Coord.parseCoord(player));
if (!warEvent.isWarZone(worldCoord))
continue;
TownyMessaging.sendDebugMsg("[War] warZone");
if (player.getLocation().getBlockY() < TownySettings.getMinWarHeight())
continue;
TownyMessaging.sendDebugMsg("[War] aboveMinHeight");
//universe.getWorld(player.getWorld().getName()).getTownBlock(worldCoord);
TownBlock townBlock = worldCoord.getTownBlock();
if (nation == townBlock.getTown().getNation() || townBlock.getTown().getNation().hasAlly(nation))
continue;
TownyMessaging.sendDebugMsg("[War] notAlly");
//Enemy nation
warEvent.damage(resident.getTown(), townBlock);
TownyMessaging.sendDebugMsg("[War] damaged");
}
} catch (NotRegisteredException e) {
continue;
}
}
}
TownyMessaging.sendDebugMsg("[War] # Players: " + numPlayers);
}
Aggregations