More reformatting

This commit is contained in:
drtshock
2014-07-01 14:52:40 -05:00
parent dc54f78cc1
commit 5066934a95
109 changed files with 1288 additions and 2883 deletions

View File

@@ -44,8 +44,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public Faction getFaction() {
if (this.factionId == null) {
return null;
}
return Factions.i.get(this.factionId);
} return Factions.i.get(this.factionId);
}
public String getFactionId() {
@@ -57,10 +56,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
}
public void setFaction(Faction faction) {
Faction oldFaction = this.getFaction();
if (oldFaction != null) { oldFaction.removeFPlayer(this); }
faction.addFPlayer(this);
this.factionId = faction.getId();
Faction oldFaction = this.getFaction(); if (oldFaction != null) { oldFaction.removeFPlayer(this); }
faction.addFPlayer(this); this.factionId = faction.getId();
}
// FIELD: role
@@ -109,11 +106,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
}
public void setAutoClaimFor(Faction faction) {
this.autoClaimFor = faction;
if (this.autoClaimFor != null) {
this.autoClaimFor = faction; if (this.autoClaimFor != null) {
// TODO: merge these into same autoclaim
this.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = false;
this.autoSafeZoneEnabled = false; this.autoWarZoneEnabled = false;
}
}
@@ -125,10 +120,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
}
public void setIsAutoSafeClaimEnabled(boolean enabled) {
this.autoSafeZoneEnabled = enabled;
if (enabled) {
this.autoClaimFor = null;
this.autoWarZoneEnabled = false;
this.autoSafeZoneEnabled = enabled; if (enabled) {
this.autoClaimFor = null; this.autoWarZoneEnabled = false;
}
}
@@ -140,10 +133,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
}
public void setIsAutoWarClaimEnabled(boolean enabled) {
this.autoWarZoneEnabled = enabled;
if (enabled) {
this.autoClaimFor = null;
this.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = enabled; if (enabled) {
this.autoClaimFor = null; this.autoSafeZoneEnabled = false;
}
}
@@ -173,8 +164,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public ChatMode getChatMode() {
if (this.factionId.equals("0") || !Conf.factionOnlyChat) {
this.chatMode = ChatMode.PUBLIC;
}
return chatMode;
} return chatMode;
}
// FIELD: chatSpy
@@ -199,17 +189,12 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
// GSON need this noarg constructor.
public FPlayer() {
this.resetFactionData(false);
this.power = Conf.powerPlayerStarting;
this.lastPowerUpdateTime = System.currentTimeMillis();
this.lastLoginTime = System.currentTimeMillis();
this.mapAutoUpdating = false;
this.autoClaimFor = null;
this.autoSafeZoneEnabled = false;
this.resetFactionData(false); this.power = Conf.powerPlayerStarting;
this.lastPowerUpdateTime = System.currentTimeMillis(); this.lastLoginTime = System.currentTimeMillis();
this.mapAutoUpdating = false; this.autoClaimFor = null; this.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = false;
this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false;
this.deleteMe = false;
this.powerBoost = 0.0;
this.deleteMe = false; this.powerBoost = 0.0;
if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.i.exists(Conf.newPlayerStartingFactionID)) {
this.factionId = Conf.newPlayerStartingFactionID;
@@ -219,18 +204,14 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public final void resetFactionData(boolean doSpoutUpdate) {
// clean up any territory ownership in old faction, if there is one
if (Factions.i.exists(this.getFactionId())) {
Faction currentFaction = this.getFaction();
currentFaction.removeFPlayer(this);
Faction currentFaction = this.getFaction(); currentFaction.removeFPlayer(this);
if (currentFaction.isNormal()) {
currentFaction.clearClaimOwnership(this);
}
}
this.factionId = "0"; // The default neutral faction
this.chatMode = ChatMode.PUBLIC;
this.role = Role.NORMAL;
this.title = "";
this.autoClaimFor = null;
this.chatMode = ChatMode.PUBLIC; this.role = Role.NORMAL; this.title = ""; this.autoClaimFor = null;
}
public void resetFactionData() {
@@ -248,9 +229,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public void setLastLoginTime(long lastLoginTime) {
losePowerFromBeingOffline();
this.lastLoginTime = lastLoginTime;
this.lastPowerUpdateTime = lastLoginTime;
losePowerFromBeingOffline(); this.lastLoginTime = lastLoginTime; this.lastPowerUpdateTime = lastLoginTime;
if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) {
this.loginPvpDisabled = true;
}
@@ -269,10 +248,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
return false;
}
if (this.lastLoginTime + (Conf.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis()) {
this.loginPvpDisabled = false;
return false;
}
return true;
this.loginPvpDisabled = false; return false;
} return true;
}
public FLocation getLastStoodAt() {
@@ -304,27 +281,22 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public String getName() {
if (isOnline()) {
return getPlayer().getName();
}
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(getId()));
} OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(getId()));
return player.getName() != null ? player.getName() : getId();
}
public String getTag() {
if (!this.hasFaction()) {
return "";
}
return this.getFaction().getTag();
} return this.getFaction().getTag();
}
// Base concatenations:
public String getNameAndSomething(String something) {
String ret = this.role.getPrefix();
if (something.length() > 0) {
String ret = this.role.getPrefix(); if (something.length() > 0) {
ret += something + " ";
}
ret += this.getName();
return ret;
} ret += this.getName(); return ret;
}
public String getNameAndTitle() {
@@ -440,11 +412,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
// Health
//----------------------------------------------//
public void heal(int amnt) {
Player player = this.getPlayer();
if (player == null) {
Player player = this.getPlayer(); if (player == null) {
return;
}
player.setHealth(player.getHealth() + amnt);
} player.setHealth(player.getHealth() + amnt);
}
@@ -452,14 +422,13 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
// Power
//----------------------------------------------//
public double getPower() {
this.updatePower();
return this.power;
this.updatePower(); return this.power;
}
protected void alterPower(double delta) {
this.power += delta;
if (this.power > this.getPowerMax()) { this.power = this.getPowerMax(); }
else if (this.power < this.getPowerMin()) { this.power = this.getPowerMin(); }
this.power += delta; if (this.power > this.getPowerMax()) {
this.power = this.getPowerMax();
} else if (this.power < this.getPowerMin()) { this.power = this.getPowerMin(); }
}
public double getPowerMax() {
@@ -484,41 +453,33 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
protected void updatePower() {
if (this.isOffline()) {
losePowerFromBeingOffline();
if (!Conf.powerRegenOffline) {
losePowerFromBeingOffline(); if (!Conf.powerRegenOffline) {
return;
}
}
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
} long now = System.currentTimeMillis(); long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now;
Player thisPlayer = this.getPlayer();
if (thisPlayer != null && thisPlayer.isDead()) {
Player thisPlayer = this.getPlayer(); if (thisPlayer != null && thisPlayer.isDead()) {
return; // don't let dead players regain power until they respawn
}
int millisPerMinute = 60 * 1000;
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
int millisPerMinute = 60 * 1000; this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
}
protected void losePowerFromBeingOffline() {
if (Conf.powerOfflineLossPerDay > 0.0 && this.power > Conf.powerOfflineLossLimit) {
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
long now = System.currentTimeMillis(); long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now;
double loss = millisPassed * Conf.powerOfflineLossPerDay / (24 * 60 * 60 * 1000);
if (this.power - loss < Conf.powerOfflineLossLimit) {
loss = this.power;
}
this.alterPower(-loss);
} this.alterPower(-loss);
}
}
public void onDeath() {
this.updatePower();
this.alterPower(-Conf.powerPerDeath);
this.updatePower(); this.alterPower(-Conf.powerPerDeath);
}
//----------------------------------------------//
@@ -550,8 +511,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
String msg = P.p.txt.parse("<i>") + " ~ " + factionHere.getTag(this);
if (factionHere.getDescription().length() > 0) {
msg += " - " + factionHere.getDescription();
}
this.sendMessage(msg);
} this.sendMessage(msg);
}
// -------------------------------
@@ -559,32 +519,27 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
// -------------------------------
public void leave(boolean makePay) {
Faction myFaction = this.getFaction();
makePay = makePay && Econ.shouldBeUsed() && !this.isAdminBypassing();
Faction myFaction = this.getFaction(); makePay = makePay && Econ.shouldBeUsed() && !this.isAdminBypassing();
if (myFaction == null) {
resetFactionData();
return;
resetFactionData(); return;
}
boolean perm = myFaction.isPermanent();
if (!perm && this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1) {
msg("<b>You must give the admin role to someone else first.");
return;
msg("<b>You must give the admin role to someone else first."); return;
}
if (!Conf.canLeaveWithNegativePower && this.getPower() < 0) {
msg("<b>You cannot leave until your power is positive.");
return;
msg("<b>You cannot leave until your power is positive."); return;
}
// if economy is enabled and they're not on the bypass list, make sure they can pay
if (makePay && !Econ.hasAtLeast(this, Conf.econCostLeave, "to leave your faction.")) { return; }
FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.LEAVE);
Bukkit.getServer().getPluginManager().callEvent(leaveEvent);
if (leaveEvent.isCancelled()) { return; }
Bukkit.getServer().getPluginManager().callEvent(leaveEvent); if (leaveEvent.isCancelled()) { return; }
// then make 'em pay (if applicable)
if (makePay && !Econ.modifyMoney(this, -Conf.econCostLeave, "to leave your faction.", "for leaving your faction.")) {
@@ -615,8 +570,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
fplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(fplayer, true));
}
myFaction.detach();
if (Conf.logFactionDisband) {
myFaction.detach(); if (Conf.logFactionDisband) {
P.p.log("The faction " + myFaction.getTag() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving.");
}
}
@@ -625,10 +579,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public boolean canClaimForFaction(Faction forFaction) {
if (forFaction.isNone()) { return false; }
if (this.isAdminBypassing()
|| (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR))
|| (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer()))
|| (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))) {
if (this.isAdminBypassing() || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))) {
return true;
}
@@ -636,95 +587,67 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
}
public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) {
String error = null;
FLocation flocation = new FLocation(location);
Faction myFaction = getFaction();
Faction currentFaction = Board.getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded();
String error = null; FLocation flocation = new FLocation(location); Faction myFaction = getFaction();
Faction currentFaction = Board.getFactionAt(flocation); int ownedLand = forFaction.getLandRounded();
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) {
// Checks for WorldGuard regions in the chunk attempting to be claimed
error = P.p.txt.parse("<b>This land is protected");
}
else if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) {
} else if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) {
error = P.p.txt.parse("<b>Sorry, this world has land claiming disabled.");
}
else if (this.isAdminBypassing()) {
} else if (this.isAdminBypassing()) {
return true;
}
else if (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) {
} else if (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) {
return true;
}
else if (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer())) {
} else if (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer())) {
return true;
}
else if (myFaction != forFaction) {
} else if (myFaction != forFaction) {
error = P.p.txt.parse("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(this));
}
else if (forFaction == currentFaction) {
} else if (forFaction == currentFaction) {
error = P.p.txt.parse("%s<i> already own this land.", forFaction.describeTo(this, true));
}
else if (this.getRole().value < Role.MODERATOR.value) {
} else if (this.getRole().value < Role.MODERATOR.value) {
error = P.p.txt.parse("<b>You must be <h>%s<b> to claim land.", Role.MODERATOR.toString());
}
else if (forFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers) {
} else if (forFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers) {
error = P.p.txt.parse("Factions must have at least <h>%s<b> members to claim land.", Conf.claimsRequireMinFactionMembers);
}
else if (currentFaction.isSafeZone()) {
} else if (currentFaction.isSafeZone()) {
error = P.p.txt.parse("<b>You can not claim a Safe Zone.");
}
else if (currentFaction.isWarZone()) {
} else if (currentFaction.isWarZone()) {
error = P.p.txt.parse("<b>You can not claim a War Zone.");
}
else if (ownedLand >= forFaction.getPowerRounded()) {
} else if (ownedLand >= forFaction.getPowerRounded()) {
error = P.p.txt.parse("<b>You can't claim more land! You need more power!");
}
else if (Conf.claimedLandsMax != 0 && ownedLand >= Conf.claimedLandsMax && forFaction.isNormal()) {
} else if (Conf.claimedLandsMax != 0 && ownedLand >= Conf.claimedLandsMax && forFaction.isNormal()) {
error = P.p.txt.parse("<b>Limit reached. You can't claim more land!");
}
else if (currentFaction.getRelationTo(forFaction) == Relation.ALLY) {
} else if (currentFaction.getRelationTo(forFaction) == Relation.ALLY) {
error = P.p.txt.parse("<b>You can't claim the land of your allies.");
}
else if (Conf.claimsMustBeConnected
&& !this.isAdminBypassing()
&& myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0
&& !Board.isConnectedLocation(flocation, myFaction)
&& (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())) {
} else if (Conf.claimsMustBeConnected && !this.isAdminBypassing() && myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, myFaction) && (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())) {
if (Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction) {
error = P.p.txt.parse("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
}
else {
} else {
error = P.p.txt.parse("<b>You can only claim additional land which is connected to your first claim!");
}
}
else if (currentFaction.isNormal()) {
} else if (currentFaction.isNormal()) {
if (myFaction.isPeaceful()) {
error = P.p.txt.parse("%s<i> owns this land. Your faction is peaceful, so you cannot claim land from other factions.", currentFaction.getTag(this));
}
else if (currentFaction.isPeaceful()) {
} else if (currentFaction.isPeaceful()) {
error = P.p.txt.parse("%s<i> owns this land, and is a peaceful faction. You cannot claim land from them.", currentFaction.getTag(this));
}
else if (!currentFaction.hasLandInflation()) {
} else if (!currentFaction.hasLandInflation()) {
// TODO more messages WARN current faction most importantly
error = P.p.txt.parse("%s<i> owns this land and is strong enough to keep it.", currentFaction.getTag(this));
}
else if (!Board.isBorderLocation(flocation)) {
} else if (!Board.isBorderLocation(flocation)) {
error = P.p.txt.parse("<b>You must start claiming land at the border of the territory.");
}
}
if (notifyFailure && error != null) {
msg(error);
}
return error == null;
} return error == null;
}
public boolean attemptClaim(Faction forFaction, Location location, boolean notifyFailure) {
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
// return value is false on failure, true on success
FLocation flocation = new FLocation(location);
Faction currentFaction = Board.getFactionAt(flocation);
FLocation flocation = new FLocation(location); Faction currentFaction = Board.getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded();
@@ -732,24 +655,22 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
// if economy is enabled and they're not on the bypass list, make sure they can pay
boolean mustPay = Econ.shouldBeUsed() && !this.isAdminBypassing() && !forFaction.isSafeZone() && !forFaction.isWarZone();
double cost = 0.0;
EconomyParticipator payee = null;
if (mustPay) {
double cost = 0.0; EconomyParticipator payee = null; if (mustPay) {
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (Conf.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, forFaction)) {
cost += Conf.econClaimUnconnectedFee;
}
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts && this.hasFaction()) { payee = this.getFaction(); }
else { payee = this; }
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts && this.hasFaction()) {
payee = this.getFaction();
} else { payee = this; }
if (!Econ.hasAtLeast(payee, cost, "to claim this land")) { return false; }
}
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this);
Bukkit.getServer().getPluginManager().callEvent(claimEvent);
if (claimEvent.isCancelled()) { return false; }
Bukkit.getServer().getPluginManager().callEvent(claimEvent); if (claimEvent.isCancelled()) { return false; }
// then make 'em pay (if applicable)
if (mustPay && !Econ.modifyMoney(payee, -cost, "to claim this land", "for claiming this land")) {
@@ -757,10 +678,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
}
// announce success
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>();
informTheseFPlayers.add(this);
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true));
for (FPlayer fp : informTheseFPlayers) {
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>(); informTheseFPlayers.add(this);
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true)); for (FPlayer fp : informTheseFPlayers) {
fp.msg("<h>%s<i> claimed land for <h>%s<i> from <h>%s<i>.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
}
@@ -781,8 +700,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public boolean shouldBeSaved() {
if (!this.hasFaction() && (this.getPowerRounded() == this.getPowerMaxRounded() || this.getPowerRounded() == (int) Math.round(Conf.powerPlayerStarting))) {
return false;
}
return !this.deleteMe;
} return !this.deleteMe;
}
public void msg(String str, Object... args) {