use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class TownyFlatFileSource method loadNation.
@Override
public boolean loadNation(Nation nation) {
String line = "";
String[] tokens;
String path = getNationFilename(nation);
File fileResident = new File(path);
if (fileResident.exists() && fileResident.isFile()) {
try {
KeyValueFile kvFile = new KeyValueFile(path);
line = kvFile.get("towns");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()) {
TownyMessaging.sendDebugMsg("Nation Fetching Town: " + token);
Town town = getTown(token);
if (town != null)
nation.addTown(town);
}
}
}
line = kvFile.get("capital");
if (line != null)
nation.setCapital(getTown(line));
// line = kvFile.get("assistants");
// if (line != null) {
// tokens = line.split(",");
// for (String token : tokens) {
// if (!token.isEmpty()) {
// Resident assistant = getResident(token);
// if (assistant != null)
// nation.addAssistant(assistant);
// }
// }
// }
line = kvFile.get("tag");
if (line != null)
try {
nation.setTag(line);
} catch (TownyException e) {
nation.setTag("");
}
line = kvFile.get("allies");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()) {
Nation friend = getNation(token);
if (friend != null)
//("ally", friend);
nation.addAlly(friend);
}
}
}
line = kvFile.get("enemies");
if (line != null) {
tokens = line.split(",");
for (String token : tokens) {
if (!token.isEmpty()) {
Nation enemy = getNation(token);
if (enemy != null)
//("enemy", enemy);
nation.addEnemy(enemy);
}
}
}
line = kvFile.get("taxes");
if (line != null)
try {
nation.setTaxes(Double.parseDouble(line));
} catch (Exception e) {
nation.setTaxes(0.0);
}
line = kvFile.get("neutral");
if (line != null)
try {
nation.setNeutral(Boolean.parseBoolean(line));
} catch (Exception e) {
}
} catch (Exception e) {
TownyMessaging.sendErrorMsg("Loading Error: Exception while reading nation file " + nation.getName());
return false;
}
return true;
} else
return false;
}
use of com.palmergames.bukkit.towny.object.Town 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.Town 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.Town in project Towny by ElgarL.
the class DailyTimerTask method collectTownCosts.
/**
* Collect or pay upkeep for all towns.
*
* @throws EconomyException
* @throws TownyException
*/
public void collectTownCosts() throws EconomyException, TownyException {
List<Town> towns = new ArrayList<Town>(TownyUniverse.getDataSource().getTowns());
ListIterator<Town> townItr = towns.listIterator();
Town town = null;
while (townItr.hasNext()) {
town = townItr.next();
/*
* Only charge/pay upkeep for this town if it really still exists.
* We are running in an Async thread so MUST verify all objects.
*/
if (TownyUniverse.getDataSource().hasTown(town.getName())) {
if (town.hasUpkeep()) {
double upkeep = TownySettings.getTownUpkeepCost(town);
if (upkeep > 0) {
// Town is paying upkeep
if (!town.pay(upkeep, "Town Upkeep")) {
TownyUniverse.getDataSource().removeTown(town);
TownyMessaging.sendGlobalMessage(town.getName() + TownySettings.getLangString("msg_bankrupt_town"));
}
} else if (upkeep < 0) {
// Negative upkeep
if (TownySettings.isUpkeepPayingPlots()) {
// Pay each plot owner a share of the negative
// upkeep
List<TownBlock> plots = new ArrayList<TownBlock>(town.getTownBlocks());
for (TownBlock townBlock : plots) {
if (townBlock.hasResident())
townBlock.getResident().pay((upkeep / plots.size()), "Negative Town Upkeep - Plot income");
else
town.pay((upkeep / plots.size()), "Negative Town Upkeep - Plot income");
}
} else {
// Not paying plot owners so just pay the town
town.pay(upkeep, "Negative Town Upkeep");
}
}
}
}
}
universe.setChangedNotify(UPKEEP_TOWN);
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class DailyTimerTask method collectTownTaxes.
/**
* Collect taxes for all towns due from their residents.
*
* @throws EconomyException
*/
public void collectTownTaxes() throws EconomyException {
List<Town> towns = new ArrayList<Town>(TownyUniverse.getDataSource().getTowns());
ListIterator<Town> townItr = towns.listIterator();
Town town = null;
while (townItr.hasNext()) {
town = townItr.next();
/*
* Only collect resident tax for this town if it really still
* exists.
* We are running in an Async thread so MUST verify all objects.
*/
if (TownyUniverse.getDataSource().hasTown(town.getName()))
collectTownTaxes(town);
}
universe.setChangedNotify(COLLECTED_TONW_TAX);
}
Aggregations