use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class TownyFormatter method getStatus.
/**
*
* @param townBlock
* @return a string list containing the results.
*/
public static List<String> getStatus(TownBlock townBlock) {
List<String> out = new ArrayList<String>();
try {
TownBlockOwner owner;
Town town = townBlock.getTown();
TownyWorld world = townBlock.getWorld();
if (townBlock.hasResident()) {
owner = townBlock.getResident();
} else {
owner = townBlock.getTown();
}
out.add(ChatTools.formatTitle(TownyFormatter.getFormattedName(owner) + ((BukkitTools.isOnline(owner.getName())) ? Colors.LightGreen + " (Online)" : "")));
out.add(Colors.Green + " Perm: " + ((owner instanceof Resident) ? townBlock.getPermissions().getColourString() : townBlock.getPermissions().getColourString().replace("f", "r")));
out.add(Colors.Green + "PvP: " + ((town.isPVP() || world.isForcePVP() || townBlock.getPermissions().pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Explosions: " + ((world.isForceExpl() || townBlock.getPermissions().explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Firespread: " + ((town.isFire() || world.isForceFire() || townBlock.getPermissions().fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + " Mob Spawns: " + ((town.hasMobs() || world.isForceTownMobs() || townBlock.getPermissions().mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
} catch (NotRegisteredException e) {
out.add("Error: " + e.getMessage());
}
return out;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class CombatUtil method isAlly.
/**
* Is the defending resident an ally of the attacking resident?
*
* @param attackingResident
* @param defendingResident
* @return true if the defender is an ally of the attacker.
*/
public static boolean isAlly(String attackingResident, String defendingResident) {
try {
Resident residentA = TownyUniverse.getDataSource().getResident(attackingResident);
Resident residentB = TownyUniverse.getDataSource().getResident(defendingResident);
if (residentA.getTown() == residentB.getTown())
return true;
if (residentA.getTown().getNation() == residentB.getTown().getNation())
return true;
if (residentA.getTown().getNation().hasAlly(residentB.getTown().getNation()))
return true;
} catch (NotRegisteredException e) {
return false;
}
return false;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class CombatUtil method isEnemy.
/**
* Is resident b an enemy of resident a?
*
* @param a
* @param b
* @return true if b is an enemy.
*/
public static boolean isEnemy(String a, String b) {
try {
Resident residentA = TownyUniverse.getDataSource().getResident(a);
Resident residentB = TownyUniverse.getDataSource().getResident(b);
if (residentA.getTown() == residentB.getTown())
return false;
if (residentA.getTown().getNation() == residentB.getTown().getNation())
return false;
if (residentA.getTown().getNation().hasEnemy(residentB.getTown().getNation()))
return true;
} catch (NotRegisteredException e) {
return false;
}
return false;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class CombatUtil method canAttackEnemy.
/**
* Can resident a attack resident b?
*
* @param a
* @param b
* @return true if they can attack.
*/
public static boolean canAttackEnemy(String a, String b) {
try {
Resident residentA = TownyUniverse.getDataSource().getResident(a);
Resident residentB = TownyUniverse.getDataSource().getResident(b);
if (residentA.getTown() == residentB.getTown())
return false;
if (residentA.getTown().getNation() == residentB.getTown().getNation())
return false;
Nation nationA = residentA.getTown().getNation();
Nation nationB = residentB.getTown().getNation();
if (nationA.isNeutral() || nationB.isNeutral())
return false;
if (nationA.hasEnemy(nationB))
return true;
} catch (NotRegisteredException e) {
return false;
}
return false;
}
use of com.palmergames.bukkit.towny.object.Resident 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;
}
}
Aggregations