use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class PlayerCacheUtil method getTownBlockStatus.
/**
* Fetch the TownBlockStatus type for this player at this WorldCoord.
*
* @param player
* @param worldCoord
* @return TownBlockStatus type.
*/
public static TownBlockStatus getTownBlockStatus(Player player, WorldCoord worldCoord) {
try {
if (!worldCoord.getTownyWorld().isUsingTowny())
return TownBlockStatus.OFF_WORLD;
} catch (NotRegisteredException ex) {
// Not a registered world
return TownBlockStatus.NOT_REGISTERED;
}
//TownyUniverse universe = plugin.getTownyUniverse();
TownBlock townBlock;
Town town;
try {
townBlock = worldCoord.getTownBlock();
town = townBlock.getTown();
if (townBlock.isLocked()) {
// Push the TownBlock location to the queue for a snapshot (if it's not already in the queue).
if (town.getWorld().isUsingPlotManagementRevert() && (TownySettings.getPlotManagementSpeed() > 0)) {
TownyRegenAPI.addWorldCoord(townBlock.getWorldCoord());
return TownBlockStatus.LOCKED;
}
townBlock.setLocked(false);
}
} catch (NotRegisteredException e) {
// Unclaimed Zone switch rights
return TownBlockStatus.UNCLAIMED_ZONE;
}
/*
* Find the resident data for this player.
*/
Resident resident;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
} catch (TownyException e) {
System.out.print("Failed to fetch resident: " + player.getName());
return TownBlockStatus.NOT_REGISTERED;
}
try {
// War Time switch rights
if (TownyUniverse.isWarTime()) {
if (TownySettings.isAllowWarBlockGriefing()) {
try {
if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral())
return TownBlockStatus.WARZONE;
} catch (NotRegisteredException e) {
}
}
//If this town is not in a nation and we are set to non neutral status during war.
if (!TownySettings.isWarTimeTownsNeutral() && !town.hasNation())
return TownBlockStatus.WARZONE;
}
// Town Owner Override
try {
if (// || townBlock.getTown().hasAssistant(resident))
townBlock.getTown().isMayor(resident))
return TownBlockStatus.TOWN_OWNER;
} catch (NotRegisteredException e) {
}
// Resident Plot rights
try {
Resident owner = townBlock.getResident();
if (resident == owner)
return TownBlockStatus.PLOT_OWNER;
else if (owner.hasFriend(resident))
return TownBlockStatus.PLOT_FRIEND;
else if (resident.hasTown() && CombatUtil.isAlly(owner.getTown(), resident.getTown()))
return TownBlockStatus.PLOT_ALLY;
else
// Exit out and use town permissions
throw new TownyException();
} catch (NotRegisteredException x) {
} catch (TownyException x) {
}
// Resident with no town.
if (!resident.hasTown()) {
if (townBlock.isWarZone()) {
if (!TownySettings.isWarTimeTownsNeutral())
return TownBlockStatus.WARZONE;
else
return TownBlockStatus.OUTSIDER;
}
throw new TownyException();
}
if (resident.getTown() != town) {
// Allied destroy rights
if (CombatUtil.isAlly(town, resident.getTown()))
return TownBlockStatus.TOWN_ALLY;
else if (CombatUtil.isEnemy(resident.getTown(), town)) {
if (townBlock.isWarZone())
return TownBlockStatus.WARZONE;
else
return TownBlockStatus.ENEMY;
} else
return TownBlockStatus.OUTSIDER;
} else if (// || resident.getTown().hasAssistant(resident))
resident.isMayor())
return TownBlockStatus.TOWN_OWNER;
else
return TownBlockStatus.TOWN_RESIDENT;
} catch (TownyException e) {
// Outsider destroy rights
return TownBlockStatus.OUTSIDER;
}
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class War method remove.
public void remove(WorldCoord worldCoord) {
try {
Town town = worldCoord.getTownBlock().getTown();
TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord, town.getName()));
warZone.remove(worldCoord);
} catch (NotRegisteredException e) {
TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord));
warZone.remove(worldCoord);
}
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class War method getScores.
/**
*
* @param maxListing Maximum lines to return. Value of -1 return all.
* @return A list of the current scores per town sorted in descending order.
*/
public List<String> getScores(int maxListing) {
List<String> output = new ArrayList<String>();
output.add(ChatTools.formatTitle("War - Top Scores"));
KeyValueTable<Town, Integer> kvTable = new KeyValueTable<Town, Integer>(townScores);
kvTable.sortByValue();
kvTable.revese();
int n = 0;
for (KeyValue<Town, Integer> kv : kvTable.getKeyValues()) {
n++;
if (maxListing != -1 && n > maxListing)
break;
Town town = (Town) kv.key;
output.add(String.format(Colors.Blue + "%40s " + Colors.Gold + "|" + Colors.LightGray + " %4d", TownyFormatter.getFormattedName(town), (Integer) kv.value));
}
return output;
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class War method end.
public void end() {
for (Player player : BukkitTools.getOnlinePlayers()) if (player != null)
sendStats(player);
double halfWinnings;
try {
// Transactions might leave 1 coin. (OH noez!)
halfWinnings = getWarSpoils().getHoldingBalance() / 2.0;
try {
// Again, might leave residue.
double nationWinnings = halfWinnings / warringNations.size();
for (Nation winningNation : warringNations) {
getWarSpoils().payTo(nationWinnings, winningNation, "War - Nation Winnings");
TownyMessaging.sendGlobalMessage("Winning Nation: " + winningNation.getName() + " won " + TownyEconomyHandler.getFormattedBalance(nationWinnings) + ".");
}
} catch (ArithmeticException e) {
// A war ended with 0 nations.
}
try {
KeyValue<Town, Integer> winningTownScore = getWinningTownScore();
getWarSpoils().payTo(halfWinnings, winningTownScore.key, "War - Town Winnings");
TownyMessaging.sendGlobalMessage("Highest Score: " + winningTownScore.key.getName() + " won " + TownyEconomyHandler.getFormattedBalance(halfWinnings) + " with the score " + winningTownScore.value + ".");
} catch (TownyException e) {
}
} catch (EconomyException e1) {
}
}
use of com.palmergames.bukkit.towny.object.Town in project Towny by ElgarL.
the class War method getWinningTownScore.
public KeyValue<Town, Integer> getWinningTownScore() throws TownyException {
KeyValueTable<Town, Integer> kvTable = new KeyValueTable<Town, Integer>(townScores);
kvTable.sortByValue();
kvTable.revese();
if (kvTable.getKeyValues().size() > 0)
return kvTable.getKeyValues().get(0);
else
throw new TownyException();
}
Aggregations