More reformatting
This commit is contained in:
@@ -115,22 +115,19 @@ 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() {
|
||||
@@ -160,8 +157,7 @@ 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() {
|
||||
@@ -169,8 +165,7 @@ 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
|
||||
@@ -222,17 +217,10 @@ 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;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@@ -305,15 +293,13 @@ 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) {
|
||||
if (this.relationWish.containsKey(otherFaction.getId()) && relation.equals(Relation.NEUTRAL)) {
|
||||
this.relationWish.remove(otherFaction.getId());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.relationWish.put(otherFaction.getId(), relation);
|
||||
}
|
||||
}
|
||||
@@ -326,14 +312,11 @@ 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() {
|
||||
@@ -341,14 +324,11 @@ 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() {
|
||||
@@ -377,8 +357,7 @@ 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) {
|
||||
@@ -401,8 +380,7 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
|
||||
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) {
|
||||
@@ -424,13 +402,11 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
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) {
|
||||
@@ -442,12 +418,10 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -461,8 +435,7 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -470,8 +443,7 @@ 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() {
|
||||
@@ -493,8 +465,7 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
|
||||
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
|
||||
@@ -507,10 +478,8 @@ 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);
|
||||
} else { // promote new faction 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());
|
||||
}
|
||||
@@ -568,8 +537,7 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -590,19 +558,15 @@ 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;
|
||||
}
|
||||
|
||||
@@ -610,21 +574,15 @@ 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) {
|
||||
@@ -632,29 +590,23 @@ 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) {
|
||||
// in own faction, with sufficient role or permission to bypass ownership?
|
||||
if (fplayer.getFaction() == this
|
||||
&& (fplayer.getRole().isAtLeast(Conf.ownedAreaModeratorsBypass ? Role.MODERATOR : Role.ADMIN)
|
||||
|| Permission.OWNERSHIP_BYPASS.has(fplayer.getPlayer()))) {
|
||||
if (fplayer.getFaction() == this && (fplayer.getRole().isAtLeast(Conf.ownedAreaModeratorsBypass ? Role.MODERATOR : Role.ADMIN) || Permission.OWNERSHIP_BYPASS.has(fplayer.getPlayer()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user