This commit is contained in:
drtshock
2014-07-01 15:10:18 -05:00
parent 5066934a95
commit 8a6a97cc90
110 changed files with 3131 additions and 1228 deletions

View File

@@ -115,19 +115,22 @@ public class Faction extends Entity implements EconomyParticipator {
public String getTag(Faction otherFaction) {
if (otherFaction == null) {
return getTag();
} return this.getTag(this.getColorTo(otherFaction).toString());
}
return this.getTag(this.getColorTo(otherFaction).toString());
}
public String getTag(FPlayer otherFplayer) {
if (otherFplayer == null) {
return getTag();
} return this.getTag(this.getColorTo(otherFplayer).toString());
}
return this.getTag(this.getColorTo(otherFplayer).toString());
}
public void setTag(String str) {
if (Conf.factionTagForceUpperCase) {
str = str.toUpperCase();
} this.tag = str;
}
this.tag = str;
}
public String getComparisonTag() {
@@ -157,7 +160,8 @@ public class Faction extends Entity implements EconomyParticipator {
}
public Location getHome() {
confirmValidHome(); return (this.home != null) ? this.home.getLocation() : null;
confirmValidHome();
return (this.home != null) ? this.home.getLocation() : null;
}
public void confirmValidHome() {
@@ -165,7 +169,8 @@ public class Faction extends Entity implements EconomyParticipator {
return;
}
msg("<b>Your faction home has been un-set since it is no longer in your territory."); this.home = null;
msg("<b>Your faction home has been un-set since it is no longer in your territory.");
this.home = null;
}
// FIELD: lastPlayerLoggedOffTime
@@ -179,7 +184,9 @@ public class Faction extends Entity implements EconomyParticipator {
String aid = "faction-" + this.getId();
// We need to override the default money given to players.
if (!Econ.hasAccount(aid)) { Econ.setBalance(aid, 0); }
if (!Econ.hasAccount(aid)) {
Econ.setBalance(aid, 0);
}
return aid;
}
@@ -217,10 +224,17 @@ public class Faction extends Entity implements EconomyParticipator {
// -------------------------------------------- //
public Faction() {
this.relationWish = new HashMap<String, Relation>(); this.invites = new HashSet<String>();
this.open = Conf.newFactionsDefaultOpen; this.tag = "???"; this.description = "Default faction description :(";
this.lastPlayerLoggedOffTime = 0; this.peaceful = false; this.peacefulExplosionsEnabled = false;
this.permanent = false; this.money = 0.0; this.powerBoost = 0.0;
this.relationWish = new HashMap<String, Relation>();
this.invites = new HashSet<String>();
this.open = Conf.newFactionsDefaultOpen;
this.tag = "???";
this.description = "Default faction description :(";
this.lastPlayerLoggedOffTime = 0;
this.peaceful = false;
this.peacefulExplosionsEnabled = false;
this.permanent = false;
this.money = 0.0;
this.powerBoost = 0.0;
}
// -------------------------------------------- //
@@ -293,7 +307,8 @@ public class Faction extends Entity implements EconomyParticipator {
public Relation getRelationWish(Faction otherFaction) {
if (this.relationWish.containsKey(otherFaction.getId())) {
return this.relationWish.get(otherFaction.getId());
} return Relation.NEUTRAL;
}
return Relation.NEUTRAL;
}
public void setRelationWish(Faction otherFaction, Relation relation) {
@@ -312,11 +327,14 @@ public class Faction extends Entity implements EconomyParticipator {
return this.getPermanentPower();
}
double ret = 0; for (FPlayer fplayer : fplayers) {
double ret = 0;
for (FPlayer fplayer : fplayers) {
ret += fplayer.getPower();
} if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
}
if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
ret = Conf.powerFactionMax;
} return ret + this.powerBoost;
}
return ret + this.powerBoost;
}
public double getPowerMax() {
@@ -324,11 +342,14 @@ public class Faction extends Entity implements EconomyParticipator {
return this.getPermanentPower();
}
double ret = 0; for (FPlayer fplayer : fplayers) {
double ret = 0;
for (FPlayer fplayer : fplayers) {
ret += fplayer.getPowerMax();
} if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
}
if (Conf.powerFactionMax > 0 && ret > Conf.powerFactionMax) {
ret = Conf.powerFactionMax;
} return ret + this.powerBoost;
}
return ret + this.powerBoost;
}
public int getPowerRounded() {
@@ -357,7 +378,10 @@ public class Faction extends Entity implements EconomyParticipator {
// maintain the reference list of FPlayers in this faction
public void refreshFPlayers() {
fplayers.clear(); if (this.isPlayerFreeType()) { return; }
fplayers.clear();
if (this.isPlayerFreeType()) {
return;
}
for (FPlayer fplayer : FPlayers.i.get()) {
if (fplayer.getFaction() == this) {
@@ -367,20 +391,25 @@ public class Faction extends Entity implements EconomyParticipator {
}
protected boolean addFPlayer(FPlayer fplayer) {
if (this.isPlayerFreeType()) { return false; }
if (this.isPlayerFreeType()) {
return false;
}
return fplayers.add(fplayer);
}
protected boolean removeFPlayer(FPlayer fplayer) {
if (this.isPlayerFreeType()) { return false; }
if (this.isPlayerFreeType()) {
return false;
}
return fplayers.remove(fplayer);
}
public Set<FPlayer> getFPlayers() {
// return a shallow copy of the FPlayer list, to prevent tampering and concurrency issues
Set<FPlayer> ret = new HashSet<FPlayer>(fplayers); return ret;
Set<FPlayer> ret = new HashSet<FPlayer>(fplayers);
return ret;
}
public Set<FPlayer> getFPlayersWhereOnline(boolean online) {
@@ -396,17 +425,23 @@ public class Faction extends Entity implements EconomyParticipator {
}
public FPlayer getFPlayerAdmin() {
if (!this.isNormal()) { return null; }
if (!this.isNormal()) {
return null;
}
for (FPlayer fplayer : fplayers) {
if (fplayer.getRole() == Role.ADMIN) {
return fplayer;
}
} return null;
}
return null;
}
public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>(); if (!this.isNormal()) { return ret; }
ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (!this.isNormal()) {
return ret;
}
for (FPlayer fplayer : fplayers) {
if (fplayer.getRole() == role) {
@@ -418,10 +453,14 @@ public class Faction extends Entity implements EconomyParticipator {
}
public ArrayList<Player> getOnlinePlayers() {
ArrayList<Player> ret = new ArrayList<Player>(); if (this.isPlayerFreeType()) { return ret; }
ArrayList<Player> ret = new ArrayList<Player>();
if (this.isPlayerFreeType()) {
return ret;
}
for (Player player : P.p.getServer().getOnlinePlayers()) {
FPlayer fplayer = FPlayers.i.get(player); if (fplayer.getFaction() == this) {
FPlayer fplayer = FPlayers.i.get(player);
if (fplayer.getFaction() == this) {
ret.add(player);
}
}
@@ -432,10 +471,13 @@ public class Faction extends Entity implements EconomyParticipator {
// slightly faster check than getOnlinePlayers() if you just want to see if there are any players online
public boolean hasPlayersOnline() {
// only real factions can have players online, not safe zone / war zone
if (this.isPlayerFreeType()) { return false; }
if (this.isPlayerFreeType()) {
return false;
}
for (Player player : P.p.getServer().getOnlinePlayers()) {
FPlayer fplayer = FPlayers.i.get(player); if (fplayer != null && fplayer.getFaction() == this) {
FPlayer fplayer = FPlayers.i.get(player);
if (fplayer != null && fplayer.getFaction() == this) {
return true;
}
}
@@ -443,7 +485,8 @@ public class Faction extends Entity implements EconomyParticipator {
// even if all players are technically logged off, maybe someone was on recently enough to not consider them officially offline yet
if (Conf.considerFactionsReallyOfflineAfterXMinutes > 0 && System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000)) {
return true;
} return false;
}
return false;
}
public void memberLoggedOff() {
@@ -454,18 +497,27 @@ public class Faction extends Entity implements EconomyParticipator {
// used when current leader is about to be removed from the faction; promotes new leader, or disbands faction if no other members left
public void promoteNewLeader() {
if (!this.isNormal()) { return; }
if (this.isPermanent() && Conf.permanentFactionsDisableLeaderPromotion) { return; }
if (!this.isNormal()) {
return;
}
if (this.isPermanent() && Conf.permanentFactionsDisableLeaderPromotion) {
return;
}
FPlayer oldLeader = this.getFPlayerAdmin();
// get list of moderators, or list of normal members if there are no moderators
ArrayList<FPlayer> replacements = this.getFPlayersWhereRole(Role.MODERATOR);
if (replacements == null || replacements.isEmpty()) { replacements = this.getFPlayersWhereRole(Role.NORMAL); }
if (replacements == null || replacements.isEmpty()) {
replacements = this.getFPlayersWhereRole(Role.NORMAL);
}
if (replacements == null || replacements.isEmpty()) { // faction admin is the only member; one-man faction
if (this.isPermanent()) {
if (oldLeader != null) { oldLeader.setRole(Role.NORMAL); } return;
if (oldLeader != null) {
oldLeader.setRole(Role.NORMAL);
}
return;
}
// no members left and faction isn't permanent, so disband it
@@ -479,7 +531,10 @@ public class Faction extends Entity implements EconomyParticipator {
this.detach();
} else { // promote new faction admin
if (oldLeader != null) { oldLeader.setRole(Role.NORMAL); } replacements.get(0).setRole(Role.ADMIN);
if (oldLeader != null) {
oldLeader.setRole(Role.NORMAL);
}
replacements.get(0).setRole(Role.ADMIN);
this.msg("<i>Faction admin <h>%s<i> has been removed. %s<i> has been promoted as the new faction admin.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName());
P.p.log("Faction " + this.getTag() + " (" + this.getId() + ") admin was removed. Replacement admin: " + replacements.get(0).getName());
}
@@ -535,9 +590,12 @@ public class Faction extends Entity implements EconomyParticipator {
for (Entry<FLocation, Set<String>> entry : claimOwnership.entrySet()) {
ownerData = entry.getValue();
if (ownerData == null) { continue; }
if (ownerData == null) {
continue;
}
Iterator<String> iter = ownerData.iterator(); while (iter.hasNext()) {
Iterator<String> iter = ownerData.iterator();
while (iter.hasNext()) {
if (iter.next().equals(player.getId())) {
iter.remove();
}
@@ -558,15 +616,19 @@ public class Faction extends Entity implements EconomyParticipator {
return false;
}
Set<String> ownerData = claimOwnership.get(loc); return ownerData != null && !ownerData.isEmpty();
Set<String> ownerData = claimOwnership.get(loc);
return ownerData != null && !ownerData.isEmpty();
}
public boolean isPlayerInOwnerList(FPlayer player, FLocation loc) {
if (claimOwnership.isEmpty()) {
return false;
} Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null) {
}
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null) {
return false;
} if (ownerData.contains(player.getId())) {
}
if (ownerData.contains(player.getId())) {
return true;
}
@@ -574,15 +636,21 @@ public class Faction extends Entity implements EconomyParticipator {
}
public void setPlayerAsOwner(FPlayer player, FLocation loc) {
Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null) {
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null) {
ownerData = new HashSet<String>();
} ownerData.add(player.getId()); claimOwnership.put(loc, ownerData);
}
ownerData.add(player.getId());
claimOwnership.put(loc, ownerData);
}
public void removePlayerAsOwner(FPlayer player, FLocation loc) {
Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null) {
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null) {
return;
} ownerData.remove(player.getId()); claimOwnership.put(loc, ownerData);
}
ownerData.remove(player.getId());
claimOwnership.put(loc, ownerData);
}
public Set<String> getOwnerList(FLocation loc) {
@@ -590,18 +658,22 @@ public class Faction extends Entity implements EconomyParticipator {
}
public String getOwnerListString(FLocation loc) {
Set<String> ownerData = claimOwnership.get(loc); if (ownerData == null || ownerData.isEmpty()) {
Set<String> ownerData = claimOwnership.get(loc);
if (ownerData == null || ownerData.isEmpty()) {
return "";
}
String ownerList = "";
Iterator<String> iter = ownerData.iterator(); while (iter.hasNext()) {
Iterator<String> iter = ownerData.iterator();
while (iter.hasNext()) {
if (!ownerList.isEmpty()) {
ownerList += ", ";
} OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(iter.next()));
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(iter.next()));
ownerList += offlinePlayer != null ? offlinePlayer.getName() : "null player";
} return ownerList;
}
return ownerList;
}
public boolean playerHasOwnershipRights(FPlayer fplayer, FLocation loc) {
@@ -611,13 +683,17 @@ public class Faction extends Entity implements EconomyParticipator {
}
// make sure claimOwnership is initialized
if (claimOwnership.isEmpty()) { return true; }
if (claimOwnership.isEmpty()) {
return true;
}
// need to check the ownership list, then
Set<String> ownerData = claimOwnership.get(loc);
// if no owner list, owner list is empty, or player is in owner list, they're allowed
if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId())) { return true; }
if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId())) {
return true;
}
return false;
}