Some reformat

This commit is contained in:
drtshock 2014-07-01 14:49:42 -05:00
parent 955958ce61
commit dc54f78cc1
83 changed files with 883 additions and 800 deletions

View File

@ -173,33 +173,39 @@ public class Board {
for (int dx = 0; dx < width; dx++) { for (int dx = 0; dx < width; dx++) {
if (dx == halfWidth && dz == halfHeight) { if (dx == halfWidth && dz == halfHeight) {
row += ChatColor.AQUA + "+"; row += ChatColor.AQUA + "+";
} else { }
else {
FLocation flocationHere = topLeft.getRelative(dx, dz); FLocation flocationHere = topLeft.getRelative(dx, dz);
Faction factionHere = getFactionAt(flocationHere); Faction factionHere = getFactionAt(flocationHere);
Relation relation = faction.getRelationTo(factionHere); Relation relation = faction.getRelationTo(factionHere);
if (factionHere.isNone()) { if (factionHere.isNone()) {
row += ChatColor.GRAY + "-"; row += ChatColor.GRAY + "-";
} else if (factionHere.isSafeZone()) { }
else if (factionHere.isSafeZone()) {
row += Conf.colorPeaceful + "+"; row += Conf.colorPeaceful + "+";
} else if (factionHere.isWarZone()) { }
else if (factionHere.isWarZone()) {
row += ChatColor.DARK_RED + "+"; row += ChatColor.DARK_RED + "+";
} else if }
( else if
factionHere == faction (
|| factionHere == faction
factionHere == factionLoc ||
|| factionHere == factionLoc
relation.isAtLeast(Relation.ALLY) ||
|| relation.isAtLeast(Relation.ALLY)
(Conf.showNeutralFactionsOnMap && relation.equals(Relation.NEUTRAL)) ||
|| (Conf.showNeutralFactionsOnMap && relation.equals(Relation.NEUTRAL))
(Conf.showEnemyFactionsOnMap && relation.equals(Relation.ENEMY)) ||
) { (Conf.showEnemyFactionsOnMap && relation.equals(Relation.ENEMY))
if (!fList.containsKey(factionHere.getTag())) ) {
if (!fList.containsKey(factionHere.getTag())) {
fList.put(factionHere.getTag(), Conf.mapKeyChrs[chrIdx++]); fList.put(factionHere.getTag(), Conf.mapKeyChrs[chrIdx++]);
}
char tag = fList.get(factionHere.getTag()); char tag = fList.get(factionHere.getTag());
row += factionHere.getColorTo(faction) + "" + tag; row += factionHere.getColorTo(faction) + "" + tag;
} else { }
else {
row += ChatColor.GRAY + "-"; row += ChatColor.GRAY + "-";
} }
} }

View File

@ -136,7 +136,7 @@ public class FLocation {
//----------------------------------------------// //----------------------------------------------//
public Set<FLocation> getCircle(double radius) { public Set<FLocation> getCircle(double radius) {
Set<FLocation> ret = new LinkedHashSet<FLocation>(); Set<FLocation> ret = new LinkedHashSet<FLocation>();
if (radius <= 0) return ret; if (radius <= 0) { return ret; }
int xfrom = (int) Math.floor(this.x - radius); int xfrom = (int) Math.floor(this.x - radius);
int xto = (int) Math.ceil(this.x + radius); int xto = (int) Math.ceil(this.x + radius);
@ -146,8 +146,7 @@ public class FLocation {
for (int x = xfrom; x <= xto; x++) { for (int x = xfrom; x <= xto; x++) {
for (int z = zfrom; z <= zto; z++) { for (int z = zfrom; z <= zto; z++) {
FLocation potential = new FLocation(this.worldName, x, z); FLocation potential = new FLocation(this.worldName, x, z);
if (this.getDistanceTo(potential) <= radius) if (this.getDistanceTo(potential) <= radius) { ret.add(potential); }
ret.add(potential);
} }
} }
@ -178,10 +177,8 @@ public class FLocation {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == this) if (obj == this) { return true; }
return true; if (!(obj instanceof FLocation)) { return false; }
if (!(obj instanceof FLocation))
return false;
FLocation that = (FLocation) obj; FLocation that = (FLocation) obj;
return this.x == that.x && this.z == that.z && (this.worldName == null ? that.worldName == null : this.worldName.equals(that.worldName)); return this.x == that.x && this.z == that.z && (this.worldName == null ? that.worldName == null : this.worldName.equals(that.worldName));

View File

@ -58,7 +58,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
public void setFaction(Faction faction) { public void setFaction(Faction faction) {
Faction oldFaction = this.getFaction(); Faction oldFaction = this.getFaction();
if (oldFaction != null) oldFaction.removeFPlayer(this); if (oldFaction != null) { oldFaction.removeFPlayer(this); }
faction.addFPlayer(this); faction.addFPlayer(this);
this.factionId = faction.getId(); this.factionId = faction.getId();
} }
@ -458,10 +458,8 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
protected void alterPower(double delta) { protected void alterPower(double delta) {
this.power += delta; this.power += delta;
if (this.power > this.getPowerMax()) if (this.power > this.getPowerMax()) { this.power = this.getPowerMax(); }
this.power = this.getPowerMax(); else if (this.power < this.getPowerMin()) { this.power = this.getPowerMin(); }
else if (this.power < this.getPowerMin())
this.power = this.getPowerMin();
} }
public double getPowerMax() { public double getPowerMax() {
@ -496,8 +494,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
this.lastPowerUpdateTime = now; this.lastPowerUpdateTime = now;
Player thisPlayer = this.getPlayer(); Player thisPlayer = this.getPlayer();
if (thisPlayer != null && thisPlayer.isDead()) if (thisPlayer != null && thisPlayer.isDead()) {
return; // don't let dead players regain power until they respawn return; // don't let dead players regain power until they respawn
}
int millisPerMinute = 60 * 1000; int millisPerMinute = 60 * 1000;
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute); this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
@ -581,21 +580,23 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
} }
// if economy is enabled and they're not on the bypass list, make sure they can pay // 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; if (makePay && !Econ.hasAtLeast(this, Conf.econCostLeave, "to leave your faction.")) { return; }
FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.LEAVE); FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.LEAVE);
Bukkit.getServer().getPluginManager().callEvent(leaveEvent); Bukkit.getServer().getPluginManager().callEvent(leaveEvent);
if (leaveEvent.isCancelled()) return; if (leaveEvent.isCancelled()) { return; }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (makePay && !Econ.modifyMoney(this, -Conf.econCostLeave, "to leave your faction.", "for leaving your faction.")) if (makePay && !Econ.modifyMoney(this, -Conf.econCostLeave, "to leave your faction.", "for leaving your faction.")) {
return; return;
}
// Am I the last one in the faction? // Am I the last one in the faction?
if (myFaction.getFPlayers().size() == 1) { if (myFaction.getFPlayers().size() == 1) {
// Transfer all money // Transfer all money
if (Econ.shouldBeUsed()) if (Econ.shouldBeUsed()) {
Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId())); Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId()));
}
} }
if (myFaction.isNormal()) { if (myFaction.isNormal()) {
@ -603,8 +604,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
fplayer.msg("%s<i> left %s<i>.", this.describeTo(fplayer, true), myFaction.describeTo(fplayer)); fplayer.msg("%s<i> left %s<i>.", this.describeTo(fplayer, true), myFaction.describeTo(fplayer));
} }
if (Conf.logFactionLeave) if (Conf.logFactionLeave) { P.p.log(this.getName() + " left the faction: " + myFaction.getTag()); }
P.p.log(this.getName() + " left the faction: " + myFaction.getTag());
} }
this.resetFactionData(); this.resetFactionData();
@ -616,18 +616,19 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
} }
myFaction.detach(); myFaction.detach();
if (Conf.logFactionDisband) if (Conf.logFactionDisband) {
P.p.log("The faction " + myFaction.getTag() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving."); P.p.log("The faction " + myFaction.getTag() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving.");
}
} }
} }
public boolean canClaimForFaction(Faction forFaction) { public boolean canClaimForFaction(Faction forFaction) {
if (forFaction.isNone()) return false; if (forFaction.isNone()) { return false; }
if (this.isAdminBypassing() if (this.isAdminBypassing()
|| (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR))
|| (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer()))
|| (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))) { || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))) {
return true; return true;
} }
@ -644,50 +645,70 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) { if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) {
// Checks for WorldGuard regions in the chunk attempting to be claimed // Checks for WorldGuard regions in the chunk attempting to be claimed
error = P.p.txt.parse("<b>This land is protected"); 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."); error = P.p.txt.parse("<b>Sorry, this world has land claiming disabled.");
} else if (this.isAdminBypassing()) { }
else if (this.isAdminBypassing()) {
return true; return true;
} else if (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) { }
else if (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) {
return true; return true;
} else if (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer())) { }
else if (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer())) {
return true; 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)); 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)); 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()); 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); 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."); 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."); 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!"); 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!"); 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."); error = P.p.txt.parse("<b>You can't claim the land of your allies.");
} else if (Conf.claimsMustBeConnected }
&& !this.isAdminBypassing() else if (Conf.claimsMustBeConnected
&& myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !this.isAdminBypassing()
&& !Board.isConnectedLocation(flocation, myFaction) && myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0
&& (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())) { && !Board.isConnectedLocation(flocation, myFaction)
if (Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction) && (!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!"); 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!"); 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()) { 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)); 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)); 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 // 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)); 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."); error = P.p.txt.parse("<b>You must start claiming land at the border of the territory.");
} }
} }
@ -707,7 +728,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
int ownedLand = forFaction.getLandRounded(); int ownedLand = forFaction.getLandRounded();
if (!this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) return false; if (!this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) { return false; }
// if economy is enabled and they're not on the bypass list, make sure they can pay // 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(); boolean mustPay = Econ.shouldBeUsed() && !this.isAdminBypassing() && !forFaction.isSafeZone() && !forFaction.isWarZone();
@ -716,23 +737,24 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
if (mustPay) { if (mustPay) {
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (Conf.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, forFaction)) if (Conf.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, forFaction)) {
cost += Conf.econClaimUnconnectedFee; cost += Conf.econClaimUnconnectedFee;
}
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts && this.hasFaction()) if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts && this.hasFaction()) { payee = this.getFaction(); }
payee = this.getFaction(); else { payee = this; }
else
payee = this;
if (!Econ.hasAtLeast(payee, cost, "to claim this land")) return false; if (!Econ.hasAtLeast(payee, cost, "to claim this land")) { return false; }
} }
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this); LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this);
Bukkit.getServer().getPluginManager().callEvent(claimEvent); Bukkit.getServer().getPluginManager().callEvent(claimEvent);
if (claimEvent.isCancelled()) return false; if (claimEvent.isCancelled()) { return false; }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (mustPay && !Econ.modifyMoney(payee, -cost, "to claim this land", "for claiming this land")) return false; if (mustPay && !Econ.modifyMoney(payee, -cost, "to claim this land", "for claiming this land")) {
return false;
}
// announce success // announce success
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>(); Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>();
@ -744,8 +766,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
Board.setFactionAt(forFaction, flocation); Board.setFactionAt(forFaction, flocation);
if (Conf.logLandClaims) if (Conf.logLandClaims) {
P.p.log(this.getName() + " claimed land at (" + flocation.getCoordString() + ") for the faction: " + forFaction.getTag()); P.p.log(this.getName() + " claimed land at (" + flocation.getCoordString() + ") for the faction: " + forFaction.getTag());
}
return true; return true;
} }
@ -756,8 +779,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
@Override @Override
public boolean shouldBeSaved() { public boolean shouldBeSaved() {
if (!this.hasFaction() && (this.getPowerRounded() == this.getPowerMaxRounded() || this.getPowerRounded() == (int) Math.round(Conf.powerPlayerStarting))) if (!this.hasFaction() && (this.getPowerRounded() == this.getPowerMaxRounded() || this.getPowerRounded() == (int) Math.round(Conf.powerPlayerStarting))) {
return false; return false;
}
return !this.deleteMe; return !this.deleteMe;
} }

View File

@ -165,8 +165,9 @@ public class Faction extends Entity implements EconomyParticipator {
} }
public void confirmValidHome() { public void confirmValidHome() {
if (!Conf.homesMustBeInClaimedTerritory || this.home == null || (this.home.getLocation() != null && Board.getFactionAt(new FLocation(this.home.getLocation())) == this)) if (!Conf.homesMustBeInClaimedTerritory || this.home == null || (this.home.getLocation() != null && Board.getFactionAt(new FLocation(this.home.getLocation())) == this)) {
return; return;
}
msg("<b>Your faction home has been un-set since it is no longer in your territory."); msg("<b>Your faction home has been un-set since it is no longer in your territory.");
this.home = null; this.home = null;
@ -183,8 +184,7 @@ public class Faction extends Entity implements EconomyParticipator {
String aid = "faction-" + this.getId(); String aid = "faction-" + this.getId();
// We need to override the default money given to players. // We need to override the default money given to players.
if (!Econ.hasAccount(aid)) if (!Econ.hasAccount(aid)) { Econ.setBalance(aid, 0); }
Econ.setBalance(aid, 0);
return aid; return aid;
} }
@ -312,7 +312,8 @@ public class Faction extends Entity implements EconomyParticipator {
public void setRelationWish(Faction otherFaction, Relation relation) { public void setRelationWish(Faction otherFaction, Relation relation) {
if (this.relationWish.containsKey(otherFaction.getId()) && relation.equals(Relation.NEUTRAL)) { if (this.relationWish.containsKey(otherFaction.getId()) && relation.equals(Relation.NEUTRAL)) {
this.relationWish.remove(otherFaction.getId()); this.relationWish.remove(otherFaction.getId());
} else { }
else {
this.relationWish.put(otherFaction.getId(), relation); this.relationWish.put(otherFaction.getId(), relation);
} }
} }
@ -377,7 +378,7 @@ public class Faction extends Entity implements EconomyParticipator {
// maintain the reference list of FPlayers in this faction // maintain the reference list of FPlayers in this faction
public void refreshFPlayers() { public void refreshFPlayers() {
fplayers.clear(); fplayers.clear();
if (this.isPlayerFreeType()) return; if (this.isPlayerFreeType()) { return; }
for (FPlayer fplayer : FPlayers.i.get()) { for (FPlayer fplayer : FPlayers.i.get()) {
if (fplayer.getFaction() == this) { if (fplayer.getFaction() == this) {
@ -387,13 +388,13 @@ public class Faction extends Entity implements EconomyParticipator {
} }
protected boolean addFPlayer(FPlayer fplayer) { protected boolean addFPlayer(FPlayer fplayer) {
if (this.isPlayerFreeType()) return false; if (this.isPlayerFreeType()) { return false; }
return fplayers.add(fplayer); return fplayers.add(fplayer);
} }
protected boolean removeFPlayer(FPlayer fplayer) { protected boolean removeFPlayer(FPlayer fplayer) {
if (this.isPlayerFreeType()) return false; if (this.isPlayerFreeType()) { return false; }
return fplayers.remove(fplayer); return fplayers.remove(fplayer);
} }
@ -417,7 +418,7 @@ public class Faction extends Entity implements EconomyParticipator {
} }
public FPlayer getFPlayerAdmin() { public FPlayer getFPlayerAdmin() {
if (!this.isNormal()) return null; if (!this.isNormal()) { return null; }
for (FPlayer fplayer : fplayers) { for (FPlayer fplayer : fplayers) {
if (fplayer.getRole() == Role.ADMIN) { if (fplayer.getRole() == Role.ADMIN) {
@ -429,7 +430,7 @@ public class Faction extends Entity implements EconomyParticipator {
public ArrayList<FPlayer> getFPlayersWhereRole(Role role) { public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>(); ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (!this.isNormal()) return ret; if (!this.isNormal()) { return ret; }
for (FPlayer fplayer : fplayers) { for (FPlayer fplayer : fplayers) {
if (fplayer.getRole() == role) { if (fplayer.getRole() == role) {
@ -442,7 +443,7 @@ public class Faction extends Entity implements EconomyParticipator {
public ArrayList<Player> getOnlinePlayers() { public ArrayList<Player> getOnlinePlayers() {
ArrayList<Player> ret = new ArrayList<Player>(); ArrayList<Player> ret = new ArrayList<Player>();
if (this.isPlayerFreeType()) return ret; if (this.isPlayerFreeType()) { return ret; }
for (Player player : P.p.getServer().getOnlinePlayers()) { for (Player player : P.p.getServer().getOnlinePlayers()) {
FPlayer fplayer = FPlayers.i.get(player); FPlayer fplayer = FPlayers.i.get(player);
@ -457,7 +458,7 @@ public class Faction extends Entity implements EconomyParticipator {
// slightly faster check than getOnlinePlayers() if you just want to see if there are any players online // slightly faster check than getOnlinePlayers() if you just want to see if there are any players online
public boolean hasPlayersOnline() { public boolean hasPlayersOnline() {
// only real factions can have players online, not safe zone / war zone // 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()) { for (Player player : P.p.getServer().getOnlinePlayers()) {
FPlayer fplayer = FPlayers.i.get(player); FPlayer fplayer = FPlayers.i.get(player);
@ -481,35 +482,34 @@ 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 // 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() { public void promoteNewLeader() {
if (!this.isNormal()) return; if (!this.isNormal()) { return; }
if (this.isPermanent() && Conf.permanentFactionsDisableLeaderPromotion) return; if (this.isPermanent() && Conf.permanentFactionsDisableLeaderPromotion) { return; }
FPlayer oldLeader = this.getFPlayerAdmin(); FPlayer oldLeader = this.getFPlayerAdmin();
// get list of moderators, or list of normal members if there are no moderators // get list of moderators, or list of normal members if there are no moderators
ArrayList<FPlayer> replacements = this.getFPlayersWhereRole(Role.MODERATOR); ArrayList<FPlayer> replacements = this.getFPlayersWhereRole(Role.MODERATOR);
if (replacements == null || replacements.isEmpty()) if (replacements == null || replacements.isEmpty()) { replacements = this.getFPlayersWhereRole(Role.NORMAL); }
replacements = this.getFPlayersWhereRole(Role.NORMAL);
if (replacements == null || replacements.isEmpty()) { // faction admin is the only member; one-man faction if (replacements == null || replacements.isEmpty()) { // faction admin is the only member; one-man faction
if (this.isPermanent()) { if (this.isPermanent()) {
if (oldLeader != null) if (oldLeader != null) { oldLeader.setRole(Role.NORMAL); }
oldLeader.setRole(Role.NORMAL);
return; return;
} }
// no members left and faction isn't permanent, so disband it // no members left and faction isn't permanent, so disband it
if (Conf.logFactionDisband) if (Conf.logFactionDisband) {
P.p.log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left."); P.p.log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left.");
}
for (FPlayer fplayer : FPlayers.i.getOnline()) { for (FPlayer fplayer : FPlayers.i.getOnline()) {
fplayer.msg("The faction %s<i> was disbanded.", this.getTag(fplayer)); fplayer.msg("The faction %s<i> was disbanded.", this.getTag(fplayer));
} }
this.detach(); this.detach();
} else { // promote new faction admin }
if (oldLeader != null) else { // promote new faction admin
oldLeader.setRole(Role.NORMAL); if (oldLeader != null) { oldLeader.setRole(Role.NORMAL); }
replacements.get(0).setRole(Role.ADMIN); 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()); 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()); P.p.log("Faction " + this.getTag() + " (" + this.getId() + ") admin was removed. Replacement admin: " + replacements.get(0).getName());
@ -566,7 +566,7 @@ public class Faction extends Entity implements EconomyParticipator {
for (Entry<FLocation, Set<String>> entry : claimOwnership.entrySet()) { for (Entry<FLocation, Set<String>> entry : claimOwnership.entrySet()) {
ownerData = entry.getValue(); ownerData = entry.getValue();
if (ownerData == null) continue; if (ownerData == null) { continue; }
Iterator<String> iter = ownerData.iterator(); Iterator<String> iter = ownerData.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
@ -653,21 +653,19 @@ public class Faction extends Entity implements EconomyParticipator {
public boolean playerHasOwnershipRights(FPlayer fplayer, FLocation loc) { public boolean playerHasOwnershipRights(FPlayer fplayer, FLocation loc) {
// in own faction, with sufficient role or permission to bypass ownership? // in own faction, with sufficient role or permission to bypass ownership?
if (fplayer.getFaction() == this if (fplayer.getFaction() == this
&& (fplayer.getRole().isAtLeast(Conf.ownedAreaModeratorsBypass ? Role.MODERATOR : Role.ADMIN) && (fplayer.getRole().isAtLeast(Conf.ownedAreaModeratorsBypass ? Role.MODERATOR : Role.ADMIN)
|| Permission.OWNERSHIP_BYPASS.has(fplayer.getPlayer()))) { || Permission.OWNERSHIP_BYPASS.has(fplayer.getPlayer()))) {
return true; return true;
} }
// make sure claimOwnership is initialized // make sure claimOwnership is initialized
if (claimOwnership.isEmpty()) if (claimOwnership.isEmpty()) { return true; }
return true;
// need to check the ownership list, then // need to check the ownership list, then
Set<String> ownerData = claimOwnership.get(loc); Set<String> ownerData = claimOwnership.get(loc);
// if no owner list, owner list is empty, or player is in owner list, they're allowed // 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())) if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId())) { return true; }
return true;
return false; return false;
} }

View File

@ -33,14 +33,15 @@ public class Factions extends EntityCollection<Faction> {
@Override @Override
public boolean loadFromDisc() { public boolean loadFromDisc() {
if (!super.loadFromDisc()) return false; if (!super.loadFromDisc()) { return false; }
// Make sure the default neutral faction exists // Make sure the default neutral faction exists
if (!this.exists("0")) { if (!this.exists("0")) {
Faction faction = this.create("0"); Faction faction = this.create("0");
faction.setTag(TL.WILDERNESS.toString()); faction.setTag(TL.WILDERNESS.toString());
faction.setDescription(TL.WILDERNESS_DESCRIPTION.toString()); faction.setDescription(TL.WILDERNESS_DESCRIPTION.toString());
} else { }
else {
if (!this.get("0").getTag().equalsIgnoreCase(TL.WILDERNESS.toString())) { if (!this.get("0").getTag().equalsIgnoreCase(TL.WILDERNESS.toString())) {
get("0").setTag(TL.WILDERNESS.toString()); get("0").setTag(TL.WILDERNESS.toString());
} }
@ -54,17 +55,17 @@ public class Factions extends EntityCollection<Faction> {
Faction faction = this.create("-1"); Faction faction = this.create("-1");
faction.setTag(TL.SAFEZONE.toString()); faction.setTag(TL.SAFEZONE.toString());
faction.setDescription(TL.SAFEZONE_DESCRIPTION.toString()); faction.setDescription(TL.SAFEZONE_DESCRIPTION.toString());
} else { }
else {
if (!getSafeZone().getTag().equalsIgnoreCase(TL.SAFEZONE.toString())) { if (!getSafeZone().getTag().equalsIgnoreCase(TL.SAFEZONE.toString())) {
getSafeZone().setTag(TL.SAFEZONE.toString()); getSafeZone().setTag(TL.SAFEZONE.toString());
} }
if(!getSafeZone().getDescription().equalsIgnoreCase(TL.SAFEZONE_DESCRIPTION.toString())) { if (!getSafeZone().getDescription().equalsIgnoreCase(TL.SAFEZONE_DESCRIPTION.toString())) {
getSafeZone().setDescription(TL.SAFEZONE_DESCRIPTION.toString()); getSafeZone().setDescription(TL.SAFEZONE_DESCRIPTION.toString());
} }
// if SafeZone has old pre-1.6.0 name, rename it to remove troublesome " " // if SafeZone has old pre-1.6.0 name, rename it to remove troublesome " "
Faction faction = this.getSafeZone(); Faction faction = this.getSafeZone();
if (faction.getTag().contains(" ")) if (faction.getTag().contains(" ")) { faction.setTag(TL.SAFEZONE.toString()); }
faction.setTag(TL.SAFEZONE.toString());
} }
// Make sure the war zone faction exists // Make sure the war zone faction exists
@ -72,17 +73,17 @@ public class Factions extends EntityCollection<Faction> {
Faction faction = this.create("-2"); Faction faction = this.create("-2");
faction.setTag(TL.WARZONE.toString()); faction.setTag(TL.WARZONE.toString());
faction.setDescription(TL.WARZONE_DESCRIPTION.toString()); faction.setDescription(TL.WARZONE_DESCRIPTION.toString());
} else { }
else {
if (!getWarZone().getTag().equalsIgnoreCase(TL.WARZONE.toString())) { if (!getWarZone().getTag().equalsIgnoreCase(TL.WARZONE.toString())) {
getWarZone().setTag(TL.WARZONE.toString()); getWarZone().setTag(TL.WARZONE.toString());
} }
if(!getWarZone().getDescription().equalsIgnoreCase(TL.WARZONE_DESCRIPTION.toString())) { if (!getWarZone().getDescription().equalsIgnoreCase(TL.WARZONE_DESCRIPTION.toString())) {
getWarZone().setDescription(TL.WARZONE_DESCRIPTION.toString()); getWarZone().setDescription(TL.WARZONE_DESCRIPTION.toString());
} }
// if WarZone has old pre-1.6.0 name, rename it to remove troublesome " " // if WarZone has old pre-1.6.0 name, rename it to remove troublesome " "
Faction faction = this.getWarZone(); Faction faction = this.getWarZone();
if (faction.getTag().contains(" ")) if (faction.getTag().contains(" ")) { faction.setTag(TL.WARZONE.toString()); }
faction.setTag(TL.WARZONE.toString());
} }
// populate all faction player lists // populate all faction player lists
@ -166,7 +167,7 @@ public class Factions extends EntityCollection<Faction> {
} }
String tag = TextUtil.getBestStartWithCI(tag2faction.keySet(), searchFor); String tag = TextUtil.getBestStartWithCI(tag2faction.keySet(), searchFor);
if (tag == null) return null; if (tag == null) { return null; }
return tag2faction.get(tag); return tag2faction.get(tag);
} }

View File

@ -79,7 +79,7 @@ public class P extends MPlugin {
return; return;
} }
if (!preEnable()) return; if (!preEnable()) { return; }
this.loadSuccessful = false; this.loadSuccessful = false;
// Load Conf from disk // Load Conf from disk
@ -123,11 +123,11 @@ public class P extends MPlugin {
}.getType(); }.getType();
return new GsonBuilder() return new GsonBuilder()
.setPrettyPrinting() .setPrettyPrinting()
.disableHtmlEscaping() .disableHtmlEscaping()
.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
.registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()) .registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter())
.registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()); .registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter());
} }
@Override @Override
@ -146,7 +146,7 @@ public class P extends MPlugin {
public void startAutoLeaveTask(boolean restartIfRunning) { public void startAutoLeaveTask(boolean restartIfRunning) {
if (AutoLeaveTask != null) { if (AutoLeaveTask != null) {
if (!restartIfRunning) return; if (!restartIfRunning) { return; }
this.getServer().getScheduler().cancelTask(AutoLeaveTask); this.getServer().getScheduler().cancelTask(AutoLeaveTask);
} }
@ -169,8 +169,9 @@ public class P extends MPlugin {
@Override @Override
public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly) { public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly) {
if (sender instanceof Player && FactionsPlayerListener.preventCommand(commandString, (Player) sender)) if (sender instanceof Player && FactionsPlayerListener.preventCommand(commandString, (Player) sender)) {
return true; return true;
}
return super.handleCommand(sender, commandString, testOnly); return super.handleCommand(sender, commandString, testOnly);
} }
@ -178,7 +179,7 @@ public class P extends MPlugin {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) { public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
// if bare command at this point, it has already been handled by MPlugin's command listeners // if bare command at this point, it has already been handled by MPlugin's command listeners
if (split == null || split.length == 0) return true; if (split == null || split.length == 0) { return true; }
// otherwise, needs to be handled; presumably another plugin directly ran the command // otherwise, needs to be handled; presumably another plugin directly ran the command
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0); String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
@ -204,17 +205,17 @@ public class P extends MPlugin {
// enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand() // enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand()
public boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event) { public boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event) {
if (event == null) return false; if (event == null) { return false; }
return (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage())); return (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage()));
} }
// Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels, // Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels,
// local chat, or anything else which targets individual recipients, so Faction Chat can be done // local chat, or anything else which targets individual recipients, so Faction Chat can be done
public boolean isPlayerFactionChatting(Player player) { public boolean isPlayerFactionChatting(Player player) {
if (player == null) return false; if (player == null) { return false; }
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
if (me == null) return false; if (me == null) { return false; }
return me.getChatMode().isAtLeast(ChatMode.ALLIANCE); return me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
} }
@ -223,7 +224,7 @@ public class P extends MPlugin {
// TODO: GET THIS BACK AND WORKING // TODO: GET THIS BACK AND WORKING
public boolean isFactionsCommand(String check) { public boolean isFactionsCommand(String check) {
if (check == null || check.isEmpty()) return false; if (check == null || check.isEmpty()) { return false; }
return this.handleCommand(null, check, true); return this.handleCommand(null, check, true);
} }
@ -236,37 +237,32 @@ public class P extends MPlugin {
public String getPlayerFactionTagRelation(Player speaker, Player listener) { public String getPlayerFactionTagRelation(Player speaker, Player listener) {
String tag = "~"; String tag = "~";
if (speaker == null) if (speaker == null) { return tag; }
return tag;
FPlayer me = FPlayers.i.get(speaker); FPlayer me = FPlayers.i.get(speaker);
if (me == null) if (me == null) { return tag; }
return tag;
// if listener isn't set, or config option is disabled, give back uncolored tag // if listener isn't set, or config option is disabled, give back uncolored tag
if (listener == null || !Conf.chatTagRelationColored) { if (listener == null || !Conf.chatTagRelationColored) {
tag = me.getChatTag().trim(); tag = me.getChatTag().trim();
} else {
FPlayer you = FPlayers.i.get(listener);
if (you == null)
tag = me.getChatTag().trim();
else // everything checks out, give the colored tag
tag = me.getChatTag(you).trim();
} }
if (tag.isEmpty()) else {
tag = "~"; FPlayer you = FPlayers.i.get(listener);
if (you == null) { tag = me.getChatTag().trim(); }
else // everything checks out, give the colored tag
{ tag = me.getChatTag(you).trim(); }
}
if (tag.isEmpty()) { tag = "~"; }
return tag; return tag;
} }
// Get a player's title within their faction, mainly for usage by chat plugins for local/channel chat // Get a player's title within their faction, mainly for usage by chat plugins for local/channel chat
public String getPlayerTitle(Player player) { public String getPlayerTitle(Player player) {
if (player == null) if (player == null) { return ""; }
return "";
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
if (me == null) if (me == null) { return ""; }
return "";
return me.getTitle().trim(); return me.getTitle().trim();
} }

View File

@ -28,7 +28,7 @@ public class CmdAdmin extends FCommand {
@Override @Override
public void perform() { public void perform() {
FPlayer fyou = this.argAsBestFPlayerMatch(0); FPlayer fyou = this.argAsBestFPlayerMatch(0);
if (fyou == null) return; if (fyou == null) { return; }
boolean permAny = Permission.ADMIN_ANY.has(sender, false); boolean permAny = Permission.ADMIN_ANY.has(sender, false);
Faction targetFaction = fyou.getFaction(); Faction targetFaction = fyou.getFaction();
@ -52,7 +52,7 @@ public class CmdAdmin extends FCommand {
if (fyou.getFaction() != targetFaction) { if (fyou.getFaction() != targetFaction) {
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER); FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
} }
FPlayer admin = targetFaction.getFPlayerAdmin(); FPlayer admin = targetFaction.getFPlayerAdmin();
@ -66,8 +66,7 @@ public class CmdAdmin extends FCommand {
} }
// promote target player, and demote existing admin if one exists // promote target player, and demote existing admin if one exists
if (admin != null) if (admin != null) { admin.setRole(Role.MODERATOR); }
admin.setRole(Role.MODERATOR);
fyou.setRole(Role.ADMIN); fyou.setRole(Role.ADMIN);
msg("<i>You have promoted %s<i> to the position of faction admin.", fyou.describeTo(fme, true)); msg("<i>You have promoted %s<i> to the position of faction admin.", fyou.describeTo(fme, true));

View File

@ -31,10 +31,8 @@ public class CmdAutoClaim extends FCommand {
} }
if (!fme.canClaimForFaction(forFaction)) { if (!fme.canClaimForFaction(forFaction)) {
if (myFaction == forFaction) if (myFaction == forFaction) { msg("<b>You must be <h>%s<b> to claim land.", Role.MODERATOR.toString()); }
msg("<b>You must be <h>%s<b> to claim land.", Role.MODERATOR.toString()); else { msg("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(fme)); }
else
msg("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(fme));
return; return;
} }

View File

@ -20,7 +20,7 @@ public class CmdAutoHelp extends MCommand<P> {
@Override @Override
public void perform() { public void perform() {
if (this.commandChain.size() == 0) return; if (this.commandChain.size() == 0) { return; }
MCommand<?> pcmd = this.commandChain.get(this.commandChain.size() - 1); MCommand<?> pcmd = this.commandChain.get(this.commandChain.size() - 1);
ArrayList<String> lines = new ArrayList<String>(); ArrayList<String> lines = new ArrayList<String>();

View File

@ -28,7 +28,7 @@ public class CmdBoom extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostNoBoom, "to toggle explosions", "for toggling explosions")) return; if (!payForCommand(Conf.econCostNoBoom, "to toggle explosions", "for toggling explosions")) { return; }
myFaction.setPeacefulExplosionsEnabled(this.argAsBool(0, !myFaction.getPeacefulExplosionsEnabled())); myFaction.setPeacefulExplosionsEnabled(this.argAsBool(0, !myFaction.getPeacefulExplosionsEnabled()));

View File

@ -28,7 +28,8 @@ public class CmdBypass extends FCommand {
if (fme.isAdminBypassing()) { if (fme.isAdminBypassing()) {
fme.msg("<i>You have enabled admin bypass mode. You will be able to build or destroy anywhere."); fme.msg("<i>You have enabled admin bypass mode. You will be able to build or destroy anywhere.");
P.p.log(fme.getName() + " has ENABLED admin bypass mode."); P.p.log(fme.getName() + " has ENABLED admin bypass mode.");
} else { }
else {
fme.msg("<i>You have disabled admin bypass mode."); fme.msg("<i>You have disabled admin bypass mode.");
P.p.log(fme.getName() + " DISABLED admin bypass mode."); P.p.log(fme.getName() + " DISABLED admin bypass mode.");
} }

View File

@ -37,11 +37,14 @@ public class CmdChat extends FCommand {
modeString.toLowerCase(); modeString.toLowerCase();
if (modeString.startsWith("p")) { if (modeString.startsWith("p")) {
modeTarget = ChatMode.PUBLIC; modeTarget = ChatMode.PUBLIC;
} else if (modeString.startsWith("a")) { }
else if (modeString.startsWith("a")) {
modeTarget = ChatMode.ALLIANCE; modeTarget = ChatMode.ALLIANCE;
} else if (modeString.startsWith("f")) { }
else if (modeString.startsWith("f")) {
modeTarget = ChatMode.FACTION; modeTarget = ChatMode.FACTION;
} else { }
else {
msg("<b>Unrecognised chat mode. <i>Please enter either 'a','f' or 'p'"); msg("<b>Unrecognised chat mode. <i>Please enter either 'a','f' or 'p'");
return; return;
} }
@ -51,9 +54,11 @@ public class CmdChat extends FCommand {
if (fme.getChatMode() == ChatMode.PUBLIC) { if (fme.getChatMode() == ChatMode.PUBLIC) {
msg("<i>Public chat mode."); msg("<i>Public chat mode.");
} else if (fme.getChatMode() == ChatMode.ALLIANCE) { }
else if (fme.getChatMode() == ChatMode.ALLIANCE) {
msg("<i>Alliance only chat mode."); msg("<i>Alliance only chat mode.");
} else { }
else {
msg("<i>Faction only chat mode."); msg("<i>Faction only chat mode.");
} }
} }

View File

@ -26,7 +26,8 @@ public class CmdChatSpy extends FCommand {
if (fme.isSpyingChat()) { if (fme.isSpyingChat()) {
fme.msg("<i>You have enabled chat spying mode."); fme.msg("<i>You have enabled chat spying mode.");
P.p.log(fme.getName() + " has ENABLED chat spying mode."); P.p.log(fme.getName() + " has ENABLED chat spying mode.");
} else { }
else {
fme.msg("<i>You have disabled chat spying mode."); fme.msg("<i>You have disabled chat spying mode.");
P.p.log(fme.getName() + " DISABLED chat spying mode."); P.p.log(fme.getName() + " DISABLED chat spying mode.");
} }

View File

@ -40,7 +40,8 @@ public class CmdClaim extends FCommand {
if (radius < 2) { if (radius < 2) {
// single chunk // single chunk
fme.attemptClaim(forFaction, me.getLocation(), true); fme.attemptClaim(forFaction, me.getLocation(), true);
} else { }
else {
// radius claim // radius claim
if (!Permission.CLAIM_RADIUS.has(sender, false)) { if (!Permission.CLAIM_RADIUS.has(sender, false)) {
msg("<b>You do not have permission to claim in a radius."); msg("<b>You do not have permission to claim in a radius.");
@ -54,8 +55,7 @@ public class CmdClaim extends FCommand {
@Override @Override
public boolean work() { public boolean work() {
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true); boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
if (success) if (success) { failCount = 0; }
failCount = 0;
else if (!success && failCount++ >= limit) { else if (!success && failCount++ >= limit) {
this.stop(); this.stop();
return false; return false;

View File

@ -72,7 +72,8 @@ public class CmdConfig extends FCommand {
if (targetValue) { if (targetValue) {
success = "\"" + fieldName + "\" option set to true (enabled)."; success = "\"" + fieldName + "\" option set to true (enabled).";
} else { }
else {
success = "\"" + fieldName + "\" option set to false (disabled)."; success = "\"" + fieldName + "\" option set to false (disabled).";
} }
} }
@ -231,8 +232,9 @@ public class CmdConfig extends FCommand {
if (sender instanceof Player) { if (sender instanceof Player) {
sendMessage(success); sendMessage(success);
P.p.log(success + " Command was run by " + fme.getName() + "."); P.p.log(success + " Command was run by " + fme.getName() + ".");
} else // using P.p.log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log }
P.p.log(success); else // using P.p.log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log
{ P.p.log(success); }
} }
// save change to disk // save change to disk
Conf.save(); Conf.save();

View File

@ -48,15 +48,15 @@ public class CmdCreate extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostCreate, "to create a new faction")) return; if (!canAffordCommand(Conf.econCostCreate, "to create a new faction")) { return; }
// trigger the faction creation event (cancellable) // trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag); FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent); Bukkit.getServer().getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) return; if (createEvent.isCancelled()) { return; }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) return; if (!payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) { return; }
Faction faction = Factions.i.create(); Faction faction = Factions.i.create();
@ -84,8 +84,7 @@ public class CmdCreate extends FCommand {
msg("<i>You should now: %s", p.cmdBase.cmdDescription.getUseageTemplate()); msg("<i>You should now: %s", p.cmdBase.cmdDescription.getUseageTemplate());
if (Conf.logFactionCreate) if (Conf.logFactionCreate) { P.p.log(fme.getName() + " created a new faction: " + tag); }
P.p.log(fme.getName() + " created a new faction: " + tag);
} }
} }

View File

@ -25,7 +25,7 @@ public class CmdDeinvite extends FCommand {
@Override @Override
public void perform() { public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return; if (you == null) { return; }
if (you.getFaction() == myFaction) { if (you.getFaction() == myFaction) {
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag()); msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());

View File

@ -27,8 +27,9 @@ public class CmdDescription extends FCommand {
@Override @Override
public void perform() { public void perform() {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostDesc, "to change faction description", "for changing faction description")) if (!payForCommand(Conf.econCostDesc, "to change faction description", "for changing faction description")) {
return; return;
}
myFaction.setDescription(TextUtil.implode(args, " ").replaceAll("(&([a-f0-9]))", "& $2")); // since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up myFaction.setDescription(TextUtil.implode(args, " ").replaceAll("(&([a-f0-9]))", "& $2")); // since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up

View File

@ -30,13 +30,14 @@ public class CmdDisband extends FCommand {
public void perform() { public void perform() {
// The faction, default to your own.. but null if console sender. // The faction, default to your own.. but null if console sender.
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
if (faction == null) return; if (faction == null) { return; }
boolean isMyFaction = fme == null ? false : faction == myFaction; boolean isMyFaction = fme == null ? false : faction == myFaction;
if (isMyFaction) { if (isMyFaction) {
if (!assertMinRole(Role.ADMIN)) return; if (!assertMinRole(Role.ADMIN)) { return; }
} else { }
else {
if (!Permission.DISBAND_ANY.has(sender, true)) { if (!Permission.DISBAND_ANY.has(sender, true)) {
return; return;
} }
@ -53,7 +54,7 @@ public class CmdDisband extends FCommand {
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId()); FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId());
Bukkit.getServer().getPluginManager().callEvent(disbandEvent); Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
if (disbandEvent.isCancelled()) return; if (disbandEvent.isCancelled()) { return; }
// Send FPlayerLeaveEvent for each player in the faction // Send FPlayerLeaveEvent for each player in the faction
for (FPlayer fplayer : faction.getFPlayers()) { for (FPlayer fplayer : faction.getFPlayers()) {
@ -65,12 +66,14 @@ public class CmdDisband extends FCommand {
String who = senderIsConsole ? "A server admin" : fme.describeTo(fplayer); String who = senderIsConsole ? "A server admin" : fme.describeTo(fplayer);
if (fplayer.getFaction() == faction) { if (fplayer.getFaction() == faction) {
fplayer.msg("<h>%s<i> disbanded your faction.", who); fplayer.msg("<h>%s<i> disbanded your faction.", who);
} else { }
else {
fplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getTag(fplayer)); fplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getTag(fplayer));
} }
} }
if (Conf.logFactionDisband) if (Conf.logFactionDisband) {
P.p.log("The faction " + faction.getTag() + " (" + faction.getId() + ") was disbanded by " + (senderIsConsole ? "console command" : fme.getName()) + "."); P.p.log("The faction " + faction.getTag() + " (" + faction.getId() + ") was disbanded by " + (senderIsConsole ? "console command" : fme.getName()) + ".");
}
if (Econ.shouldBeUsed() && !senderIsConsole) { if (Econ.shouldBeUsed() && !senderIsConsole) {
//Give all the faction's money to the disbander //Give all the faction's money to the disbander

View File

@ -30,7 +30,7 @@ public class CmdHelp extends FCommand {
@Override @Override
public void perform() { public void perform() {
if (helpPages == null) updateHelp(); if (helpPages == null) { updateHelp(); }
int page = this.argAsInt(0, 1); int page = this.argAsInt(0, 1);

View File

@ -87,12 +87,10 @@ public class CmdHome extends FCommand {
double z = loc.getZ(); double z = loc.getZ();
for (Player p : me.getServer().getOnlinePlayers()) { for (Player p : me.getServer().getOnlinePlayers()) {
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) { continue; }
continue;
FPlayer fp = FPlayers.i.get(p); FPlayer fp = FPlayers.i.get(p);
if (fme.getRelationTo(fp) != Relation.ENEMY) if (fme.getRelationTo(fp) != Relation.ENEMY) { continue; }
continue;
Location l = p.getLocation(); Location l = p.getLocation();
double dx = Math.abs(x - l.getX()); double dx = Math.abs(x - l.getX());
@ -101,8 +99,7 @@ public class CmdHome extends FCommand {
double max = Conf.homesTeleportAllowedEnemyDistance; double max = Conf.homesTeleportAllowedEnemyDistance;
// box-shaped distance check // box-shaped distance check
if (dx > max || dy > max || dz > max) if (dx > max || dy > max || dz > max) { continue; }
continue;
fme.msg("<b>You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you."); fme.msg("<b>You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
return; return;
@ -110,11 +107,12 @@ public class CmdHome extends FCommand {
} }
// if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown) // if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown)
if (Essentials.handleTeleport(me, myFaction.getHome())) return; if (Essentials.handleTeleport(me, myFaction.getHome())) { return; }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) if (!payForCommand(Conf.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) {
return; return;
}
// Create a smoke effect // Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) { if (Conf.homesTeleportCommandSmokeEffectEnabled) {

View File

@ -25,7 +25,7 @@ public class CmdInvite extends FCommand {
@Override @Override
public void perform() { public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return; if (you == null) { return; }
if (you.getFaction() == myFaction) { if (you.getFaction() == myFaction) {
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag()); msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
@ -34,7 +34,7 @@ public class CmdInvite extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostInvite, "to invite someone", "for inviting someone")) return; if (!payForCommand(Conf.econCostInvite, "to invite someone", "for inviting someone")) { return; }
myFaction.invite(you); myFaction.invite(you);

View File

@ -25,7 +25,7 @@ public class CmdJoin extends FCommand {
@Override @Override
public void perform() { public void perform() {
Faction faction = this.argAsFaction(0); Faction faction = this.argAsFaction(0);
if (faction == null) return; if (faction == null) { return; }
FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false); FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false);
boolean samePlayer = fplayer == fme; boolean samePlayer = fplayer == fme;
@ -62,26 +62,26 @@ public class CmdJoin extends FCommand {
if (!(faction.getOpen() || faction.isInvited(fplayer) || fme.isAdminBypassing() || Permission.JOIN_ANY.has(sender, false))) { if (!(faction.getOpen() || faction.isInvited(fplayer) || fme.isAdminBypassing() || Permission.JOIN_ANY.has(sender, false))) {
msg("<i>This faction requires invitation."); msg("<i>This faction requires invitation.");
if (samePlayer) if (samePlayer) { faction.msg("%s<i> tried to join your faction.", fplayer.describeTo(faction, true)); }
faction.msg("%s<i> tried to join your faction.", fplayer.describeTo(faction, true));
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (samePlayer && !canAffordCommand(Conf.econCostJoin, "to join a faction")) return; if (samePlayer && !canAffordCommand(Conf.econCostJoin, "to join a faction")) { return; }
// trigger the join event (cancellable) // trigger the join event (cancellable)
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND); FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND);
Bukkit.getServer().getPluginManager().callEvent(joinEvent); Bukkit.getServer().getPluginManager().callEvent(joinEvent);
if (joinEvent.isCancelled()) return; if (joinEvent.isCancelled()) { return; }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (samePlayer && !payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) return; if (samePlayer && !payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) { return; }
fme.msg("<i>%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme)); fme.msg("<i>%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme));
if (!samePlayer) if (!samePlayer) {
fplayer.msg("<i>%s moved you into the faction %s.", fme.describeTo(fplayer, true), faction.getTag(fplayer)); fplayer.msg("<i>%s moved you into the faction %s.", fme.describeTo(fplayer, true), faction.getTag(fplayer));
}
faction.msg("<i>%s joined your faction.", fplayer.describeTo(faction, true)); faction.msg("<i>%s joined your faction.", fplayer.describeTo(faction, true));
fplayer.resetFactionData(); fplayer.resetFactionData();
@ -89,10 +89,10 @@ public class CmdJoin extends FCommand {
faction.deinvite(fplayer); faction.deinvite(fplayer);
if (Conf.logFactionJoin) { if (Conf.logFactionJoin) {
if (samePlayer) if (samePlayer) { P.p.log("%s joined the faction %s.", fplayer.getName(), faction.getTag()); }
P.p.log("%s joined the faction %s.", fplayer.getName(), faction.getTag()); else {
else
P.p.log("%s moved the player %s into the faction %s.", fme.getName(), fplayer.getName(), faction.getTag()); P.p.log("%s moved the player %s into the faction %s.", fme.getName(), fplayer.getName(), faction.getTag());
}
} }
} }
} }

View File

@ -30,7 +30,7 @@ public class CmdKick extends FCommand {
@Override @Override
public void perform() { public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return; if (you == null) { return; }
if (fme == you) { if (fme == you) {
msg("<b>You cannot kick yourself."); msg("<b>You cannot kick yourself.");
@ -60,16 +60,17 @@ public class CmdKick extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostKick, "to kick someone from the faction")) return; if (!canAffordCommand(Conf.econCostKick, "to kick someone from the faction")) { return; }
// trigger the leave event (cancellable) [reason:kicked] // trigger the leave event (cancellable) [reason:kicked]
FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED); FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) if (!payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) {
return; return;
}
yourFaction.msg("%s<i> kicked %s<i> from the faction! :O", fme.describeTo(yourFaction, true), you.describeTo(yourFaction, true)); yourFaction.msg("%s<i> kicked %s<i> from the faction! :O", fme.describeTo(yourFaction, true), you.describeTo(yourFaction, true));
you.msg("%s<i> kicked you from %s<i>! :O", fme.describeTo(you, true), yourFaction.describeTo(you)); you.msg("%s<i> kicked you from %s<i>! :O", fme.describeTo(you, true), yourFaction.describeTo(you));
@ -77,11 +78,11 @@ public class CmdKick extends FCommand {
fme.msg("<i>You kicked %s<i> from the faction %s<i>!", you.describeTo(fme), yourFaction.describeTo(fme)); fme.msg("<i>You kicked %s<i> from the faction %s<i>!", you.describeTo(fme), yourFaction.describeTo(fme));
} }
if (Conf.logFactionKick) if (Conf.logFactionKick) {
P.p.log((senderIsConsole ? "A console command" : fme.getName()) + " kicked " + you.getName() + " from the faction: " + yourFaction.getTag()); P.p.log((senderIsConsole ? "A console command" : fme.getName()) + " kicked " + you.getName() + " from the faction: " + yourFaction.getTag());
}
if (you.getRole() == Role.ADMIN) if (you.getRole() == Role.ADMIN) { yourFaction.promoteNewLeader(); }
yourFaction.promoteNewLeader();
yourFaction.deinvite(you); yourFaction.deinvite(you);
you.resetFactionData(); you.resetFactionData();

View File

@ -32,7 +32,7 @@ public class CmdList extends FCommand {
@Override @Override
public void perform() { public void perform() {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) return; if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) { return; }
ArrayList<Faction> factionList = new ArrayList<Faction>(Factions.i.get()); ArrayList<Faction> factionList = new ArrayList<Faction>(Factions.i.get());
factionList.remove(Factions.i.getNone()); factionList.remove(Factions.i.getNone());
@ -45,10 +45,8 @@ public class CmdList extends FCommand {
public int compare(Faction f1, Faction f2) { public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayers().size(); int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size(); int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) if (f1Size < f2Size) { return 1; }
return 1; else if (f1Size > f2Size) { return -1; }
else if (f1Size > f2Size)
return -1;
return 0; return 0;
} }
}); });
@ -59,10 +57,8 @@ public class CmdList extends FCommand {
public int compare(Faction f1, Faction f2) { public int compare(Faction f1, Faction f2) {
int f1Size = f1.getFPlayersWhereOnline(true).size(); int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size(); int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) if (f1Size < f2Size) { return 1; }
return 1; else if (f1Size > f2Size) { return -1; }
else if (f1Size > f2Size)
return -1;
return 0; return 0;
} }
}); });
@ -91,14 +87,11 @@ public class CmdList extends FCommand {
final int pageheight = 9; final int pageheight = 9;
int pagenumber = this.argAsInt(0, 1); int pagenumber = this.argAsInt(0, 1);
int pagecount = (factionList.size() / pageheight) + 1; int pagecount = (factionList.size() / pageheight) + 1;
if (pagenumber > pagecount) if (pagenumber > pagecount) { pagenumber = pagecount; }
pagenumber = pagecount; else if (pagenumber < 1) { pagenumber = 1; }
else if (pagenumber < 1)
pagenumber = 1;
int start = (pagenumber - 1) * pageheight; int start = (pagenumber - 1) * pageheight;
int end = start + pageheight; int end = start + pageheight;
if (end > factionList.size()) if (end > factionList.size()) { end = factionList.size(); }
end = factionList.size();
lines.add(p.txt.titleize("Faction List " + pagenumber + "/" + pagecount)); lines.add(p.txt.titleize("Faction List " + pagenumber + "/" + pagecount));
@ -108,12 +101,12 @@ public class CmdList extends FCommand {
continue; continue;
} }
lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d", lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getTag(fme), faction.getTag(fme),
faction.getFPlayersWhereOnline(true).size(), faction.getFPlayersWhereOnline(true).size(),
faction.getFPlayers().size(), faction.getFPlayers().size(),
faction.getLandRounded(), faction.getLandRounded(),
faction.getPowerRounded(), faction.getPowerRounded(),
faction.getPowerMaxRounded()) faction.getPowerMaxRounded())
); );
} }

View File

@ -33,7 +33,8 @@ public class CmdLock extends FCommand {
if (p.getLocked()) { if (p.getLocked()) {
msg("<i>Factions is now locked"); msg("<i>Factions is now locked");
} else { }
else {
msg("<i>Factions in now unlocked"); msg("<i>Factions in now unlocked");
} }
} }

View File

@ -30,21 +30,23 @@ public class CmdMap extends FCommand {
// Turn on // Turn on
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) return; if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) { return; }
fme.setMapAutoUpdating(true); fme.setMapAutoUpdating(true);
msg("<i>Map auto update <green>ENABLED."); msg("<i>Map auto update <green>ENABLED.");
// And show the map once // And show the map once
showMap(); showMap();
} else { }
else {
// Turn off // Turn off
fme.setMapAutoUpdating(false); fme.setMapAutoUpdating(false);
msg("<i>Map auto update <red>DISABLED."); msg("<i>Map auto update <red>DISABLED.");
} }
} else { }
else {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) return; if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) { return; }
showMap(); showMap();
} }

View File

@ -26,7 +26,7 @@ public class CmdMod extends FCommand {
@Override @Override
public void perform() { public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return; if (you == null) { return; }
boolean permAny = Permission.MOD_ANY.has(sender, false); boolean permAny = Permission.MOD_ANY.has(sender, false);
Faction targetFaction = you.getFaction(); Faction targetFaction = you.getFaction();
@ -56,7 +56,8 @@ public class CmdMod extends FCommand {
you.setRole(Role.NORMAL); you.setRole(Role.NORMAL);
targetFaction.msg("%s<i> is no longer moderator in your faction.", you.describeTo(targetFaction, true)); targetFaction.msg("%s<i> is no longer moderator in your faction.", you.describeTo(targetFaction, true));
msg("<i>You have removed moderator status from %s<i>.", you.describeTo(fme, true)); msg("<i>You have removed moderator status from %s<i>.", you.describeTo(fme, true));
} else { }
else {
// Give // Give
you.setRole(Role.MODERATOR); you.setRole(Role.MODERATOR);
targetFaction.msg("%s<i> was promoted to moderator in your faction.", you.describeTo(targetFaction, true)); targetFaction.msg("%s<i> was promoted to moderator in your faction.", you.describeTo(targetFaction, true));

View File

@ -29,8 +29,8 @@ public class CmdMoneyBalance extends FCommand {
faction = this.argAsFaction(0); faction = this.argAsFaction(0);
} }
if (faction == null) return; if (faction == null) { return; }
if (faction != myFaction && !Permission.MONEY_BALANCE_ANY.has(sender, true)) return; if (faction != myFaction && !Permission.MONEY_BALANCE_ANY.has(sender, true)) { return; }
Econ.sendBalanceInfo(fme, faction); Econ.sendBalanceInfo(fme, faction);
} }

View File

@ -31,11 +31,12 @@ public class CmdMoneyDeposit extends FCommand {
public void perform() { public void perform() {
double amount = this.argAsDouble(0, 0d); double amount = this.argAsDouble(0, 0d);
EconomyParticipator faction = this.argAsFaction(1, myFaction); EconomyParticipator faction = this.argAsFaction(1, myFaction);
if (faction == null) return; if (faction == null) { return; }
boolean success = Econ.transferMoney(fme, fme, faction, amount); boolean success = Econ.transferMoney(fme, fme, faction, amount);
if (success && Conf.logMoneyTransactions) if (success && Conf.logMoneyTransactions) {
P.p.log(ChatColor.stripColor(P.p.txt.parse("%s deposited %s in the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null)))); P.p.log(ChatColor.stripColor(P.p.txt.parse("%s deposited %s in the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null))));
}
} }
} }

View File

@ -31,13 +31,14 @@ public class CmdMoneyTransferFf extends FCommand {
public void perform() { public void perform() {
double amount = this.argAsDouble(0, 0d); double amount = this.argAsDouble(0, 0d);
EconomyParticipator from = this.argAsFaction(1); EconomyParticipator from = this.argAsFaction(1);
if (from == null) return; if (from == null) { return; }
EconomyParticipator to = this.argAsFaction(2); EconomyParticipator to = this.argAsFaction(2);
if (to == null) return; if (to == null) { return; }
boolean success = Econ.transferMoney(fme, from, to, amount); boolean success = Econ.transferMoney(fme, from, to, amount);
if (success && Conf.logMoneyTransactions) if (success && Conf.logMoneyTransactions) {
P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the faction \"%s\" to the faction \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the faction \"%s\" to the faction \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
}
} }
} }

View File

@ -31,13 +31,14 @@ public class CmdMoneyTransferFp extends FCommand {
public void perform() { public void perform() {
double amount = this.argAsDouble(0, 0d); double amount = this.argAsDouble(0, 0d);
EconomyParticipator from = this.argAsFaction(1); EconomyParticipator from = this.argAsFaction(1);
if (from == null) return; if (from == null) { return; }
EconomyParticipator to = this.argAsBestFPlayerMatch(2); EconomyParticipator to = this.argAsBestFPlayerMatch(2);
if (to == null) return; if (to == null) { return; }
boolean success = Econ.transferMoney(fme, from, to, amount); boolean success = Econ.transferMoney(fme, from, to, amount);
if (success && Conf.logMoneyTransactions) if (success && Conf.logMoneyTransactions) {
P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the faction \"%s\" to the player \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the faction \"%s\" to the player \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
}
} }
} }

View File

@ -31,13 +31,14 @@ public class CmdMoneyTransferPf extends FCommand {
public void perform() { public void perform() {
double amount = this.argAsDouble(0, 0d); double amount = this.argAsDouble(0, 0d);
EconomyParticipator from = this.argAsBestFPlayerMatch(1); EconomyParticipator from = this.argAsBestFPlayerMatch(1);
if (from == null) return; if (from == null) { return; }
EconomyParticipator to = this.argAsFaction(2); EconomyParticipator to = this.argAsFaction(2);
if (to == null) return; if (to == null) { return; }
boolean success = Econ.transferMoney(fme, from, to, amount); boolean success = Econ.transferMoney(fme, from, to, amount);
if (success && Conf.logMoneyTransactions) if (success && Conf.logMoneyTransactions) {
P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the player \"%s\" to the faction \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null)))); P.p.log(ChatColor.stripColor(P.p.txt.parse("%s transferred %s from the player \"%s\" to the faction \"%s\"", fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
}
} }
} }

View File

@ -29,10 +29,11 @@ public class CmdMoneyWithdraw extends FCommand {
public void perform() { public void perform() {
double amount = this.argAsDouble(0, 0d); double amount = this.argAsDouble(0, 0d);
EconomyParticipator faction = this.argAsFaction(1, myFaction); EconomyParticipator faction = this.argAsFaction(1, myFaction);
if (faction == null) return; if (faction == null) { return; }
boolean success = Econ.transferMoney(fme, faction, fme, amount); boolean success = Econ.transferMoney(fme, faction, fme, amount);
if (success && Conf.logMoneyTransactions) if (success && Conf.logMoneyTransactions) {
P.p.log(ChatColor.stripColor(P.p.txt.parse("%s withdrew %s from the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null)))); P.p.log(ChatColor.stripColor(P.p.txt.parse("%s withdrew %s from the faction bank: %s", fme.getName(), Econ.moneyString(amount), faction.describeTo(null))));
}
} }
} }

View File

@ -25,8 +25,9 @@ public class CmdOpen extends FCommand {
@Override @Override
public void perform() { public void perform() {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostOpen, "to open or close the faction", "for opening or closing the faction")) if (!payForCommand(Conf.econCostOpen, "to open or close the faction", "for opening or closing the faction")) {
return; return;
}
myFaction.setOpen(this.argAsBool(0, !myFaction.getOpen())); myFaction.setOpen(this.argAsBool(0, !myFaction.getOpen()));

View File

@ -63,7 +63,7 @@ public class CmdOwner extends FCommand {
} }
FPlayer target = this.argAsBestFPlayerMatch(0, fme); FPlayer target = this.argAsBestFPlayerMatch(0, fme);
if (target == null) return; if (target == null) { return; }
String playerName = target.getName(); String playerName = target.getName();
@ -86,8 +86,9 @@ public class CmdOwner extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostOwner, "to set ownership of claimed land", "for setting ownership of claimed land")) if (!payForCommand(Conf.econCostOwner, "to set ownership of claimed land", "for setting ownership of claimed land")) {
return; return;
}
myFaction.setPlayerAsOwner(target, flocation); myFaction.setPlayerAsOwner(target, flocation);

View File

@ -26,13 +26,14 @@ public class CmdPeaceful extends FCommand {
@Override @Override
public void perform() { public void perform() {
Faction faction = this.argAsFaction(0); Faction faction = this.argAsFaction(0);
if (faction == null) return; if (faction == null) { return; }
String change; String change;
if (faction.isPeaceful()) { if (faction.isPeaceful()) {
change = "removed peaceful status from"; change = "removed peaceful status from";
faction.setPeaceful(false); faction.setPeaceful(false);
} else { }
else {
change = "granted peaceful status to"; change = "granted peaceful status to";
faction.setPeaceful(true); faction.setPeaceful(true);
} }
@ -41,7 +42,8 @@ public class CmdPeaceful extends FCommand {
for (FPlayer fplayer : FPlayers.i.getOnline()) { for (FPlayer fplayer : FPlayers.i.getOnline()) {
if (fplayer.getFaction() == faction) { if (fplayer.getFaction() == faction) {
fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> has " + change + " your faction."); fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> has " + change + " your faction.");
} else { }
else {
fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> has " + change + " the faction \"" + faction.getTag(fplayer) + "<i>\"."); fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> has " + change + " the faction \"" + faction.getTag(fplayer) + "<i>\".");
} }
} }

View File

@ -27,13 +27,14 @@ public class CmdPermanent extends FCommand {
@Override @Override
public void perform() { public void perform() {
Faction faction = this.argAsFaction(0); Faction faction = this.argAsFaction(0);
if (faction == null) return; if (faction == null) { return; }
String change; String change;
if (faction.isPermanent()) { if (faction.isPermanent()) {
change = "removed permanent status from"; change = "removed permanent status from";
faction.setPermanent(false); faction.setPermanent(false);
} else { }
else {
change = "added permanent status to"; change = "added permanent status to";
faction.setPermanent(true); faction.setPermanent(true);
} }
@ -44,7 +45,8 @@ public class CmdPermanent extends FCommand {
for (FPlayer fplayer : FPlayers.i.getOnline()) { for (FPlayer fplayer : FPlayers.i.getOnline()) {
if (fplayer.getFaction() == faction) { if (fplayer.getFaction() == faction) {
fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> " + change + " your faction."); fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> " + change + " your faction.");
} else { }
else {
fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> " + change + " the faction \"" + faction.getTag(fplayer) + "\"."); fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true)) + "<i> " + change + " the faction \"" + faction.getTag(fplayer) + "\".");
} }
} }

View File

@ -24,7 +24,7 @@ public class CmdPermanentPower extends FCommand {
@Override @Override
public void perform() { public void perform() {
Faction targetFaction = this.argAsFaction(0); Faction targetFaction = this.argAsFaction(0);
if (targetFaction == null) return; if (targetFaction == null) { return; }
Integer targetPower = this.argAsInt(1); Integer targetPower = this.argAsInt(1);

View File

@ -26,12 +26,14 @@ public class CmdPower extends FCommand {
@Override @Override
public void perform() { public void perform() {
FPlayer target = this.argAsBestFPlayerMatch(0, fme); FPlayer target = this.argAsBestFPlayerMatch(0, fme);
if (target == null) return; if (target == null) { return; }
if (target != fme && !Permission.POWER_ANY.has(sender, true)) return; if (target != fme && !Permission.POWER_ANY.has(sender, true)) { return; }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostPower, "to show player power info", "for showing player power info")) return; if (!payForCommand(Conf.econCostPower, "to show player power info", "for showing player power info")) {
return;
}
double powerBoost = target.getPowerBoost(); double powerBoost = target.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")";

View File

@ -29,7 +29,8 @@ public class CmdPowerBoost extends FCommand {
boolean doPlayer = true; boolean doPlayer = true;
if (type.equals("f") || type.equals("faction")) { if (type.equals("f") || type.equals("faction")) {
doPlayer = false; doPlayer = false;
} else if (!type.equals("p") && !type.equals("player")) { }
else if (!type.equals("p") && !type.equals("player")) {
msg("<b>You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction."); msg("<b>You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction.");
msg("<b>ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5"); msg("<b>ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5");
return; return;
@ -45,18 +46,20 @@ public class CmdPowerBoost extends FCommand {
if (doPlayer) { if (doPlayer) {
FPlayer targetPlayer = this.argAsBestFPlayerMatch(1); FPlayer targetPlayer = this.argAsBestFPlayerMatch(1);
if (targetPlayer == null) return; if (targetPlayer == null) { return; }
targetPlayer.setPowerBoost(targetPower); targetPlayer.setPowerBoost(targetPower);
target = "Player \"" + targetPlayer.getName() + "\""; target = "Player \"" + targetPlayer.getName() + "\"";
} else { }
else {
Faction targetFaction = this.argAsFaction(1); Faction targetFaction = this.argAsFaction(1);
if (targetFaction == null) return; if (targetFaction == null) { return; }
targetFaction.setPowerBoost(targetPower); targetFaction.setPowerBoost(targetPower);
target = "Faction \"" + targetFaction.getTag() + "\""; target = "Faction \"" + targetFaction.getTag() + "\"";
} }
msg("<i>" + target + " now has a power bonus/penalty of " + targetPower + " to min and max power levels."); msg("<i>" + target + " now has a power bonus/penalty of " + targetPower + " to min and max power levels.");
if (!senderIsConsole) if (!senderIsConsole) {
P.p.log(fme.getName() + " has set the power bonus/penalty for " + target + " to " + targetPower + "."); P.p.log(fme.getName() + " has set the power bonus/penalty for " + target + " to " + targetPower + ".");
}
} }
} }

View File

@ -31,22 +31,27 @@ public class CmdReload extends FCommand {
if (file.startsWith("c")) { if (file.startsWith("c")) {
Conf.load(); Conf.load();
fileName = "conf.json"; fileName = "conf.json";
} else if (file.startsWith("b")) { }
else if (file.startsWith("b")) {
Board.load(); Board.load();
fileName = "board.json"; fileName = "board.json";
} else if (file.startsWith("f")) { }
else if (file.startsWith("f")) {
Factions.i.loadFromDisc(); Factions.i.loadFromDisc();
fileName = "factions.json"; fileName = "factions.json";
} else if (file.startsWith("p")) { }
else if (file.startsWith("p")) {
FPlayers.i.loadFromDisc(); FPlayers.i.loadFromDisc();
fileName = "players.json"; fileName = "players.json";
} else if (file.startsWith("a")) { }
else if (file.startsWith("a")) {
fileName = "all"; fileName = "all";
Conf.load(); Conf.load();
FPlayers.i.loadFromDisc(); FPlayers.i.loadFromDisc();
Factions.i.loadFromDisc(); Factions.i.loadFromDisc();
Board.load(); Board.load();
} else { }
else {
P.p.log("RELOAD CANCELLED - SPECIFIED FILE INVALID"); P.p.log("RELOAD CANCELLED - SPECIFIED FILE INVALID");
msg("<b>Invalid file specified. <i>Valid files: all, conf, board, factions, players"); msg("<b>Invalid file specified. <i>Valid files: all, conf, board, factions, players");
return; return;

View File

@ -31,8 +31,7 @@ public class CmdSafeunclaimall extends FCommand {
Board.unclaimAll(Factions.i.getSafeZone().getId()); Board.unclaimAll(Factions.i.getSafeZone().getId());
msg("<i>You unclaimed ALL safe zone land."); msg("<i>You unclaimed ALL safe zone land.");
if (Conf.logLandUnclaims) if (Conf.logLandUnclaims) { P.p.log(fme.getName() + " unclaimed all safe zones."); }
P.p.log(fme.getName() + " unclaimed all safe zones.");
} }
} }

View File

@ -31,13 +31,14 @@ public class CmdSethome extends FCommand {
} }
Faction faction = this.argAsFaction(0, myFaction); Faction faction = this.argAsFaction(0, myFaction);
if (faction == null) return; if (faction == null) { return; }
// Can the player set the home for this faction? // Can the player set the home for this faction?
if (faction == myFaction) { if (faction == myFaction) {
if (!Permission.SETHOME_ANY.has(sender) && !assertMinRole(Role.MODERATOR)) return; if (!Permission.SETHOME_ANY.has(sender) && !assertMinRole(Role.MODERATOR)) { return; }
} else { }
if (!Permission.SETHOME_ANY.has(sender, true)) return; else {
if (!Permission.SETHOME_ANY.has(sender, true)) { return; }
} }
// Can the player set the faction home HERE? // Can the player set the faction home HERE?
@ -54,7 +55,7 @@ public class CmdSethome extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostSethome, "to set the faction home", "for setting the faction home")) return; if (!payForCommand(Conf.econCostSethome, "to set the faction home", "for setting the faction home")) { return; }
faction.setHome(me.getLocation()); faction.setHome(me.getLocation());

View File

@ -34,11 +34,13 @@ public class CmdShow extends FCommand {
Faction faction = myFaction; Faction faction = myFaction;
if (this.argIsSet(0)) { if (this.argIsSet(0)) {
faction = this.argAsFaction(0); faction = this.argAsFaction(0);
if (faction == null) return; if (faction == null) { return; }
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostShow, "to show faction information", "for showing faction information")) return; if (!payForCommand(Conf.econCostShow, "to show faction information", "for showing faction information")) {
return;
}
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN); Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR); Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
@ -87,22 +89,19 @@ public class CmdShow extends FCommand {
String allyList = p.txt.parse("<a>Allies: "); String allyList = p.txt.parse("<a>Allies: ");
String enemyList = p.txt.parse("<a>Enemies: "); String enemyList = p.txt.parse("<a>Enemies: ");
for (Faction otherFaction : Factions.i.get()) { for (Faction otherFaction : Factions.i.get()) {
if (otherFaction == faction) continue; if (otherFaction == faction) { continue; }
Relation rel = otherFaction.getRelationTo(faction); Relation rel = otherFaction.getRelationTo(faction);
if (!rel.isAlly() && !rel.isEnemy()) if (!rel.isAlly() && !rel.isEnemy()) {
continue; // if not ally or enemy, drop out now so we're not wasting time on it; good performance boost continue; // if not ally or enemy, drop out now so we're not wasting time on it; good performance boost
}
listpart = otherFaction.getTag(fme) + p.txt.parse("<i>") + ", "; listpart = otherFaction.getTag(fme) + p.txt.parse("<i>") + ", ";
if (rel.isAlly()) if (rel.isAlly()) { allyList += listpart; }
allyList += listpart; else if (rel.isEnemy()) { enemyList += listpart; }
else if (rel.isEnemy())
enemyList += listpart;
} }
if (allyList.endsWith(", ")) if (allyList.endsWith(", ")) { allyList = allyList.substring(0, allyList.length() - 2); }
allyList = allyList.substring(0, allyList.length() - 2); if (enemyList.endsWith(", ")) { enemyList = enemyList.substring(0, enemyList.length() - 2); }
if (enemyList.endsWith(", "))
enemyList = enemyList.substring(0, enemyList.length() - 2);
sendMessage(allyList); sendMessage(allyList);
sendMessage(enemyList); sendMessage(enemyList);
@ -114,7 +113,8 @@ public class CmdShow extends FCommand {
listpart = follower.getNameAndTitle(fme) + p.txt.parse("<i>") + ", "; listpart = follower.getNameAndTitle(fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(me)) { if (follower.isOnlineAndVisibleTo(me)) {
onlineList += listpart; onlineList += listpart;
} else { }
else {
offlineList += listpart; offlineList += listpart;
} }
} }
@ -123,7 +123,8 @@ public class CmdShow extends FCommand {
if if
(follower.isOnlineAndVisibleTo(me)) { (follower.isOnlineAndVisibleTo(me)) {
onlineList += listpart; onlineList += listpart;
} else { }
else {
offlineList += listpart; offlineList += listpart;
} }
} }
@ -131,7 +132,8 @@ public class CmdShow extends FCommand {
listpart = follower.getNameAndTitle(fme) + p.txt.parse("<i>") + ", "; listpart = follower.getNameAndTitle(fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(me)) { if (follower.isOnlineAndVisibleTo(me)) {
onlineList += listpart; onlineList += listpart;
} else { }
else {
offlineList += listpart; offlineList += listpart;
} }
} }

View File

@ -45,15 +45,15 @@ public class CmdTag extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostTag, "to change the faction tag")) return; if (!canAffordCommand(Conf.econCostTag, "to change the faction tag")) { return; }
// trigger the faction rename event (cancellable) // trigger the faction rename event (cancellable)
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
Bukkit.getServer().getPluginManager().callEvent(renameEvent); Bukkit.getServer().getPluginManager().callEvent(renameEvent);
if (renameEvent.isCancelled()) return; if (renameEvent.isCancelled()) { return; }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) return; if (!payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) { return; }
String oldtag = myFaction.getTag(); String oldtag = myFaction.getTag();
myFaction.setTag(tag); myFaction.setTag(tag);

View File

@ -24,15 +24,15 @@ public class CmdTitle extends FCommand {
@Override @Override
public void perform() { public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return; if (you == null) { return; }
args.remove(0); args.remove(0);
String title = TextUtil.implode(args, " "); String title = TextUtil.implode(args, " ");
if (!canIAdministerYou(fme, you)) return; if (!canIAdministerYou(fme, you)) { return; }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostTitle, "to change a players title", "for changing a players title")) return; if (!payForCommand(Conf.econCostTitle, "to change a players title", "for changing a players title")) { return; }
you.setTitle(title); you.setTitle(title);

View File

@ -34,20 +34,25 @@ public class CmdUnclaim extends FCommand {
Board.removeAt(flocation); Board.removeAt(flocation);
msg("<i>Safe zone was unclaimed."); msg("<i>Safe zone was unclaimed.");
if (Conf.logLandUnclaims) if (Conf.logLandUnclaims) {
P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag()); P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag());
} else { }
}
else {
msg("<b>This is a safe zone. You lack permissions to unclaim."); msg("<b>This is a safe zone. You lack permissions to unclaim.");
} }
return; return;
} else if (otherFaction.isWarZone()) { }
else if (otherFaction.isWarZone()) {
if (Permission.MANAGE_WAR_ZONE.has(sender)) { if (Permission.MANAGE_WAR_ZONE.has(sender)) {
Board.removeAt(flocation); Board.removeAt(flocation);
msg("<i>War zone was unclaimed."); msg("<i>War zone was unclaimed.");
if (Conf.logLandUnclaims) if (Conf.logLandUnclaims) {
P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag()); P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag());
} else { }
}
else {
msg("<b>This is a war zone. You lack permissions to unclaim."); msg("<b>This is a war zone. You lack permissions to unclaim.");
} }
return; return;
@ -59,8 +64,9 @@ public class CmdUnclaim extends FCommand {
otherFaction.msg("%s<i> unclaimed some of your land.", fme.describeTo(otherFaction, true)); otherFaction.msg("%s<i> unclaimed some of your land.", fme.describeTo(otherFaction, true));
msg("<i>You unclaimed this land."); msg("<i>You unclaimed this land.");
if (Conf.logLandUnclaims) if (Conf.logLandUnclaims) {
P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag()); P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag());
}
return; return;
} }
@ -81,23 +87,27 @@ public class CmdUnclaim extends FCommand {
LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction, fme); LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction, fme);
Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
if (unclaimEvent.isCancelled()) return; if (unclaimEvent.isCancelled()) { return; }
if (Econ.shouldBeUsed()) { if (Econ.shouldBeUsed()) {
double refund = Econ.calculateClaimRefund(myFaction.getLandRounded()); double refund = Econ.calculateClaimRefund(myFaction.getLandRounded());
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) { if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) {
if (!Econ.modifyMoney(myFaction, refund, "to unclaim this land", "for unclaiming this land")) return; if (!Econ.modifyMoney(myFaction, refund, "to unclaim this land", "for unclaiming this land")) {
} else { return;
if (!Econ.modifyMoney(fme, refund, "to unclaim this land", "for unclaiming this land")) return; }
}
else {
if (!Econ.modifyMoney(fme, refund, "to unclaim this land", "for unclaiming this land")) { return; }
} }
} }
Board.removeAt(flocation); Board.removeAt(flocation);
myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
if (Conf.logLandUnclaims) if (Conf.logLandUnclaims) {
P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag()); P.p.log(fme.getName() + " unclaimed land at (" + flocation.getCoordString() + ") from the faction: " + otherFaction.getTag());
}
} }
} }

View File

@ -30,11 +30,14 @@ public class CmdUnclaimall extends FCommand {
if (Econ.shouldBeUsed()) { if (Econ.shouldBeUsed()) {
double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded()); double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded());
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) { if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) {
if (!Econ.modifyMoney(myFaction, refund, "to unclaim all faction land", "for unclaiming all faction land")) if (!Econ.modifyMoney(myFaction, refund, "to unclaim all faction land", "for unclaiming all faction land")) {
return; return;
} else { }
if (!Econ.modifyMoney(fme, refund, "to unclaim all faction land", "for unclaiming all faction land")) }
else {
if (!Econ.modifyMoney(fme, refund, "to unclaim all faction land", "for unclaiming all faction land")) {
return; return;
}
} }
} }
@ -45,8 +48,9 @@ public class CmdUnclaimall extends FCommand {
Board.unclaimAll(myFaction.getId()); Board.unclaimAll(myFaction.getId());
myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); myFaction.msg("%s<i> unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true));
if (Conf.logLandUnclaims) if (Conf.logLandUnclaims) {
P.p.log(fme.getName() + " unclaimed everything for the faction: " + myFaction.getTag()); P.p.log(fme.getName() + " unclaimed everything for the faction: " + myFaction.getTag());
}
} }
} }

View File

@ -31,8 +31,7 @@ public class CmdWarunclaimall extends FCommand {
Board.unclaimAll(Factions.i.getWarZone().getId()); Board.unclaimAll(Factions.i.getWarZone().getId());
msg("<i>You unclaimed ALL war zone land."); msg("<i>You unclaimed ALL war zone land.");
if (Conf.logLandUnclaims) if (Conf.logLandUnclaims) { P.p.log(fme.getName() + " unclaimed all war zones."); }
P.p.log(fme.getName() + " unclaimed all war zones.");
} }
} }

View File

@ -42,7 +42,8 @@ public abstract class FCommand extends MCommand<P> {
if (sender instanceof Player) { if (sender instanceof Player) {
this.fme = FPlayers.i.get((Player) sender); this.fme = FPlayers.i.get((Player) sender);
this.myFaction = this.fme.getFaction(); this.myFaction = this.fme.getFaction();
} else { }
else {
this.fme = null; this.fme = null;
this.myFaction = null; this.myFaction = null;
} }
@ -72,11 +73,11 @@ public abstract class FCommand extends MCommand<P> {
@Override @Override
public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) { public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) {
boolean superValid = super.validSenderType(sender, informSenderIfNot); boolean superValid = super.validSenderType(sender, informSenderIfNot);
if (!superValid) return false; if (!superValid) { return false; }
if (!(this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin)) return true; if (!(this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin)) { return true; }
if (!(sender instanceof Player)) return false; if (!(sender instanceof Player)) { return false; }
FPlayer fplayer = FPlayers.i.get((Player) sender); FPlayer fplayer = FPlayers.i.get((Player) sender);
@ -103,7 +104,7 @@ public abstract class FCommand extends MCommand<P> {
// -------------------------------------------- // // -------------------------------------------- //
public boolean assertHasFaction() { public boolean assertHasFaction() {
if (me == null) return true; if (me == null) { return true; }
if (!fme.hasFaction()) { if (!fme.hasFaction()) {
sendMessage("You are not member of any faction."); sendMessage("You are not member of any faction.");
@ -113,7 +114,7 @@ public abstract class FCommand extends MCommand<P> {
} }
public boolean assertMinRole(Role role) { public boolean assertMinRole(Role role) {
if (me == null) return true; if (me == null) { return true; }
if (fme.getRole().value < role.value) { if (fme.getRole().value < role.value) {
msg("<b>You <h>must be " + role + "<b> to " + this.getHelpShort() + "."); msg("<b>You <h>must be " + role + "<b> to " + this.getHelpShort() + ".");
@ -240,13 +241,16 @@ public abstract class FCommand extends MCommand<P> {
if (you.getRole().equals(Role.ADMIN)) { if (you.getRole().equals(Role.ADMIN)) {
i.sendMessage(p.txt.parse("<b>Only the faction admin can do that.")); i.sendMessage(p.txt.parse("<b>Only the faction admin can do that."));
} else if (i.getRole().equals(Role.MODERATOR)) { }
else if (i.getRole().equals(Role.MODERATOR)) {
if (i == you) { if (i == you) {
return true; //Moderators can control themselves return true; //Moderators can control themselves
} else { }
else {
i.sendMessage(p.txt.parse("<b>Moderators can't control each other...")); i.sendMessage(p.txt.parse("<b>Moderators can't control each other..."));
} }
} else { }
else {
i.sendMessage(p.txt.parse("<b>You must be a faction moderator to do that.")); i.sendMessage(p.txt.parse("<b>You must be a faction moderator to do that."));
} }
@ -255,21 +259,21 @@ public abstract class FCommand extends MCommand<P> {
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost // if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
public boolean payForCommand(double cost, String toDoThis, String forDoingThis) { public boolean payForCommand(double cost, String toDoThis, String forDoingThis) {
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) return true; if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) { return true; }
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis); return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
else }
return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis); else { return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis); }
} }
// like above, but just make sure they can pay; returns true unless person can't afford the cost // like above, but just make sure they can pay; returns true unless person can't afford the cost
public boolean canAffordCommand(double cost, String toDoThis) { public boolean canAffordCommand(double cost, String toDoThis) {
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) return true; if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) { return true; }
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
return Econ.hasAtLeast(myFaction, cost, toDoThis); return Econ.hasAtLeast(myFaction, cost, toDoThis);
else }
return Econ.hasAtLeast(fme, cost, toDoThis); else { return Econ.hasAtLeast(fme, cost, toDoThis); }
} }
} }

View File

@ -28,7 +28,7 @@ public abstract class FRelationCommand extends FCommand {
@Override @Override
public void perform() { public void perform() {
Faction them = this.argAsFaction(0); Faction them = this.argAsFaction(0);
if (them == null) return; if (them == null) { return; }
if (!them.isNormal()) { if (!them.isNormal()) {
msg("<b>Nope! You can't."); msg("<b>Nope! You can't.");
@ -46,8 +46,9 @@ public abstract class FRelationCommand extends FCommand {
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(targetRelation.getRelationCost(), "to change a relation wish", "for changing a relation wish")) if (!payForCommand(targetRelation.getRelationCost(), "to change a relation wish", "for changing a relation wish")) {
return; return;
}
// try to set the new relation // try to set the new relation
Relation oldRelation = myFaction.getRelationTo(them, true); Relation oldRelation = myFaction.getRelationTo(them, true);

View File

@ -19,7 +19,7 @@ public class Econ {
private static Economy econ = null; private static Economy econ = null;
public static void setup() { public static void setup() {
if (isSetup()) return; if (isSetup()) { return; }
String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" "; String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" ";
@ -37,8 +37,9 @@ public class Econ {
P.p.log("Economy integration through Vault plugin successful."); P.p.log("Economy integration through Vault plugin successful.");
if (!Conf.econEnabled) if (!Conf.econEnabled) {
P.p.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true"); P.p.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
}
P.p.cmdBase.cmdHelp.updateHelp(); P.p.cmdBase.cmdHelp.updateHelp();
@ -55,11 +56,11 @@ public class Econ {
public static void modifyUniverseMoney(double delta) { public static void modifyUniverseMoney(double delta) {
if (!shouldBeUsed()) return; if (!shouldBeUsed()) { return; }
if (Conf.econUniverseAccount == null) return; if (Conf.econUniverseAccount == null) { return; }
if (Conf.econUniverseAccount.length() == 0) return; if (Conf.econUniverseAccount.length() == 0) { return; }
if (!econ.hasAccount(Conf.econUniverseAccount)) return; if (!econ.hasAccount(Conf.econUniverseAccount)) { return; }
modifyBalance(Conf.econUniverseAccount, delta); modifyBalance(Conf.econUniverseAccount, delta);
} }
@ -77,25 +78,26 @@ public class Econ {
Faction fYou = RelationUtil.getFaction(you); Faction fYou = RelationUtil.getFaction(you);
// This is a system invoker. Accept it. // This is a system invoker. Accept it.
if (fI == null) return true; if (fI == null) { return true; }
// Bypassing players can do any kind of transaction // Bypassing players can do any kind of transaction
if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) return true; if (i instanceof FPlayer && ((FPlayer) i).isAdminBypassing()) { return true; }
// Players with the any withdraw can do. // Players with the any withdraw can do.
if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) return true; if (i instanceof FPlayer && Permission.MONEY_WITHDRAW_ANY.has(((FPlayer) i).getPlayer())) { return true; }
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again. // You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
if (i == you) return true; if (i == you) { return true; }
// A faction can always transfer away the money of it's members and its own money... // A faction can always transfer away the money of it's members and its own money...
// This will however probably never happen as a faction does not have free will. // This will however probably never happen as a faction does not have free will.
// Ohh by the way... Yes it could. For daily rent to the faction. // Ohh by the way... Yes it could. For daily rent to the faction.
if (i == fI && fI == fYou) return true; if (i == fI && fI == fYou) { return true; }
// Factions can be controlled by members that are moderators... or any member if any member can withdraw. // Factions can be controlled by members that are moderators... or any member if any member can withdraw.
if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) {
return true; return true;
}
// Otherwise you may not! ;,,; // Otherwise you may not! ;,,;
i.msg("<h>%s<i> lacks permission to control <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i)); i.msg("<h>%s<i> lacks permission to control <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i));
@ -107,7 +109,7 @@ public class Econ {
} }
public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) { public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount, boolean notify) {
if (!shouldBeUsed()) return false; if (!shouldBeUsed()) { return false; }
// The amount must be positive. // The amount must be positive.
// If the amount is negative we must flip and multiply amount with -1. // If the amount is negative we must flip and multiply amount with -1.
@ -119,13 +121,14 @@ public class Econ {
} }
// Check the rights // Check the rights
if (!canIControllYou(invoker, from)) return false; if (!canIControllYou(invoker, from)) { return false; }
// Is there enough money for the transaction to happen? // Is there enough money for the transaction to happen?
if (!econ.has(from.getAccountId(), amount)) { if (!econ.has(from.getAccountId(), amount)) {
// There was not enough money to pay // There was not enough money to pay
if (invoker != null && notify) if (invoker != null && notify) {
invoker.msg("<h>%s<b> can't afford to transfer <h>%s<b> to %s<b>.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker)); invoker.msg("<h>%s<b> can't afford to transfer <h>%s<b> to %s<b>.", from.describeTo(invoker, true), moneyString(amount), to.describeTo(invoker));
}
return false; return false;
} }
@ -136,17 +139,19 @@ public class Econ {
if (erw.transactionSuccess()) { if (erw.transactionSuccess()) {
EconomyResponse erd = econ.depositPlayer(to.getAccountId(), amount); EconomyResponse erd = econ.depositPlayer(to.getAccountId(), amount);
if (erd.transactionSuccess()) { if (erd.transactionSuccess()) {
if (notify) sendTransferInfo(invoker, from, to, amount); if (notify) { sendTransferInfo(invoker, from, to, amount); }
return true; return true;
} else { }
else {
// transaction failed, refund account // transaction failed, refund account
econ.depositPlayer(from.getAccountId(), amount); econ.depositPlayer(from.getAccountId(), amount);
} }
} }
// if we get here something with the transaction failed // if we get here something with the transaction failed
if (notify) if (notify) {
invoker.msg("Unable to transfer %s<b> to <h>%s<b> from <h>%s<b>.", moneyString(amount), to.describeTo(invoker), from.describeTo(invoker, true)); invoker.msg("Unable to transfer %s<b> to <h>%s<b> from <h>%s<b>.", moneyString(amount), to.describeTo(invoker), from.describeTo(invoker, true));
}
return false; return false;
} }
@ -156,9 +161,11 @@ public class Econ {
if (ep == null) { if (ep == null) {
// Add nothing // Add nothing
} else if (ep instanceof FPlayer) { }
else if (ep instanceof FPlayer) {
fplayers.add((FPlayer) ep); fplayers.add((FPlayer) ep);
} else if (ep instanceof Faction) { }
else if (ep instanceof Faction) {
fplayers.addAll(((Faction) ep).getFPlayers()); fplayers.addAll(((Faction) ep).getFPlayers());
} }
@ -175,15 +182,18 @@ public class Econ {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients) {
recipient.msg("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i>.", moneyString(amount), from.describeTo(recipient), to.describeTo(recipient)); recipient.msg("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i>.", moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
} }
} else if (invoker == from) { }
else if (invoker == from) {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients) {
recipient.msg("<h>%s<i> <h>gave %s<i> to <h>%s<i>.", from.describeTo(recipient, true), moneyString(amount), to.describeTo(recipient)); recipient.msg("<h>%s<i> <h>gave %s<i> to <h>%s<i>.", from.describeTo(recipient, true), moneyString(amount), to.describeTo(recipient));
} }
} else if (invoker == to) { }
else if (invoker == to) {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients) {
recipient.msg("<h>%s<i> <h>took %s<i> from <h>%s<i>.", to.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient)); recipient.msg("<h>%s<i> <h>took %s<i> from <h>%s<i>.", to.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient));
} }
} else { }
else {
for (FPlayer recipient : recipients) { for (FPlayer recipient : recipients) {
recipient.msg("<h>%s<i> transfered <h>%s<i> from <h>%s<i> to <h>%s<i>.", invoker.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient), to.describeTo(recipient)); recipient.msg("<h>%s<i> transfered <h>%s<i> from <h>%s<i> to <h>%s<i>.", invoker.describeTo(recipient, true), moneyString(amount), from.describeTo(recipient), to.describeTo(recipient));
} }
@ -191,18 +201,19 @@ public class Econ {
} }
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) { public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) {
if (!shouldBeUsed()) return true; if (!shouldBeUsed()) { return true; }
if (!econ.has(ep.getAccountId(), delta)) { if (!econ.has(ep.getAccountId(), delta)) {
if (toDoThis != null && !toDoThis.isEmpty()) if (toDoThis != null && !toDoThis.isEmpty()) {
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", ep.describeTo(ep, true), moneyString(delta), toDoThis); ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", ep.describeTo(ep, true), moneyString(delta), toDoThis);
}
return false; return false;
} }
return true; return true;
} }
public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) { public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis) {
if (!shouldBeUsed()) return false; if (!shouldBeUsed()) { return false; }
String acc = ep.getAccountId(); String acc = ep.getAccountId();
String You = ep.describeTo(ep, true); String You = ep.describeTo(ep, true);
@ -219,29 +230,36 @@ public class Econ {
EconomyResponse er = econ.depositPlayer(acc, delta); EconomyResponse er = econ.depositPlayer(acc, delta);
if (er.transactionSuccess()) { if (er.transactionSuccess()) {
modifyUniverseMoney(-delta); modifyUniverseMoney(-delta);
if (forDoingThis != null && !forDoingThis.isEmpty()) if (forDoingThis != null && !forDoingThis.isEmpty()) {
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis); ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
}
return true; return true;
} else { }
else {
// transfer to account failed // transfer to account failed
if (forDoingThis != null && !forDoingThis.isEmpty()) if (forDoingThis != null && !forDoingThis.isEmpty()) {
ep.msg("<h>%s<i> would have gained <h>%s<i> %s, but the deposit failed.", You, moneyString(delta), forDoingThis); ep.msg("<h>%s<i> would have gained <h>%s<i> %s, but the deposit failed.", You, moneyString(delta), forDoingThis);
}
return false; return false;
} }
} else { }
else {
// The player should loose money // The player should loose money
// The player might not have enough. // The player might not have enough.
if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) { if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) {
// There is enough money to pay // There is enough money to pay
modifyUniverseMoney(-delta); modifyUniverseMoney(-delta);
if (forDoingThis != null && !forDoingThis.isEmpty()) if (forDoingThis != null && !forDoingThis.isEmpty()) {
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis); ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
}
return true; return true;
} else { }
else {
// There was not enough money to pay // There was not enough money to pay
if (toDoThis != null && !toDoThis.isEmpty()) if (toDoThis != null && !toDoThis.isEmpty()) {
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis); ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis);
}
return false; return false;
} }
} }
@ -253,7 +271,7 @@ public class Econ {
} }
public static void oldMoneyDoTransfer() { public static void oldMoneyDoTransfer() {
if (!shouldBeUsed()) return; if (!shouldBeUsed()) { return; }
for (Faction faction : Factions.i.get()) { for (Faction faction : Factions.i.get()) {
if (faction.money > 0) { if (faction.money > 0) {
@ -271,8 +289,8 @@ public class Econ {
// basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction // basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction
return Conf.econCostClaimWilderness return Conf.econCostClaimWilderness
+ (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand) + (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand)
- (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus : 0); - (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus : 0);
} }
// calculate refund amount for unclaiming land // calculate refund amount for unclaiming land
@ -309,17 +327,13 @@ public class Econ {
public static boolean setBalance(String account, double amount) { public static boolean setBalance(String account, double amount) {
double current = econ.getBalance(account); double current = econ.getBalance(account);
if (current > amount) if (current > amount) { return econ.withdrawPlayer(account, current - amount).transactionSuccess(); }
return econ.withdrawPlayer(account, current - amount).transactionSuccess(); else { return econ.depositPlayer(account, amount - current).transactionSuccess(); }
else
return econ.depositPlayer(account, amount - current).transactionSuccess();
} }
public static boolean modifyBalance(String account, double amount) { public static boolean modifyBalance(String account, double amount) {
if (amount < 0) if (amount < 0) { return econ.withdrawPlayer(account, -amount).transactionSuccess(); }
return econ.withdrawPlayer(account, -amount).transactionSuccess(); else { return econ.depositPlayer(account, amount).transactionSuccess(); }
else
return econ.depositPlayer(account, amount).transactionSuccess();
} }
public static boolean deposit(String account, double amount) { public static boolean deposit(String account, double amount) {

View File

@ -23,7 +23,7 @@ public class Essentials {
// return false if feature is disabled or Essentials isn't available // return false if feature is disabled or Essentials isn't available
public static boolean handleTeleport(Player player, Location loc) { public static boolean handleTeleport(Player player, Location loc) {
if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) return false; if (!Conf.homesTeleportCommandEssentialsIntegration || essentials == null) { return false; }
Teleport teleport = (Teleport) essentials.getUser(player).getTeleport(); Teleport teleport = (Teleport) essentials.getUser(player).getTeleport();
Trade trade = new Trade(Conf.econCostHome, essentials); Trade trade = new Trade(Conf.econCostHome, essentials);

View File

@ -36,7 +36,8 @@ public class Worldguard {
enabled = false; enabled = false;
wg = null; wg = null;
P.p.log("Could not hook to WorldGuard. WorldGuard checks are disabled."); P.p.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
} else { }
else {
wg = (WorldGuardPlugin) wgplug; wg = (WorldGuardPlugin) wgplug;
enabled = true; enabled = true;
P.p.log("Successfully hooked to WorldGuard."); P.p.log("Successfully hooked to WorldGuard.");
@ -79,8 +80,7 @@ public class Worldguard {
World world = loc.getWorld(); World world = loc.getWorld();
Vector pt = toVector(loc); Vector pt = toVector(loc);
if (wg.getRegionManager(world).getApplicableRegions(pt).size() > 0) if (wg.getRegionManager(world).getApplicableRegions(pt).size() > 0) { return wg.canBuild(player, loc); }
return wg.canBuild(player, loc);
return false; return false;
} }
@ -117,7 +117,8 @@ public class Worldguard {
overlaps = region.getIntersectingRegions(allregionslist); overlaps = region.getIntersectingRegions(allregionslist);
if (overlaps == null || overlaps.isEmpty()) { if (overlaps == null || overlaps.isEmpty()) {
foundregions = false; foundregions = false;
} else { }
else {
foundregions = true; foundregions = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -23,21 +23,22 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
if (!event.canBuild()) return; if (!event.canBuild()) { return; }
// special case for flint&steel, which should only be prevented by DenyUsage list // special case for flint&steel, which should only be prevented by DenyUsage list
if (event.getBlockPlaced().getType() == Material.FIRE) { if (event.getBlockPlaced().getType() == Material.FIRE) {
return; return;
} }
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) {
event.setCancelled(true); event.setCancelled(true);
}
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
@ -46,7 +47,7 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onBlockDamage(BlockDamageEvent event) { public void onBlockDamage(BlockDamageEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
@ -55,8 +56,8 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onBlockPistonExtend(BlockPistonExtendEvent event) { public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
if (!Conf.pistonProtectionThroughDenyBuild) return; if (!Conf.pistonProtectionThroughDenyBuild) { return; }
Faction pistonFaction = Board.getFactionAt(new FLocation(event.getBlock())); Faction pistonFaction = Board.getFactionAt(new FLocation(event.getBlock()));
@ -102,75 +103,69 @@ public class FactionsBlockListener implements Listener {
Faction otherFaction = Board.getFactionAt(new FLocation(target)); Faction otherFaction = Board.getFactionAt(new FLocation(target));
if (pistonFaction == otherFaction) if (pistonFaction == otherFaction) { return true; }
return true;
if (otherFaction.isNone()) { if (otherFaction.isNone()) {
if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName())) if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName())) {
return true; return true;
}
return false; return false;
} else if (otherFaction.isSafeZone()) { }
if (!Conf.safeZoneDenyBuild) else if (otherFaction.isSafeZone()) {
return true; if (!Conf.safeZoneDenyBuild) { return true; }
return false; return false;
} else if (otherFaction.isWarZone()) { }
if (!Conf.warZoneDenyBuild) else if (otherFaction.isWarZone()) {
return true; if (!Conf.warZoneDenyBuild) { return true; }
return false; return false;
} }
Relation rel = pistonFaction.getRelationTo(otherFaction); Relation rel = pistonFaction.getRelationTo(otherFaction);
if (rel.confDenyBuild(otherFaction.hasPlayersOnline())) if (rel.confDenyBuild(otherFaction.hasPlayersOnline())) { return false; }
return false;
return true; return true;
} }
public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) { public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) {
String name = player.getName(); String name = player.getName();
if (Conf.playersWhoBypassAllProtection.contains(name)) return true; if (Conf.playersWhoBypassAllProtection.contains(name)) { return true; }
FPlayer me = FPlayers.i.get(player.getUniqueId().toString()); FPlayer me = FPlayers.i.get(player.getUniqueId().toString());
if (me.isAdminBypassing()) return true; if (me.isAdminBypassing()) { return true; }
FLocation loc = new FLocation(location); FLocation loc = new FLocation(location);
Faction otherFaction = Board.getFactionAt(loc); Faction otherFaction = Board.getFactionAt(loc);
if (otherFaction.isNone()) { if (otherFaction.isNone()) {
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { return true; }
return true;
if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) {
return true; // This is not faction territory. Use whatever you like here. return true; // This is not faction territory. Use whatever you like here.
}
if (!justCheck) if (!justCheck) { me.msg("<b>You can't " + action + " in the wilderness."); }
me.msg("<b>You can't " + action + " in the wilderness.");
return false; return false;
} else if (otherFaction.isSafeZone()) { }
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) else if (otherFaction.isSafeZone()) {
return true; if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { return true; }
if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) { return true; }
return true;
if (!justCheck) if (!justCheck) { me.msg("<b>You can't " + action + " in a safe zone."); }
me.msg("<b>You can't " + action + " in a safe zone.");
return false; return false;
} else if (otherFaction.isWarZone()) { }
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) else if (otherFaction.isWarZone()) {
return true; if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { return true; }
if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) { return true; }
return true;
if (!justCheck) if (!justCheck) { me.msg("<b>You can't " + action + " in a war zone."); }
me.msg("<b>You can't " + action + " in a war zone.");
return false; return false;
} }
@ -185,14 +180,16 @@ public class FactionsBlockListener implements Listener {
if (pain) { if (pain) {
player.damage(Conf.actionDeniedPainAmount); player.damage(Conf.actionDeniedPainAmount);
if (!deny) if (!deny) {
me.msg("<b>It is painful to try to " + action + " in the territory of " + otherFaction.getTag(myFaction)); me.msg("<b>It is painful to try to " + action + " in the territory of " + otherFaction.getTag(myFaction));
}
} }
// cancel building/destroying in other territory? // cancel building/destroying in other territory?
if (deny) { if (deny) {
if (!justCheck) if (!justCheck) {
me.msg("<b>You can't " + action + " in the territory of " + otherFaction.getTag(myFaction)); me.msg("<b>You can't " + action + " in the territory of " + otherFaction.getTag(myFaction));
}
return false; return false;
} }
@ -202,12 +199,14 @@ public class FactionsBlockListener implements Listener {
if (!pain && Conf.ownedAreaPainBuild && !justCheck) { if (!pain && Conf.ownedAreaPainBuild && !justCheck) {
player.damage(Conf.actionDeniedPainAmount); player.damage(Conf.actionDeniedPainAmount);
if (!Conf.ownedAreaDenyBuild) if (!Conf.ownedAreaDenyBuild) {
me.msg("<b>It is painful to try to " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc)); me.msg("<b>It is painful to try to " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
}
} }
if (Conf.ownedAreaDenyBuild) { if (Conf.ownedAreaDenyBuild) {
if (!justCheck) if (!justCheck) {
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc)); me.msg("<b>You can't " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
}
return false; return false;
} }

View File

@ -25,7 +25,7 @@ public class FactionsChatListener implements Listener {
// this is for handling slashless command usage and faction/alliance chat, set at lowest priority so Factions gets to them first // this is for handling slashless command usage and faction/alliance chat, set at lowest priority so Factions gets to them first
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerEarlyChat(PlayerChatEvent event) { public void onPlayerEarlyChat(PlayerChatEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
Player talkingPlayer = event.getPlayer(); Player talkingPlayer = event.getPlayer();
String msg = event.getMessage(); String msg = event.getMessage();
@ -34,8 +34,9 @@ public class FactionsChatListener implements Listener {
// slashless factions commands need to be handled here if the user isn't in public chat mode // slashless factions commands need to be handled here if the user isn't in public chat mode
if (chat != ChatMode.PUBLIC && p.handleCommand(talkingPlayer, msg, false, true)) { if (chat != ChatMode.PUBLIC && p.handleCommand(talkingPlayer, msg, false, true)) {
if (Conf.logPlayerCommands) if (Conf.logPlayerCommands) {
Bukkit.getLogger().log(Level.INFO, "[PLAYER_COMMAND] " + talkingPlayer.getName() + ": " + msg); Bukkit.getLogger().log(Level.INFO, "[PLAYER_COMMAND] " + talkingPlayer.getName() + ": " + msg);
}
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -51,13 +52,15 @@ public class FactionsChatListener implements Listener {
//Send to any players who are spying chat //Send to any players who are spying chat
for (FPlayer fplayer : FPlayers.i.getOnline()) { for (FPlayer fplayer : FPlayers.i.getOnline()) {
if (fplayer.isSpyingChat() && fplayer.getFaction() != myFaction) if (fplayer.isSpyingChat() && fplayer.getFaction() != myFaction) {
fplayer.sendMessage("[FCspy] " + myFaction.getTag() + ": " + message); fplayer.sendMessage("[FCspy] " + myFaction.getTag() + ": " + message);
}
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} else if (chat == ChatMode.ALLIANCE) { }
else if (chat == ChatMode.ALLIANCE) {
Faction myFaction = me.getFaction(); Faction myFaction = me.getFaction();
String message = String.format(Conf.allianceChatFormat, ChatColor.stripColor(me.getNameAndTag()), msg); String message = String.format(Conf.allianceChatFormat, ChatColor.stripColor(me.getNameAndTag()), msg);
@ -67,12 +70,10 @@ public class FactionsChatListener implements Listener {
//Send to all our allies //Send to all our allies
for (FPlayer fplayer : FPlayers.i.getOnline()) { for (FPlayer fplayer : FPlayers.i.getOnline()) {
if (myFaction.getRelationTo(fplayer) == Relation.ALLY) if (myFaction.getRelationTo(fplayer) == Relation.ALLY) { fplayer.sendMessage(message); }
fplayer.sendMessage(message);
//Send to any players who are spying chat //Send to any players who are spying chat
else if (fplayer.isSpyingChat()) else if (fplayer.isSpyingChat()) { fplayer.sendMessage("[ACspy]: " + message); }
fplayer.sendMessage("[ACspy]: " + message);
} }
Bukkit.getLogger().log(Level.INFO, ChatColor.stripColor("AllianceChat: " + message)); Bukkit.getLogger().log(Level.INFO, ChatColor.stripColor("AllianceChat: " + message));
@ -85,11 +86,11 @@ public class FactionsChatListener implements Listener {
// this is for handling insertion of the player's faction tag, set at highest priority to give other plugins a chance to modify chat first // this is for handling insertion of the player's faction tag, set at highest priority to give other plugins a chance to modify chat first
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(PlayerChatEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
// Are we to insert the Faction tag into the format? // Are we to insert the Faction tag into the format?
// If we are not to insert it - we are done. // If we are not to insert it - we are done.
if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) return; if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) { return; }
Player talkingPlayer = event.getPlayer(); Player talkingPlayer = event.getPlayer();
String msg = event.getMessage(); String msg = event.getMessage();
@ -107,17 +108,19 @@ public class FactionsChatListener implements Listener {
eventFormat = eventFormat.replace(Conf.chatTagReplaceString, ""); eventFormat = eventFormat.replace(Conf.chatTagReplaceString, "");
Conf.chatTagPadAfter = false; Conf.chatTagPadAfter = false;
Conf.chatTagPadBefore = false; Conf.chatTagPadBefore = false;
} else if (!Conf.chatTagInsertAfterString.isEmpty() && eventFormat.contains(Conf.chatTagInsertAfterString)) { }
else if (!Conf.chatTagInsertAfterString.isEmpty() && eventFormat.contains(Conf.chatTagInsertAfterString)) {
// we're using the "insert after string" method // we're using the "insert after string" method
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertAfterString) + Conf.chatTagInsertAfterString.length(); InsertIndex = eventFormat.indexOf(Conf.chatTagInsertAfterString) + Conf.chatTagInsertAfterString.length();
} else if (!Conf.chatTagInsertBeforeString.isEmpty() && eventFormat.contains(Conf.chatTagInsertBeforeString)) { }
else if (!Conf.chatTagInsertBeforeString.isEmpty() && eventFormat.contains(Conf.chatTagInsertBeforeString)) {
// we're using the "insert before string" method // we're using the "insert before string" method
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString); InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString);
} else { }
else {
// we'll fall back to using the index place method // we'll fall back to using the index place method
InsertIndex = Conf.chatTagInsertIndex; InsertIndex = Conf.chatTagInsertIndex;
if (InsertIndex > eventFormat.length()) if (InsertIndex > eventFormat.length()) { return; }
return;
} }
String formatStart = eventFormat.substring(0, InsertIndex) + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : ""); String formatStart = eventFormat.substring(0, InsertIndex) + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : "");
@ -148,7 +151,8 @@ public class FactionsChatListener implements Listener {
// Write to the log... We will write the non colored message. // Write to the log... We will write the non colored message.
String nonColoredMsg = ChatColor.stripColor(String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg)); String nonColoredMsg = ChatColor.stripColor(String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg));
Bukkit.getLogger().log(Level.INFO, nonColoredMsg); Bukkit.getLogger().log(Level.INFO, nonColoredMsg);
} else { }
else {
// No relation color. // No relation color.
event.setFormat(nonColoredMsgFormat); event.setFormat(nonColoredMsgFormat);
} }

View File

@ -54,16 +54,20 @@ public class FactionsEntityListener implements Listener {
if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) { if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) {
powerLossEvent.setMessage("<b>The world you are in has power loss normally disabled, but you still lost power since you were in a war zone.\n<i>Your power is now <h>%d / %d"); powerLossEvent.setMessage("<b>The world you are in has power loss normally disabled, but you still lost power since you were in a war zone.\n<i>Your power is now <h>%d / %d");
} }
} else if (faction.isNone() && !Conf.wildernessPowerLoss && !Conf.worldsNoWildernessProtection.contains(player.getWorld().getName())) { }
else if (faction.isNone() && !Conf.wildernessPowerLoss && !Conf.worldsNoWildernessProtection.contains(player.getWorld().getName())) {
powerLossEvent.setMessage("<i>You didn't lose any power since you were in the wilderness."); powerLossEvent.setMessage("<i>You didn't lose any power since you were in the wilderness.");
powerLossEvent.setCancelled(true); powerLossEvent.setCancelled(true);
} else if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) { }
else if (Conf.worldsNoPowerLoss.contains(player.getWorld().getName())) {
powerLossEvent.setMessage("<i>You didn't lose any power due to the world you died in."); powerLossEvent.setMessage("<i>You didn't lose any power due to the world you died in.");
powerLossEvent.setCancelled(true); powerLossEvent.setCancelled(true);
} else if (Conf.peacefulMembersDisablePowerLoss && fplayer.hasFaction() && fplayer.getFaction().isPeaceful()) { }
else if (Conf.peacefulMembersDisablePowerLoss && fplayer.hasFaction() && fplayer.getFaction().isPeaceful()) {
powerLossEvent.setMessage("<i>You didn't lose any power since you are in a peaceful faction."); powerLossEvent.setMessage("<i>You didn't lose any power since you are in a peaceful faction.");
powerLossEvent.setCancelled(true); powerLossEvent.setCancelled(true);
} else { }
else {
powerLossEvent.setMessage("<i>Your power is now <h>%d / %d"); powerLossEvent.setMessage("<i>Your power is now <h>%d / %d");
} }
@ -87,14 +91,15 @@ public class FactionsEntityListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
if (event instanceof EntityDamageByEntityEvent) { if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event; EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
if (!this.canDamagerHurtDamagee(sub, true)) { if (!this.canDamagerHurtDamagee(sub, true)) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) { }
else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) {
// Players can not take any damage in a Safe Zone // Players can not take any damage in a Safe Zone
event.setCancelled(true); event.setCancelled(true);
} }
@ -102,7 +107,7 @@ public class FactionsEntityListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
Location loc = event.getLocation(); Location loc = event.getLocation();
Entity boomer = event.getEntity(); Entity boomer = event.getEntity();
@ -133,40 +138,43 @@ public class FactionsEntityListener implements Listener {
) { ) {
// creeper which needs prevention // creeper which needs prevention
event.setCancelled(true); event.setCancelled(true);
} else if }
( else if
(
// it's a bit crude just using fireball protection for Wither boss too, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever // it's a bit crude just using fireball protection for Wither boss too, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever
(boomer instanceof Fireball || boomer instanceof WitherSkull || boomer instanceof Wither) (boomer instanceof Fireball || boomer instanceof WitherSkull || boomer instanceof Wither)
&& &&
( (
(faction.isNone() && Conf.wildernessBlockFireballs && !Conf.worldsNoWildernessProtection.contains(loc.getWorld().getName())) (faction.isNone() && Conf.wildernessBlockFireballs && !Conf.worldsNoWildernessProtection.contains(loc.getWorld().getName()))
|| ||
(faction.isNormal() && (online ? Conf.territoryBlockFireballs : Conf.territoryBlockFireballsWhenOffline)) (faction.isNormal() && (online ? Conf.territoryBlockFireballs : Conf.territoryBlockFireballsWhenOffline))
|| ||
(faction.isWarZone() && Conf.warZoneBlockFireballs) (faction.isWarZone() && Conf.warZoneBlockFireballs)
|| ||
faction.isSafeZone() faction.isSafeZone()
) )
) { ) {
// ghast fireball which needs prevention // ghast fireball which needs prevention
event.setCancelled(true); event.setCancelled(true);
} else if }
( else if
(boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) (
&& (boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart)
( &&
(faction.isNone() && Conf.wildernessBlockTNT && !Conf.worldsNoWildernessProtection.contains(loc.getWorld().getName())) (
|| (faction.isNone() && Conf.wildernessBlockTNT && !Conf.worldsNoWildernessProtection.contains(loc.getWorld().getName()))
(faction.isNormal() && (online ? Conf.territoryBlockTNT : Conf.territoryBlockTNTWhenOffline)) ||
|| (faction.isNormal() && (online ? Conf.territoryBlockTNT : Conf.territoryBlockTNTWhenOffline))
(faction.isWarZone() && Conf.warZoneBlockTNT) ||
|| (faction.isWarZone() && Conf.warZoneBlockTNT)
(faction.isSafeZone() && Conf.safeZoneBlockTNT) ||
) (faction.isSafeZone() && Conf.safeZoneBlockTNT)
) { )
) {
// TNT which needs prevention // TNT which needs prevention
event.setCancelled(true); event.setCancelled(true);
} else if ((boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) && Conf.handleExploitTNTWaterlog) { }
else if ((boomer instanceof TNTPrimed || boomer instanceof ExplosiveMinecart) && Conf.handleExploitTNTWaterlog) {
// TNT in water/lava doesn't normally destroy any surrounding blocks, which is usually desired behavior, but... // TNT in water/lava doesn't normally destroy any surrounding blocks, which is usually desired behavior, but...
// this change below provides workaround for waterwalling providing perfect protection, // this change below provides workaround for waterwalling providing perfect protection,
// and makes cheap (non-obsidian) TNT cannons require minor maintenance between shots // and makes cheap (non-obsidian) TNT cannons require minor maintenance between shots
@ -183,8 +191,9 @@ public class FactionsEntityListener implements Listener {
for (Block target : targets) { for (Block target : targets) {
int id = target.getTypeId(); int id = target.getTypeId();
// ignore air, bedrock, water, lava, obsidian, enchanting table, etc.... too bad we can't get a blast resistance value through Bukkit yet // ignore air, bedrock, water, lava, obsidian, enchanting table, etc.... too bad we can't get a blast resistance value through Bukkit yet
if (id != 0 && (id < 7 || id > 11) && id != 49 && id != 90 && id != 116 && id != 119 && id != 120 && id != 130) if (id != 0 && (id < 7 || id > 11) && id != 49 && id != 90 && id != 116 && id != 119 && id != 120 && id != 130) {
target.breakNaturally(); target.breakNaturally();
}
} }
} }
} }
@ -193,23 +202,22 @@ public class FactionsEntityListener implements Listener {
// mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled // mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0); EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0);
if (!this.canDamagerHurtDamagee(sub, false)) if (!this.canDamagerHurtDamagee(sub, false)) { event.setCancelled(true); }
event.setCancelled(true);
sub = null; sub = null;
} }
private static final Set<PotionEffectType> badPotionEffects = new LinkedHashSet<PotionEffectType>(Arrays.asList( private static final Set<PotionEffectType> badPotionEffects = new LinkedHashSet<PotionEffectType>(Arrays.asList(
PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER,
PotionEffectType.POISON, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.POISON, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS,
PotionEffectType.WITHER PotionEffectType.WITHER
)); ));
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPotionSplashEvent(PotionSplashEvent event) { public void onPotionSplashEvent(PotionSplashEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
// see if the potion has a harmful effect // see if the potion has a harmful effect
boolean badjuju = false; boolean badjuju = false;
@ -219,7 +227,7 @@ public class FactionsEntityListener implements Listener {
break; break;
} }
} }
if (!badjuju) return; if (!badjuju) { return; }
ProjectileSource thrower = event.getPotion().getShooter(); ProjectileSource thrower = event.getPotion().getShooter();
if (!(thrower instanceof Entity)) { if (!(thrower instanceof Entity)) {
@ -231,8 +239,9 @@ public class FactionsEntityListener implements Listener {
while (iter.hasNext()) { while (iter.hasNext()) {
LivingEntity target = iter.next(); LivingEntity target = iter.next();
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent((Entity) thrower, target, EntityDamageEvent.DamageCause.CUSTOM, 0); EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent((Entity) thrower, target, EntityDamageEvent.DamageCause.CUSTOM, 0);
if (!this.canDamagerHurtDamagee(sub, true)) if (!this.canDamagerHurtDamagee(sub, true)) {
event.setIntensity(target, 0.0); // affected entity list doesn't accept modification (so no iter.remove()), but this works event.setIntensity(target, 0.0); // affected entity list doesn't accept modification (so no iter.remove()), but this works
}
sub = null; sub = null;
} }
} }
@ -256,13 +265,11 @@ public class FactionsEntityListener implements Listener {
Entity damagee = sub.getEntity(); Entity damagee = sub.getEntity();
double damage = sub.getDamage(); double damage = sub.getDamage();
if (!(damagee instanceof Player)) if (!(damagee instanceof Player)) { return true; }
return true;
FPlayer defender = FPlayers.i.get((Player) damagee); FPlayer defender = FPlayers.i.get((Player) damagee);
if (defender == null || defender.getPlayer() == null) if (defender == null || defender.getPlayer() == null) { return true; }
return true;
Location defenderLoc = defender.getPlayer().getLocation(); Location defenderLoc = defender.getPlayer().getLocation();
Faction defLocFaction = Board.getFactionAt(new FLocation(defenderLoc)); Faction defLocFaction = Board.getFactionAt(new FLocation(defenderLoc));
@ -273,7 +280,7 @@ public class FactionsEntityListener implements Listener {
} }
if (damager == damagee) // ender pearl usage and other self-inflicted damage if (damager == damagee) // ender pearl usage and other self-inflicted damage
return true; { return true; }
// Players can not take attack damage in a SafeZone, or possibly peaceful territory // Players can not take attack damage in a SafeZone, or possibly peaceful territory
if (defLocFaction.noPvPInTerritory()) { if (defLocFaction.noPvPInTerritory()) {
@ -287,19 +294,18 @@ public class FactionsEntityListener implements Listener {
return !defLocFaction.noMonstersInTerritory(); return !defLocFaction.noMonstersInTerritory();
} }
if (!(damager instanceof Player)) if (!(damager instanceof Player)) { return true; }
return true;
FPlayer attacker = FPlayers.i.get((Player) damager); FPlayer attacker = FPlayers.i.get((Player) damager);
if (attacker == null || attacker.getPlayer() == null) if (attacker == null || attacker.getPlayer() == null) { return true; }
return true;
if (Conf.playersWhoBypassAllProtection.contains(attacker.getName())) return true; if (Conf.playersWhoBypassAllProtection.contains(attacker.getName())) { return true; }
if (attacker.hasLoginPvpDisabled()) { if (attacker.hasLoginPvpDisabled()) {
if (notify) if (notify) {
attacker.msg("<i>You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in."); attacker.msg("<i>You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in.");
}
return false; return false;
} }
@ -307,38 +313,40 @@ public class FactionsEntityListener implements Listener {
// so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be? // so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be?
if (locFaction.noPvPInTerritory()) { if (locFaction.noPvPInTerritory()) {
if (notify) if (notify) {
attacker.msg("<i>You can't hurt other players while you are in " + (locFaction.isSafeZone() ? "a SafeZone." : "peaceful territory.")); attacker.msg("<i>You can't hurt other players while you are in " + (locFaction.isSafeZone() ? "a SafeZone." : "peaceful territory."));
}
return false; return false;
} }
if (locFaction.isWarZone() && Conf.warZoneFriendlyFire) if (locFaction.isWarZone() && Conf.warZoneFriendlyFire) { return true; }
return true;
if (Conf.worldsIgnorePvP.contains(defenderLoc.getWorld().getName())) if (Conf.worldsIgnorePvP.contains(defenderLoc.getWorld().getName())) { return true; }
return true;
Faction defendFaction = defender.getFaction(); Faction defendFaction = defender.getFaction();
Faction attackFaction = attacker.getFaction(); Faction attackFaction = attacker.getFaction();
if (attackFaction.isNone() && Conf.disablePVPForFactionlessPlayers) { if (attackFaction.isNone() && Conf.disablePVPForFactionlessPlayers) {
if (notify) attacker.msg("<i>You can't hurt other players until you join a faction."); if (notify) { attacker.msg("<i>You can't hurt other players until you join a faction."); }
return false; return false;
} else if (defendFaction.isNone()) { }
else if (defendFaction.isNone()) {
if (defLocFaction == attackFaction && Conf.enablePVPAgainstFactionlessInAttackersLand) { if (defLocFaction == attackFaction && Conf.enablePVPAgainstFactionlessInAttackersLand) {
// Allow PVP vs. Factionless in attacker's faction territory // Allow PVP vs. Factionless in attacker's faction territory
return true; return true;
} else if (Conf.disablePVPForFactionlessPlayers) { }
if (notify) attacker.msg("<i>You can't hurt players who are not currently in a faction."); else if (Conf.disablePVPForFactionlessPlayers) {
if (notify) { attacker.msg("<i>You can't hurt players who are not currently in a faction."); }
return false; return false;
} }
} }
if (defendFaction.isPeaceful()) { if (defendFaction.isPeaceful()) {
if (notify) attacker.msg("<i>You can't hurt players who are in a peaceful faction."); if (notify) { attacker.msg("<i>You can't hurt players who are in a peaceful faction."); }
return false; return false;
} else if (attackFaction.isPeaceful()) { }
if (notify) attacker.msg("<i>You can't hurt players while you are in a peaceful faction."); else if (attackFaction.isPeaceful()) {
if (notify) { attacker.msg("<i>You can't hurt players while you are in a peaceful faction."); }
return false; return false;
} }
@ -346,17 +354,16 @@ public class FactionsEntityListener implements Listener {
// You can not hurt neutral factions // You can not hurt neutral factions
if (Conf.disablePVPBetweenNeutralFactions && relation.isNeutral()) { if (Conf.disablePVPBetweenNeutralFactions && relation.isNeutral()) {
if (notify) attacker.msg("<i>You can't hurt neutral factions. Declare them as an enemy."); if (notify) { attacker.msg("<i>You can't hurt neutral factions. Declare them as an enemy."); }
return false; return false;
} }
// Players without faction may be hurt anywhere // Players without faction may be hurt anywhere
if (!defender.hasFaction()) if (!defender.hasFaction()) { return true; }
return true;
// You can never hurt faction members or allies // You can never hurt faction members or allies
if (relation.isMember() || relation.isAlly()) { if (relation.isMember() || relation.isAlly()) {
if (notify) attacker.msg("<i>You can't hurt %s<i>.", defender.describeTo(attacker)); if (notify) { attacker.msg("<i>You can't hurt %s<i>.", defender.describeTo(attacker)); }
return false; return false;
} }
@ -399,7 +406,7 @@ public class FactionsEntityListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onEntityTarget(EntityTargetEvent event) { public void onEntityTarget(EntityTargetEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
// if there is a target // if there is a target
Entity target = event.getTarget(); Entity target = event.getTarget();
@ -420,7 +427,7 @@ public class FactionsEntityListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPaintingBreak(HangingBreakEvent event) { public void onPaintingBreak(HangingBreakEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
if (event.getCause() == RemoveCause.EXPLOSION) { if (event.getCause() == RemoveCause.EXPLOSION) {
Location loc = event.getEntity().getLocation(); Location loc = event.getEntity().getLocation();
Faction faction = Board.getFactionAt(new FLocation(loc)); Faction faction = Board.getFactionAt(new FLocation(loc));
@ -444,8 +451,8 @@ public class FactionsEntityListener implements Listener {
faction.isNormal() faction.isNormal()
&& &&
(online (online
? (Conf.territoryBlockCreepers || Conf.territoryBlockFireballs || Conf.territoryBlockTNT) ? (Conf.territoryBlockCreepers || Conf.territoryBlockFireballs || Conf.territoryBlockTNT)
: (Conf.territoryBlockCreepersWhenOffline || Conf.territoryBlockFireballsWhenOffline || Conf.territoryBlockTNTWhenOffline) : (Conf.territoryBlockCreepersWhenOffline || Conf.territoryBlockFireballsWhenOffline || Conf.territoryBlockTNTWhenOffline)
) )
) )
|| ||
@ -477,7 +484,7 @@ public class FactionsEntityListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPaintingPlace(HangingPlaceEvent event) { public void onPaintingPlace(HangingPlaceEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) { if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) {
event.setCancelled(true); event.setCancelled(true);
@ -486,19 +493,19 @@ public class FactionsEntityListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onEntityChangeBlock(EntityChangeBlockEvent event) { public void onEntityChangeBlock(EntityChangeBlockEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
Entity entity = event.getEntity(); Entity entity = event.getEntity();
// for now, only interested in Enderman and Wither boss tomfoolery // for now, only interested in Enderman and Wither boss tomfoolery
if (!(entity instanceof Enderman) && !(entity instanceof Wither)) return; if (!(entity instanceof Enderman) && !(entity instanceof Wither)) { return; }
Location loc = event.getBlock().getLocation(); Location loc = event.getBlock().getLocation();
if (entity instanceof Enderman) { if (entity instanceof Enderman) {
if (stopEndermanBlockManipulation(loc)) if (stopEndermanBlockManipulation(loc)) { event.setCancelled(true); }
event.setCancelled(true); }
} else if (entity instanceof Wither) { else if (entity instanceof Wither) {
Faction faction = Board.getFactionAt(new FLocation(loc)); Faction faction = Board.getFactionAt(new FLocation(loc));
// it's a bit crude just using fireball protection, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever // it's a bit crude just using fireball protection, but I'd rather not add in a whole new set of xxxBlockWitherExplosion or whatever
if if
@ -510,8 +517,7 @@ public class FactionsEntityListener implements Listener {
(faction.isWarZone() && Conf.warZoneBlockFireballs) (faction.isWarZone() && Conf.warZoneBlockFireballs)
|| ||
faction.isSafeZone() faction.isSafeZone()
) ) { event.setCancelled(true); }
event.setCancelled(true);
} }
} }
@ -540,11 +546,14 @@ public class FactionsEntityListener implements Listener {
if (claimFaction.isNone()) { if (claimFaction.isNone()) {
return Conf.wildernessDenyEndermanBlocks; return Conf.wildernessDenyEndermanBlocks;
} else if (claimFaction.isNormal()) { }
else if (claimFaction.isNormal()) {
return claimFaction.hasPlayersOnline() ? Conf.territoryDenyEndermanBlocks : Conf.territoryDenyEndermanBlocksWhenOffline; return claimFaction.hasPlayersOnline() ? Conf.territoryDenyEndermanBlocks : Conf.territoryDenyEndermanBlocksWhenOffline;
} else if (claimFaction.isSafeZone()) { }
else if (claimFaction.isSafeZone()) {
return Conf.safeZoneDenyEndermanBlocks; return Conf.safeZoneDenyEndermanBlocks;
} else if (claimFaction.isWarZone()) { }
else if (claimFaction.isWarZone()) {
return Conf.warZoneDenyEndermanBlocks; return Conf.warZoneDenyEndermanBlocks;
} }

View File

@ -14,21 +14,20 @@ import org.bukkit.event.player.PlayerTeleportEvent;
public class FactionsExploitListener implements Listener { public class FactionsExploitListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void obsidianGenerator(BlockFromToEvent event) { public void obsidianGenerator(BlockFromToEvent event) {
if (event.isCancelled() == true || !Conf.handleExploitObsidianGenerators) return; if (event.isCancelled() == true || !Conf.handleExploitObsidianGenerators) { return; }
// thanks to ObGenBlocker and WorldGuard for this method // thanks to ObGenBlocker and WorldGuard for this method
Block block = event.getToBlock(); Block block = event.getToBlock();
int source = event.getBlock().getTypeId(); int source = event.getBlock().getTypeId();
int target = block.getTypeId(); int target = block.getTypeId();
if ((target == 55 || target == 132) && (source == 0 || source == 10 || source == 11)) if ((target == 55 || target == 132) && (source == 0 || source == 10 || source == 11)) { block.setTypeId(0); }
block.setTypeId(0);
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void enderPearlTeleport(PlayerTeleportEvent event) { public void enderPearlTeleport(PlayerTeleportEvent event) {
if (event.isCancelled() == true || !Conf.handleExploitEnderPearlClipping) return; if (event.isCancelled() == true || !Conf.handleExploitEnderPearlClipping) { return; }
if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return; if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { return; }
// this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar... // this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar...
Location target = event.getTo(); Location target = event.getTo();

View File

@ -57,13 +57,12 @@ public class FactionsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
// quick check to make sure player is moving between chunks; good performance boost // quick check to make sure player is moving between chunks; good performance boost
if(event.getFrom().getBlockX() >> 4 == event.getTo().getBlockX() >> 4 if (event.getFrom().getBlockX() >> 4 == event.getTo().getBlockX() >> 4
&& event.getFrom().getBlockZ() >> 4 == event.getTo().getBlockZ() >> 4 && event.getFrom().getBlockZ() >> 4 == event.getTo().getBlockZ() >> 4
&& event.getFrom().getWorld() == event.getTo().getWorld()) && event.getFrom().getWorld() == event.getTo().getWorld()) { return; }
return;
Player player = event.getPlayer(); Player player = event.getPlayer();
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
@ -92,41 +91,45 @@ public class FactionsPlayerListener implements Listener {
if (me.isMapAutoUpdating()) { if (me.isMapAutoUpdating()) {
me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw())); me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw()));
} else { }
else {
Faction myFaction = me.getFaction(); Faction myFaction = me.getFaction();
String ownersTo = myFaction.getOwnerListString(to); String ownersTo = myFaction.getOwnerListString(to);
if (changedFaction) { if (changedFaction) {
me.sendFactionHereMessage(); me.sendFactionHereMessage();
if (Conf.ownedAreasEnabled && Conf.ownedMessageOnBorder &&myFaction == factionTo && !ownersTo.isEmpty()) { if (Conf.ownedAreasEnabled && Conf.ownedMessageOnBorder && myFaction == factionTo && !ownersTo.isEmpty()) {
me.sendMessage(Conf.ownedLandMessage + ownersTo); me.sendMessage(Conf.ownedLandMessage + ownersTo);
} }
} else if (Conf.ownedAreasEnabled && Conf.ownedMessageInsideTerritory && factionFrom == factionTo &&myFaction == factionTo) { }
else if (Conf.ownedAreasEnabled && Conf.ownedMessageInsideTerritory && factionFrom == factionTo && myFaction == factionTo) {
String ownersFrom = myFaction.getOwnerListString(from); String ownersFrom = myFaction.getOwnerListString(from);
if (Conf.ownedMessageByChunk || !ownersFrom.equals(ownersTo)) { if (Conf.ownedMessageByChunk || !ownersFrom.equals(ownersTo)) {
if (!ownersTo.isEmpty()) if (!ownersTo.isEmpty()) { me.sendMessage(Conf.ownedLandMessage + ownersTo); }
me.sendMessage(Conf.ownedLandMessage + ownersTo); else if (!Conf.publicLandMessage.isEmpty()) { me.sendMessage(Conf.publicLandMessage); }
else if (!Conf.publicLandMessage.isEmpty())
me.sendMessage(Conf.publicLandMessage);
} }
} }
} }
if (me.getAutoClaimFor() != null) { if (me.getAutoClaimFor() != null) {
me.attemptClaim(me.getAutoClaimFor(), event.getTo(), true); me.attemptClaim(me.getAutoClaimFor(), event.getTo(), true);
} else if (me.isAutoSafeClaimEnabled()) { }
else if (me.isAutoSafeClaimEnabled()) {
if (!Permission.MANAGE_SAFE_ZONE.has(player)) { if (!Permission.MANAGE_SAFE_ZONE.has(player)) {
me.setIsAutoSafeClaimEnabled(false); me.setIsAutoSafeClaimEnabled(false);
} else { }
else {
if (!Board.getFactionAt(to).isSafeZone()) { if (!Board.getFactionAt(to).isSafeZone()) {
Board.setFactionAt(Factions.i.getSafeZone(), to); Board.setFactionAt(Factions.i.getSafeZone(), to);
me.msg("<i>This land is now a safe zone."); me.msg("<i>This land is now a safe zone.");
} }
} }
} else if (me.isAutoWarClaimEnabled()) { }
else if (me.isAutoWarClaimEnabled()) {
if (!Permission.MANAGE_WAR_ZONE.has(player)) { if (!Permission.MANAGE_WAR_ZONE.has(player)) {
me.setIsAutoWarClaimEnabled(false); me.setIsAutoWarClaimEnabled(false);
} else { }
else {
if (!Board.getFactionAt(to).isWarZone()) { if (!Board.getFactionAt(to).isWarZone()) {
Board.setFactionAt(Factions.i.getWarZone(), to); Board.setFactionAt(Factions.i.getWarZone(), to);
me.msg("<i>This land is now a war zone."); me.msg("<i>This land is now a war zone.");
@ -137,14 +140,16 @@ public class FactionsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
// only need to check right-clicks and physical as of MC 1.4+; good performance boost // only need to check right-clicks and physical as of MC 1.4+; good performance boost
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) { return; }
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
if (block == null) return; // clicked in air, apparently if (block == null) {
return; // clicked in air, apparently
}
if (!canPlayerUseBlock(player, block, false)) { if (!canPlayerUseBlock(player, block, false)) {
event.setCancelled(true); event.setCancelled(true);
@ -165,7 +170,9 @@ public class FactionsPlayerListener implements Listener {
return; return;
} }
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; // only interested on right-clicks for below if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return; // only interested on right-clicks for below
}
if (!playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) { if (!playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) {
event.setCancelled(true); event.setCancelled(true);
@ -184,10 +191,8 @@ public class FactionsPlayerListener implements Listener {
// returns the current attempt count // returns the current attempt count
public int increment() { public int increment() {
long Now = System.currentTimeMillis(); long Now = System.currentTimeMillis();
if (Now > lastAttempt + 2000) if (Now > lastAttempt + 2000) { attempts = 1; }
attempts = 1; else { attempts++; }
else
attempts++;
lastAttempt = Now; lastAttempt = Now;
return attempts; return attempts;
} }
@ -196,44 +201,47 @@ public class FactionsPlayerListener implements Listener {
public static boolean playerCanUseItemHere(Player player, Location location, Material material, boolean justCheck) { public static boolean playerCanUseItemHere(Player player, Location location, Material material, boolean justCheck) {
String name = player.getName(); String name = player.getName();
if (Conf.playersWhoBypassAllProtection.contains(name)) return true; if (Conf.playersWhoBypassAllProtection.contains(name)) { return true; }
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
if (me.isAdminBypassing()) return true; if (me.isAdminBypassing()) { return true; }
FLocation loc = new FLocation(location); FLocation loc = new FLocation(location);
Faction otherFaction = Board.getFactionAt(loc); Faction otherFaction = Board.getFactionAt(loc);
if (otherFaction.hasPlayersOnline()) { if (otherFaction.hasPlayersOnline()) {
if (!Conf.territoryDenyUseageMaterials.contains(material)) if (!Conf.territoryDenyUseageMaterials.contains(material)) {
return true; // Item isn't one we're preventing for online factions. return true; // Item isn't one we're preventing for online factions.
} else { }
if (!Conf.territoryDenyUseageMaterialsWhenOffline.contains(material)) }
else {
if (!Conf.territoryDenyUseageMaterialsWhenOffline.contains(material)) {
return true; // Item isn't one we're preventing for offline factions. return true; // Item isn't one we're preventing for offline factions.
}
} }
if (otherFaction.isNone()) { if (otherFaction.isNone()) {
if (!Conf.wildernessDenyUseage || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) if (!Conf.wildernessDenyUseage || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) {
return true; // This is not faction territory. Use whatever you like here. return true; // This is not faction territory. Use whatever you like here.
}
if (!justCheck) if (!justCheck) {
me.msg("<b>You can't use <h>%s<b> in the wilderness.", TextUtil.getMaterialName(material)); me.msg("<b>You can't use <h>%s<b> in the wilderness.", TextUtil.getMaterialName(material));
}
return false; return false;
} else if (otherFaction.isSafeZone()) { }
if (!Conf.safeZoneDenyUseage || Permission.MANAGE_SAFE_ZONE.has(player)) else if (otherFaction.isSafeZone()) {
return true; if (!Conf.safeZoneDenyUseage || Permission.MANAGE_SAFE_ZONE.has(player)) { return true; }
if (!justCheck) if (!justCheck) { me.msg("<b>You can't use <h>%s<b> in a safe zone.", TextUtil.getMaterialName(material)); }
me.msg("<b>You can't use <h>%s<b> in a safe zone.", TextUtil.getMaterialName(material));
return false; return false;
} else if (otherFaction.isWarZone()) { }
if (!Conf.warZoneDenyUseage || Permission.MANAGE_WAR_ZONE.has(player)) else if (otherFaction.isWarZone()) {
return true; if (!Conf.warZoneDenyUseage || Permission.MANAGE_WAR_ZONE.has(player)) { return true; }
if (!justCheck) if (!justCheck) { me.msg("<b>You can't use <h>%s<b> in a war zone.", TextUtil.getMaterialName(material)); }
me.msg("<b>You can't use <h>%s<b> in a war zone.", TextUtil.getMaterialName(material));
return false; return false;
} }
@ -243,16 +251,18 @@ public class FactionsPlayerListener implements Listener {
// Cancel if we are not in our own territory // Cancel if we are not in our own territory
if (rel.confDenyUseage()) { if (rel.confDenyUseage()) {
if (!justCheck) if (!justCheck) {
me.msg("<b>You can't use <h>%s<b> in the territory of <h>%s<b>.", TextUtil.getMaterialName(material), otherFaction.getTag(myFaction)); me.msg("<b>You can't use <h>%s<b> in the territory of <h>%s<b>.", TextUtil.getMaterialName(material), otherFaction.getTag(myFaction));
}
return false; return false;
} }
// Also cancel if player doesn't have ownership rights for this claim // Also cancel if player doesn't have ownership rights for this claim
if (Conf.ownedAreasEnabled && Conf.ownedAreaDenyUseage && !otherFaction.playerHasOwnershipRights(me, loc)) { if (Conf.ownedAreasEnabled && Conf.ownedAreaDenyUseage && !otherFaction.playerHasOwnershipRights(me, loc)) {
if (!justCheck) if (!justCheck) {
me.msg("<b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>.", TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc)); me.msg("<b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>.", TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc));
}
return false; return false;
} }
@ -261,26 +271,24 @@ public class FactionsPlayerListener implements Listener {
} }
public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) { public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) {
if (Conf.playersWhoBypassAllProtection.contains(player.getName())) return true; if (Conf.playersWhoBypassAllProtection.contains(player.getName())) { return true; }
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
if (me.isAdminBypassing()) return true; if (me.isAdminBypassing()) { return true; }
Material material = block.getType(); Material material = block.getType();
FLocation loc = new FLocation(block); FLocation loc = new FLocation(block);
Faction otherFaction = Board.getFactionAt(loc); Faction otherFaction = Board.getFactionAt(loc);
// no door/chest/whatever protection in wilderness, war zones, or safe zones // no door/chest/whatever protection in wilderness, war zones, or safe zones
if (!otherFaction.isNormal()) if (!otherFaction.isNormal()) { return true; }
return true;
// We only care about some material types. // We only care about some material types.
if (otherFaction.hasPlayersOnline()) { if (otherFaction.hasPlayersOnline()) {
if (!Conf.territoryProtectedMaterials.contains(material)) if (!Conf.territoryProtectedMaterials.contains(material)) { return true; }
return true; }
} else { else {
if (!Conf.territoryProtectedMaterialsWhenOffline.contains(material)) if (!Conf.territoryProtectedMaterialsWhenOffline.contains(material)) { return true; }
return true;
} }
Faction myFaction = me.getFaction(); Faction myFaction = me.getFaction();
@ -288,16 +296,18 @@ public class FactionsPlayerListener implements Listener {
// You may use any block unless it is another faction's territory... // You may use any block unless it is another faction's territory...
if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) { if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) {
if (!justCheck) if (!justCheck) {
me.msg("<b>You can't %s <h>%s<b> in the territory of <h>%s<b>.", (material == Material.SOIL ? "trample" : "use"), TextUtil.getMaterialName(material), otherFaction.getTag(myFaction)); me.msg("<b>You can't %s <h>%s<b> in the territory of <h>%s<b>.", (material == Material.SOIL ? "trample" : "use"), TextUtil.getMaterialName(material), otherFaction.getTag(myFaction));
}
return false; return false;
} }
// Also cancel if player doesn't have ownership rights for this claim // Also cancel if player doesn't have ownership rights for this claim
if (Conf.ownedAreasEnabled && Conf.ownedAreaProtectMaterials && !otherFaction.playerHasOwnershipRights(me, loc)) { if (Conf.ownedAreasEnabled && Conf.ownedAreaProtectMaterials && !otherFaction.playerHasOwnershipRights(me, loc)) {
if (!justCheck) if (!justCheck) {
me.msg("<b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>.", TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc)); me.msg("<b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>.", TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc));
}
return false; return false;
} }
@ -334,7 +344,7 @@ public class FactionsPlayerListener implements Listener {
// but these separate bucket events below always fire without fail // but these separate bucket events below always fire without fail
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -347,7 +357,7 @@ public class FactionsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerBucketFill(PlayerBucketFillEvent event) { public void onPlayerBucketFill(PlayerBucketFillEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -359,16 +369,16 @@ public class FactionsPlayerListener implements Listener {
} }
public static boolean preventCommand(String fullCmd, Player player) { public static boolean preventCommand(String fullCmd, Player player) {
if ((Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryEnemyDenyCommands.isEmpty() && Conf.permanentFactionMemberDenyCommands.isEmpty())) if ((Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryEnemyDenyCommands.isEmpty() && Conf.permanentFactionMemberDenyCommands.isEmpty())) {
return false; return false;
}
fullCmd = fullCmd.toLowerCase(); fullCmd = fullCmd.toLowerCase();
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
String shortCmd; // command without the slash at the beginning String shortCmd; // command without the slash at the beginning
if (fullCmd.startsWith("/")) if (fullCmd.startsWith("/")) { shortCmd = fullCmd.substring(1); }
shortCmd = fullCmd.substring(1);
else { else {
shortCmd = fullCmd; shortCmd = fullCmd;
fullCmd = "/" + fullCmd; fullCmd = "/" + fullCmd;
@ -422,15 +432,14 @@ public class FactionsPlayerListener implements Listener {
} }
cmdCheck = cmdCheck.toLowerCase(); cmdCheck = cmdCheck.toLowerCase();
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) { return true; }
return true;
} }
return false; return false;
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) { return; }
FPlayer badGuy = FPlayers.i.get(event.getPlayer()); FPlayer badGuy = FPlayers.i.get(event.getPlayer());
if (badGuy == null) { if (badGuy == null) {
@ -439,8 +448,7 @@ public class FactionsPlayerListener implements Listener {
// if player was banned (not just kicked), get rid of their stored info // if player was banned (not just kicked), get rid of their stored info
if (Conf.removePlayerDataWhenBanned && event.getReason().equals("Banned by admin.")) { if (Conf.removePlayerDataWhenBanned && event.getReason().equals("Banned by admin.")) {
if (badGuy.getRole() == Role.ADMIN) if (badGuy.getRole() == Role.ADMIN) { badGuy.getFaction().promoteNewLeader(); }
badGuy.getFaction().promoteNewLeader();
badGuy.leave(false); badGuy.leave(false);
badGuy.detach(); badGuy.detach();

View File

@ -27,8 +27,8 @@ public enum ChatMode {
} }
public ChatMode getNext() { public ChatMode getNext() {
if (this == PUBLIC) return ALLIANCE; if (this == PUBLIC) { return ALLIANCE; }
if (this == ALLIANCE) return FACTION; if (this == ALLIANCE) { return FACTION; }
return PUBLIC; return PUBLIC;
} }
} }

View File

@ -48,78 +48,55 @@ public enum Relation {
} }
public ChatColor getColor() { public ChatColor getColor() {
if (this == MEMBER) if (this == MEMBER) { return Conf.colorMember; }
return Conf.colorMember; else if (this == ALLY) { return Conf.colorAlly; }
else if (this == ALLY) else if (this == NEUTRAL) { return Conf.colorNeutral; }
return Conf.colorAlly; else { return Conf.colorEnemy; }
else if (this == NEUTRAL)
return Conf.colorNeutral;
else
return Conf.colorEnemy;
} }
// return appropriate Conf setting for DenyBuild based on this relation and their online status // return appropriate Conf setting for DenyBuild based on this relation and their online status
public boolean confDenyBuild(boolean online) { public boolean confDenyBuild(boolean online) {
if (isMember()) if (isMember()) { return false; }
return false;
if (online) { if (online) {
if (isEnemy()) if (isEnemy()) { return Conf.territoryEnemyDenyBuild; }
return Conf.territoryEnemyDenyBuild; else if (isAlly()) { return Conf.territoryAllyDenyBuild; }
else if (isAlly()) else { return Conf.territoryDenyBuild; }
return Conf.territoryAllyDenyBuild; }
else else {
return Conf.territoryDenyBuild; if (isEnemy()) { return Conf.territoryEnemyDenyBuildWhenOffline; }
} else { else if (isAlly()) { return Conf.territoryAllyDenyBuildWhenOffline; }
if (isEnemy()) else { return Conf.territoryDenyBuildWhenOffline; }
return Conf.territoryEnemyDenyBuildWhenOffline;
else if (isAlly())
return Conf.territoryAllyDenyBuildWhenOffline;
else
return Conf.territoryDenyBuildWhenOffline;
} }
} }
// return appropriate Conf setting for PainBuild based on this relation and their online status // return appropriate Conf setting for PainBuild based on this relation and their online status
public boolean confPainBuild(boolean online) { public boolean confPainBuild(boolean online) {
if (isMember()) if (isMember()) { return false; }
return false;
if (online) { if (online) {
if (isEnemy()) if (isEnemy()) { return Conf.territoryEnemyPainBuild; }
return Conf.territoryEnemyPainBuild; else if (isAlly()) { return Conf.territoryAllyPainBuild; }
else if (isAlly()) else { return Conf.territoryPainBuild; }
return Conf.territoryAllyPainBuild; }
else else {
return Conf.territoryPainBuild; if (isEnemy()) { return Conf.territoryEnemyPainBuildWhenOffline; }
} else { else if (isAlly()) { return Conf.territoryAllyPainBuildWhenOffline; }
if (isEnemy()) else { return Conf.territoryPainBuildWhenOffline; }
return Conf.territoryEnemyPainBuildWhenOffline;
else if (isAlly())
return Conf.territoryAllyPainBuildWhenOffline;
else
return Conf.territoryPainBuildWhenOffline;
} }
} }
// return appropriate Conf setting for DenyUseage based on this relation // return appropriate Conf setting for DenyUseage based on this relation
public boolean confDenyUseage() { public boolean confDenyUseage() {
if (isMember()) if (isMember()) { return false; }
return false; else if (isEnemy()) { return Conf.territoryEnemyDenyUseage; }
else if (isEnemy()) else if (isAlly()) { return Conf.territoryAllyDenyUseage; }
return Conf.territoryEnemyDenyUseage; else { return Conf.territoryDenyUseage; }
else if (isAlly())
return Conf.territoryAllyDenyUseage;
else
return Conf.territoryDenyUseage;
} }
public double getRelationCost() { public double getRelationCost() {
if (isEnemy()) if (isEnemy()) { return Conf.econCostEnemy; }
return Conf.econCostEnemy; else if (isAlly()) { return Conf.econCostAlly; }
else if (isAlly()) else { return Conf.econCostNeutral; }
return Conf.econCostAlly;
else
return Conf.econCostNeutral;
} }
} }

View File

@ -33,29 +33,18 @@ public class AsciiCompass {
public static AsciiCompass.Point getCompassPointForDirection(double inDegrees) { public static AsciiCompass.Point getCompassPointForDirection(double inDegrees) {
double degrees = (inDegrees - 180) % 360; double degrees = (inDegrees - 180) % 360;
if (degrees < 0) if (degrees < 0) { degrees += 360; }
degrees += 360;
if (0 <= degrees && degrees < 22.5) if (0 <= degrees && degrees < 22.5) { return AsciiCompass.Point.N; }
return AsciiCompass.Point.N; else if (22.5 <= degrees && degrees < 67.5) { return AsciiCompass.Point.NE; }
else if (22.5 <= degrees && degrees < 67.5) else if (67.5 <= degrees && degrees < 112.5) { return AsciiCompass.Point.E; }
return AsciiCompass.Point.NE; else if (112.5 <= degrees && degrees < 157.5) { return AsciiCompass.Point.SE; }
else if (67.5 <= degrees && degrees < 112.5) else if (157.5 <= degrees && degrees < 202.5) { return AsciiCompass.Point.S; }
return AsciiCompass.Point.E; else if (202.5 <= degrees && degrees < 247.5) { return AsciiCompass.Point.SW; }
else if (112.5 <= degrees && degrees < 157.5) else if (247.5 <= degrees && degrees < 292.5) { return AsciiCompass.Point.W; }
return AsciiCompass.Point.SE; else if (292.5 <= degrees && degrees < 337.5) { return AsciiCompass.Point.NW; }
else if (157.5 <= degrees && degrees < 202.5) else if (337.5 <= degrees && degrees < 360.0) { return AsciiCompass.Point.N; }
return AsciiCompass.Point.S; else { return null; }
else if (202.5 <= degrees && degrees < 247.5)
return AsciiCompass.Point.SW;
else if (247.5 <= degrees && degrees < 292.5)
return AsciiCompass.Point.W;
else if (292.5 <= degrees && degrees < 337.5)
return AsciiCompass.Point.NW;
else if (337.5 <= degrees && degrees < 360.0)
return AsciiCompass.Point.N;
else
return null;
} }
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) { public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) {

View File

@ -27,7 +27,7 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
return; return;
} }
if (!readyToGo) return; if (!readyToGo) { return; }
// this is set so it only does one iteration at a time, no matter how frequently the timer fires // this is set so it only does one iteration at a time, no matter how frequently the timer fires
readyToGo = false; readyToGo = false;
// and this is tracked to keep one iteration from dragging on too long and possibly choking the system if there are a very large number of players to go through // and this is tracked to keep one iteration from dragging on too long and possibly choking the system if there are a very large number of players to go through
@ -44,14 +44,14 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
FPlayer fplayer = iterator.next(); FPlayer fplayer = iterator.next();
if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) { if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) {
if (Conf.logFactionLeave || Conf.logFactionKick) if (Conf.logFactionLeave || Conf.logFactionKick) {
P.p.log("Player " + fplayer.getName() + " was auto-removed due to inactivity."); P.p.log("Player " + fplayer.getName() + " was auto-removed due to inactivity.");
}
// if player is faction admin, sort out the faction since he's going away // if player is faction admin, sort out the faction since he's going away
if (fplayer.getRole() == Role.ADMIN) { if (fplayer.getRole() == Role.ADMIN) {
Faction faction = fplayer.getFaction(); Faction faction = fplayer.getFaction();
if (faction != null) if (faction != null) { fplayer.getFaction().promoteNewLeader(); }
fplayer.getFaction().promoteNewLeader();
} }
fplayer.leave(false); fplayer.leave(false);

View File

@ -12,14 +12,12 @@ public class AutoLeaveTask implements Runnable {
} }
public synchronized void run() { public synchronized void run() {
if (task != null && !task.isFinished()) if (task != null && !task.isFinished()) { return; }
return;
task = new AutoLeaveProcessTask(); task = new AutoLeaveProcessTask();
task.runTaskTimer(P.p, 1, 1); task.runTaskTimer(P.p, 1, 1);
// maybe setting has been changed? if so, restart this task at new rate // maybe setting has been changed? if so, restart this task at new rate
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) { P.p.startAutoLeaveTask(true); }
P.p.startAutoLeaveTask(true);
} }
} }

View File

@ -57,11 +57,11 @@ public class LazyLocation {
// This initializes the Location // This initializes the Location
private void initLocation() { private void initLocation() {
// if location is already initialized, simply return // if location is already initialized, simply return
if (location != null) return; if (location != null) { return; }
// get World; hopefully it's initialized at this point // get World; hopefully it's initialized at this point
World world = Bukkit.getWorld(worldName); World world = Bukkit.getWorld(worldName);
if (world == null) return; if (world == null) { return; }
// store the Location for future calls, and pass it on // store the Location for future calls, and pass it on
location = new Location(world, x, y, z, yaw, pitch); location = new Location(world, x, y, z, yaw, pitch);

View File

@ -301,7 +301,8 @@ public final class Metrics {
// It does not reroute POST requests so we need to go around it // It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) { if (isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY); connection = url.openConnection(Proxy.NO_PROXY);
} else { }
else {
connection = url.openConnection(); connection = url.openConnection();
} }
@ -339,7 +340,8 @@ public final class Metrics {
if (response == null || response.startsWith("ERR") || response.startsWith("7")) { if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
if (response == null) { if (response == null) {
response = "null"; response = "null";
} else if (response.startsWith("7")) { }
else if (response.startsWith("7")) {
response = response.substring(response.startsWith("7,") ? 2 : 1); response = response.substring(response.startsWith("7,") ? 2 : 1);
} }
@ -419,7 +421,8 @@ public final class Metrics {
if (isValueNumeric) { if (isValueNumeric) {
json.append(value); json.append(value);
} else { }
else {
json.append(escapeJSON(value)); json.append(escapeJSON(value));
} }
} }
@ -460,7 +463,8 @@ public final class Metrics {
if (chr < ' ') { if (chr < ' ') {
String t = "000" + Integer.toHexString(chr); String t = "000" + Integer.toHexString(chr);
builder.append("\\u").append(t.substring(t.length() - 4)); builder.append("\\u").append(t.substring(t.length() - 4));
} else { }
else {
builder.append(chr); builder.append(chr);
} }
break; break;

View File

@ -39,10 +39,10 @@ public class MiscUtil {
/// TODO create tag whitelist!! /// TODO create tag whitelist!!
public static HashSet<String> substanceChars = new HashSet<String>(Arrays.asList(new String[]{ public static HashSet<String> substanceChars = new HashSet<String>(Arrays.asList(new String[]{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z" "s", "t", "u", "v", "w", "x", "y", "z"
})); }));
public static String getComparisonString(String str) { public static String getComparisonString(String str) {

View File

@ -13,7 +13,9 @@ public class RelationUtil {
String ret = ""; String ret = "";
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction == null) return "ERROR"; // ERROR if (thatFaction == null) {
return "ERROR"; // ERROR
}
Faction myFaction = getFaction(me); Faction myFaction = getFaction(me);
// if (myFaction == null) return that.describeTo(null); // no relation, but can show basic name or tag // if (myFaction == null) return that.describeTo(null); // no relation, but can show basic name or tag
@ -21,16 +23,20 @@ public class RelationUtil {
if (that instanceof Faction) { if (that instanceof Faction) {
if (me instanceof FPlayer && myFaction == thatFaction) { if (me instanceof FPlayer && myFaction == thatFaction) {
ret = "your faction"; ret = "your faction";
} else { }
else {
ret = thatFaction.getTag(); ret = thatFaction.getTag();
} }
} else if (that instanceof FPlayer) { }
else if (that instanceof FPlayer) {
FPlayer fplayerthat = (FPlayer) that; FPlayer fplayerthat = (FPlayer) that;
if (that == me) { if (that == me) {
ret = "you"; ret = "you";
} else if (thatFaction == myFaction) { }
else if (thatFaction == myFaction) {
ret = fplayerthat.getNameAndTitle(); ret = fplayerthat.getNameAndTitle();
} else { }
else {
ret = fplayerthat.getNameAndTag(); ret = fplayerthat.getNameAndTag();
} }
} }
@ -52,10 +58,14 @@ public class RelationUtil {
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) { public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) {
Faction fthat = getFaction(that); Faction fthat = getFaction(that);
if (fthat == null) return Relation.NEUTRAL; // ERROR if (fthat == null) {
return Relation.NEUTRAL; // ERROR
}
Faction fme = getFaction(me); Faction fme = getFaction(me);
if (fme == null) return Relation.NEUTRAL; // ERROR if (fme == null) {
return Relation.NEUTRAL; // ERROR
}
if (!fthat.isNormal() || !fme.isNormal()) { if (!fthat.isNormal() || !fme.isNormal()) {
return Relation.NEUTRAL; return Relation.NEUTRAL;

View File

@ -98,19 +98,18 @@ public abstract class SpiralTask implements Runnable {
*/ */
public final void setTaskID(int ID) { public final void setTaskID(int ID) {
if (ID == -1) if (ID == -1) { this.stop(); }
this.stop();
taskID = ID; taskID = ID;
} }
public final void run() { public final void run() {
if (!this.valid() || !readyToGo) return; if (!this.valid() || !readyToGo) { return; }
// this is set so it only does one iteration at a time, no matter how frequently the timer fires // this is set so it only does one iteration at a time, no matter how frequently the timer fires
readyToGo = false; readyToGo = false;
// make sure we're still inside the specified radius // make sure we're still inside the specified radius
if (!this.insideRadius()) return; if (!this.insideRadius()) { return; }
// track this to keep one iteration from dragging on too long and possibly choking the system // track this to keep one iteration from dragging on too long and possibly choking the system
long loopStartTime = now(); long loopStartTime = now();
@ -124,8 +123,7 @@ public abstract class SpiralTask implements Runnable {
} }
// move on to next chunk in spiral // move on to next chunk in spiral
if (!this.moveToNext()) if (!this.moveToNext()) { return; }
return;
} }
// ready for the next iteration to run // ready for the next iteration to run
@ -134,15 +132,16 @@ public abstract class SpiralTask implements Runnable {
// step through chunks in spiral pattern from center; returns false if we're done, otherwise returns true // step through chunks in spiral pattern from center; returns false if we're done, otherwise returns true
public final boolean moveToNext() { public final boolean moveToNext() {
if (!this.valid()) return false; if (!this.valid()) { return false; }
// make sure we don't need to turn down the next leg of the spiral // make sure we don't need to turn down the next leg of the spiral
if (current < length) { if (current < length) {
current++; current++;
// if we're outside the radius, we're done // if we're outside the radius, we're done
if (!this.insideRadius()) return false; if (!this.insideRadius()) { return false; }
} else { // one leg/side of the spiral down... }
else { // one leg/side of the spiral down...
current = 0; current = 0;
isZLeg ^= true; isZLeg ^= true;
// every second leg (between X and Z legs, negative or positive), length increases // every second leg (between X and Z legs, negative or positive), length increases
@ -153,18 +152,15 @@ public abstract class SpiralTask implements Runnable {
} }
// move one chunk further in the appropriate direction // move one chunk further in the appropriate direction
if (isZLeg) if (isZLeg) { z += (isNeg) ? -1 : 1; }
z += (isNeg) ? -1 : 1; else { x += (isNeg) ? -1 : 1; }
else
x += (isNeg) ? -1 : 1;
return true; return true;
} }
public final boolean insideRadius() { public final boolean insideRadius() {
boolean inside = current < limit; boolean inside = current < limit;
if (!inside) if (!inside) { this.finish(); }
this.finish();
return inside; return inside;
} }
@ -176,7 +172,7 @@ public abstract class SpiralTask implements Runnable {
// we're done, whether finished or cancelled // we're done, whether finished or cancelled
public final void stop() { public final void stop() {
if (!this.valid()) return; if (!this.valid()) { return; }
readyToGo = false; readyToGo = false;
Bukkit.getServer().getScheduler().cancelTask(taskID); Bukkit.getServer().getScheduler().cancelTask(taskID);

View File

@ -11,8 +11,9 @@ public class FCommandHandler implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (P.p.handleCommand(sender, cmd.getName() + args)) { if (P.p.handleCommand(sender, cmd.getName() + args)) {
if (P.p.logPlayerCommands()) if (P.p.logPlayerCommands()) {
Bukkit.getLogger().info("[PLAYER_COMMAND] " + sender.getName() + ": " + cmd.getName() + args); Bukkit.getLogger().info("[PLAYER_COMMAND] " + sender.getName() + ": " + cmd.getName() + args);
}
} }
return false; return false;
} }

View File

@ -91,7 +91,8 @@ public abstract class MCommand<T extends MPlugin> {
if (sender instanceof Player) { if (sender instanceof Player) {
this.me = (Player) sender; this.me = (Player) sender;
this.senderIsConsole = false; this.senderIsConsole = false;
} else { }
else {
this.me = null; this.me = null;
this.senderIsConsole = true; this.senderIsConsole = true;
} }
@ -110,9 +111,9 @@ public abstract class MCommand<T extends MPlugin> {
} }
} }
if (!validCall(this.sender, this.args)) return; if (!validCall(this.sender, this.args)) { return; }
if (!this.isEnabled()) return; if (!this.isEnabled()) { return; }
perform(); perform();
} }
@ -164,7 +165,7 @@ public abstract class MCommand<T extends MPlugin> {
} }
public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) { public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) {
if (this.permission == null) return true; if (this.permission == null) { return true; }
return p.perm.has(sender, this.permission, informSenderIfNot); return p.perm.has(sender, this.permission, informSenderIfNot);
} }
@ -219,7 +220,8 @@ public abstract class MCommand<T extends MPlugin> {
String val = optionalArg.getValue(); String val = optionalArg.getValue();
if (val == null) { if (val == null) {
val = ""; val = "";
} else { }
else {
val = "=" + val; val = "=" + val;
} }
args.add("[" + optionalArg.getKey() + val + "]"); args.add("[" + optionalArg.getKey() + val + "]");
@ -290,7 +292,7 @@ public abstract class MCommand<T extends MPlugin> {
// INT ====================== // INT ======================
public Integer strAsInt(String str, Integer def) { public Integer strAsInt(String str, Integer def) {
if (str == null) return def; if (str == null) { return def; }
try { try {
Integer ret = Integer.parseInt(str); Integer ret = Integer.parseInt(str);
return ret; return ret;
@ -309,7 +311,7 @@ public abstract class MCommand<T extends MPlugin> {
// Double ====================== // Double ======================
public Double strAsDouble(String str, Double def) { public Double strAsDouble(String str, Double def) {
if (str == null) return def; if (str == null) { return def; }
try { try {
Double ret = Double.parseDouble(str); Double ret = Double.parseDouble(str);
return ret; return ret;
@ -338,7 +340,7 @@ public abstract class MCommand<T extends MPlugin> {
public Boolean argAsBool(int idx, boolean def) { public Boolean argAsBool(int idx, boolean def) {
String str = this.argAsString(idx); String str = this.argAsString(idx);
if (str == null) return def; if (str == null) { return def; }
return strAsBool(str); return strAsBool(str);
} }

View File

@ -90,8 +90,7 @@ public abstract class MPlugin extends JavaPlugin {
// reference command will be used to prevent "unknown command" console messages // reference command will be used to prevent "unknown command" console messages
try { try {
Map<String, Map<String, Object>> refCmd = this.getDescription().getCommands(); Map<String, Map<String, Object>> refCmd = this.getDescription().getCommands();
if (refCmd != null && !refCmd.isEmpty()) if (refCmd != null && !refCmd.isEmpty()) { this.refCommand = (String) (refCmd.keySet().toArray()[0]); }
this.refCommand = (String) (refCmd.keySet().toArray()[0]);
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
} }
@ -186,8 +185,7 @@ public abstract class MPlugin extends JavaPlugin {
saveTask = null; saveTask = null;
} }
// only save data if plugin actually loaded successfully // only save data if plugin actually loaded successfully
if (loadSuccessful) if (loadSuccessful) { EM.saveAllToDisc(); }
EM.saveAllToDisc();
log("Disabled"); log("Disabled");
} }
@ -204,10 +202,10 @@ public abstract class MPlugin extends JavaPlugin {
public GsonBuilder getGsonBuilder() { public GsonBuilder getGsonBuilder() {
return new GsonBuilder() return new GsonBuilder()
.setPrettyPrinting() .setPrettyPrinting()
.disableHtmlEscaping() .disableHtmlEscaping()
.serializeNulls() .serializeNulls()
.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE); .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -237,7 +235,7 @@ public abstract class MPlugin extends JavaPlugin {
}.getType(); }.getType();
Map<String, String> tagsFromFile = this.persist.load(type, "tags"); Map<String, String> tagsFromFile = this.persist.load(type, "tags");
if (tagsFromFile != null) this.rawTags.putAll(tagsFromFile); if (tagsFromFile != null) { this.rawTags.putAll(tagsFromFile); }
this.persist.save(this.rawTags, "tags"); this.persist.save(this.rawTags, "tags");
for (Entry<String, String> rawTag : this.rawTags.entrySet()) { for (Entry<String, String> rawTag : this.rawTags.entrySet()) {
@ -266,17 +264,17 @@ public abstract class MPlugin extends JavaPlugin {
} }
for (final MCommand<?> command : this.getBaseCommands()) { for (final MCommand<?> command : this.getBaseCommands()) {
if (noSlash && !command.allowNoSlashAccess) continue; if (noSlash && !command.allowNoSlashAccess) { continue; }
for (String alias : command.aliases) { for (String alias : command.aliases) {
// disallow double-space after alias, so specific commands can be prevented (preventing "f home" won't prevent "f home") // disallow double-space after alias, so specific commands can be prevented (preventing "f home" won't prevent "f home")
if (commandString.startsWith(alias + " ")) return false; if (commandString.startsWith(alias + " ")) { return false; }
if (commandString.startsWith(alias + " ") || commandString.equals(alias)) { if (commandString.startsWith(alias + " ") || commandString.equals(alias)) {
final List<String> args = new ArrayList<String>(Arrays.asList(commandString.split("\\s+"))); final List<String> args = new ArrayList<String>(Arrays.asList(commandString.split("\\s+")));
args.remove(0); args.remove(0);
if (testOnly) return true; if (testOnly) { return true; }
if (async) { if (async) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@ -285,8 +283,8 @@ public abstract class MPlugin extends JavaPlugin {
command.execute(sender, args); command.execute(sender, args);
} }
}); });
} else }
command.execute(sender, args); else { command.execute(sender, args); }
return true; return true;
} }

View File

@ -26,8 +26,9 @@ public class MPluginSecretPlayerListener implements Listener {
//@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) //@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (p.handleCommand(event.getPlayer(), event.getMessage())) { if (p.handleCommand(event.getPlayer(), event.getMessage())) {
if (p.logPlayerCommands()) if (p.logPlayerCommands()) {
Bukkit.getLogger().info("[PLAYER_COMMAND] " + event.getPlayer().getName() + ": " + event.getMessage()); Bukkit.getLogger().info("[PLAYER_COMMAND] " + event.getPlayer().getName() + ": " + event.getMessage());
}
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -35,8 +36,9 @@ public class MPluginSecretPlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
if (p.handleCommand(event.getPlayer(), event.getMessage(), false, true)) { if (p.handleCommand(event.getPlayer(), event.getMessage(), false, true)) {
if (p.logPlayerCommands()) if (p.logPlayerCommands()) {
Bukkit.getLogger().info("[PLAYER_COMMAND] " + event.getPlayer().getName() + ": " + event.getMessage()); Bukkit.getLogger().info("[PLAYER_COMMAND] " + event.getPlayer().getName() + ": " + event.getMessage());
}
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -14,7 +14,7 @@ public class MPluginSecretServerListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onServerCommand(ServerCommandEvent event) { public void onServerCommand(ServerCommandEvent event) {
if (event.getCommand().length() == 0) return; if (event.getCommand().length() == 0) { return; }
if (p.handleCommand(event.getSender(), event.getCommand())) { if (p.handleCommand(event.getSender(), event.getCommand())) {
event.setCommand(p.refCommand); event.setCommand(p.refCommand);

View File

@ -99,24 +99,24 @@ public abstract class EntityCollection<E extends Entity> {
} }
public E get(String id) { public E get(String id) {
if (this.creative) return this.getCreative(id); if (this.creative) { return this.getCreative(id); }
return id2entity.get(id); return id2entity.get(id);
} }
public E getCreative(String id) { public E getCreative(String id) {
E e = id2entity.get(id); E e = id2entity.get(id);
if (e != null) return e; if (e != null) { return e; }
return this.create(id); return this.create(id);
} }
public boolean exists(String id) { public boolean exists(String id) {
if (id == null) return false; if (id == null) { return false; }
return id2entity.get(id) != null; return id2entity.get(id) != null;
} }
public E getBestIdMatch(String pattern) { public E getBestIdMatch(String pattern) {
String id = TextUtil.getBestStartWithCI(this.id2entity.keySet(), pattern); String id = TextUtil.getBestStartWithCI(this.id2entity.keySet(), pattern);
if (id == null) return null; if (id == null) { return null; }
return this.id2entity.get(id); return this.id2entity.get(id);
} }
@ -129,7 +129,7 @@ public abstract class EntityCollection<E extends Entity> {
} }
public synchronized E create(String id) { public synchronized E create(String id) {
if (!this.isIdFree(id)) return null; if (!this.isIdFree(id)) { return null; }
E e = null; E e = null;
try { try {
@ -150,7 +150,7 @@ public abstract class EntityCollection<E extends Entity> {
// -------------------------------------------- // // -------------------------------------------- //
public void attach(E entity) { public void attach(E entity) {
if (entity.getId() != null) return; if (entity.getId() != null) { return; }
entity.setId(this.getNextId()); entity.setId(this.getNextId());
this.entities.add(entity); this.entities.add(entity);
this.id2entity.put(entity.getId(), entity); this.id2entity.put(entity.getId(), entity);
@ -165,7 +165,7 @@ public abstract class EntityCollection<E extends Entity> {
public void detach(String id) { public void detach(String id) {
E entity = this.id2entity.get(id); E entity = this.id2entity.get(id);
if (entity == null) return; if (entity == null) { return; }
this.detach(entity); this.detach(entity);
} }
@ -185,7 +185,7 @@ public abstract class EntityCollection<E extends Entity> {
private boolean saveIsRunning = false; private boolean saveIsRunning = false;
public boolean saveToDisc() { public boolean saveToDisc() {
if (saveIsRunning) return true; if (saveIsRunning) { return true; }
saveIsRunning = true; saveIsRunning = true;
Map<String, E> entitiesThatShouldBeSaved = new HashMap<String, E>(); Map<String, E> entitiesThatShouldBeSaved = new HashMap<String, E>();
@ -205,7 +205,7 @@ public abstract class EntityCollection<E extends Entity> {
public boolean loadFromDisc() { public boolean loadFromDisc() {
Map<String, E> id2entity = this.loadCore(); Map<String, E> id2entity = this.loadCore();
if (id2entity == null) return false; if (id2entity == null) { return false; }
this.entities.clear(); this.entities.clear();
this.entities.addAll(id2entity.values()); this.entities.addAll(id2entity.values());
this.id2entity.clear(); this.id2entity.clear();
@ -289,7 +289,8 @@ public abstract class EntityCollection<E extends Entity> {
Bukkit.getLogger().log(Level.INFO, "Done converting players.json to UUID."); Bukkit.getLogger().log(Level.INFO, "Done converting players.json to UUID.");
} }
return (Map<String, E>) data; return (Map<String, E>) data;
} else { }
else {
Map<String, Faction> data = this.gson.fromJson(content, type); Map<String, Faction> data = this.gson.fromJson(content, type);
// Do we have any names that need updating in claims or invites? // Do we have any names that need updating in claims or invites?

View File

@ -8,7 +8,7 @@ import java.util.List;
public class PlayerEntity extends Entity { public class PlayerEntity extends Entity {
public Player getPlayer() { public Player getPlayer() {
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.getUniqueId().toString().equals(this.getId())) return player; if (player.getUniqueId().toString().equals(this.getId())) { return player; }
} }
return null; return null;
} }
@ -33,7 +33,7 @@ public class PlayerEntity extends Entity {
public void sendMessage(String msg) { public void sendMessage(String msg) {
Player player = this.getPlayer(); Player player = this.getPlayer();
if (player == null) return; if (player == null) { return; }
player.sendMessage(msg); player.sendMessage(msg);
} }

View File

@ -12,7 +12,7 @@ public class SaveTask implements Runnable {
} }
public void run() { public void run() {
if (!p.getAutoSave() || running) return; if (!p.getAutoSave() || running) { return; }
running = true; running = true;
p.preAutoSave(); p.preAutoSave();
EM.saveAllToDisc(); EM.saveAllToDisc();

View File

@ -47,7 +47,7 @@ public class PermUtil {
* This method tests if me has a certain permission and returns true if me has. Otherwise false * This method tests if me has a certain permission and returns true if me has. Otherwise false
*/ */
public boolean has(CommandSender me, String perm) { public boolean has(CommandSender me, String perm) {
if (me == null) return false; if (me == null) { return false; }
if (!(me instanceof Player)) { if (!(me instanceof Player)) {
return me.hasPermission(perm); return me.hasPermission(perm);
@ -59,19 +59,20 @@ public class PermUtil {
public boolean has(CommandSender me, String perm, boolean informSenderIfNot) { public boolean has(CommandSender me, String perm, boolean informSenderIfNot) {
if (has(me, perm)) { if (has(me, perm)) {
return true; return true;
} else if (informSenderIfNot && me != null) { }
else if (informSenderIfNot && me != null) {
me.sendMessage(this.getForbiddenMessage(perm)); me.sendMessage(this.getForbiddenMessage(perm));
} }
return false; return false;
} }
public <T> T pickFirstVal(CommandSender me, Map<String, T> perm2val) { public <T> T pickFirstVal(CommandSender me, Map<String, T> perm2val) {
if (perm2val == null) return null; if (perm2val == null) { return null; }
T ret = null; T ret = null;
for (Entry<String, T> entry : perm2val.entrySet()) { for (Entry<String, T> entry : perm2val.entrySet()) {
ret = entry.getValue(); ret = entry.getValue();
if (has(me, entry.getKey())) break; if (has(me, entry.getKey())) { break; }
} }
return ret; return ret;

View File

@ -77,7 +77,7 @@ public class Persist {
// backup bad file, so user can attempt to recover their changes from it // backup bad file, so user can attempt to recover their changes from it
File backup = new File(file.getPath() + "_bad"); File backup = new File(file.getPath() + "_bad");
if (backup.exists()) backup.delete(); if (backup.exists()) { backup.delete(); }
p.log(Level.WARNING, "Backing up copy of bad file to: " + backup); p.log(Level.WARNING, "Backing up copy of bad file to: " + backup);
file.renameTo(backup); file.renameTo(backup);

View File

@ -31,7 +31,7 @@ public class SmokeUtil {
// Single ======== // Single ========
public static void spawnSingle(Location location, int direction) { public static void spawnSingle(Location location, int direction) {
if (location == null) return; if (location == null) { return; }
location.getWorld().playEffect(location.clone(), Effect.SMOKE, direction); location.getWorld().playEffect(location.clone(), Effect.SMOKE, direction);
} }

View File

@ -38,7 +38,7 @@ public enum TL {
/** /**
* Lang enum constructor. * Lang enum constructor.
* *
* @param path The string path. * @param path The string path.
* @param start The default string. * @param start The default string.
*/ */
TL(String path, String start) { TL(String path, String start) {

View File

@ -44,7 +44,8 @@ public class TextUtil {
String repl = tags.get(tag); String repl = tags.get(tag);
if (repl == null) { if (repl == null) {
matcher.appendReplacement(ret, "<" + tag + ">"); matcher.appendReplacement(ret, "<" + tag + ">");
} else { }
else {
matcher.appendReplacement(ret, repl); matcher.appendReplacement(ret, repl);
} }
} }
@ -72,34 +73,34 @@ public class TextUtil {
public static String parseColorAcc(String string) { public static String parseColorAcc(String string) {
return string.replace("`e", "") return string.replace("`e", "")
.replace("`r", ChatColor.RED.toString()).replace("`R", ChatColor.DARK_RED.toString()) .replace("`r", ChatColor.RED.toString()).replace("`R", ChatColor.DARK_RED.toString())
.replace("`y", ChatColor.YELLOW.toString()).replace("`Y", ChatColor.GOLD.toString()) .replace("`y", ChatColor.YELLOW.toString()).replace("`Y", ChatColor.GOLD.toString())
.replace("`g", ChatColor.GREEN.toString()).replace("`G", ChatColor.DARK_GREEN.toString()) .replace("`g", ChatColor.GREEN.toString()).replace("`G", ChatColor.DARK_GREEN.toString())
.replace("`a", ChatColor.AQUA.toString()).replace("`A", ChatColor.DARK_AQUA.toString()) .replace("`a", ChatColor.AQUA.toString()).replace("`A", ChatColor.DARK_AQUA.toString())
.replace("`b", ChatColor.BLUE.toString()).replace("`B", ChatColor.DARK_BLUE.toString()) .replace("`b", ChatColor.BLUE.toString()).replace("`B", ChatColor.DARK_BLUE.toString())
.replace("`p", ChatColor.LIGHT_PURPLE.toString()).replace("`P", ChatColor.DARK_PURPLE.toString()) .replace("`p", ChatColor.LIGHT_PURPLE.toString()).replace("`P", ChatColor.DARK_PURPLE.toString())
.replace("`k", ChatColor.BLACK.toString()).replace("`s", ChatColor.GRAY.toString()) .replace("`k", ChatColor.BLACK.toString()).replace("`s", ChatColor.GRAY.toString())
.replace("`S", ChatColor.DARK_GRAY.toString()).replace("`w", ChatColor.WHITE.toString()); .replace("`S", ChatColor.DARK_GRAY.toString()).replace("`w", ChatColor.WHITE.toString());
} }
public static String parseColorTags(String string) { public static String parseColorTags(String string) {
return string.replace("<empty>", "") return string.replace("<empty>", "")
.replace("<black>", "\u00A70") .replace("<black>", "\u00A70")
.replace("<navy>", "\u00A71") .replace("<navy>", "\u00A71")
.replace("<green>", "\u00A72") .replace("<green>", "\u00A72")
.replace("<teal>", "\u00A73") .replace("<teal>", "\u00A73")
.replace("<red>", "\u00A74") .replace("<red>", "\u00A74")
.replace("<purple>", "\u00A75") .replace("<purple>", "\u00A75")
.replace("<gold>", "\u00A76") .replace("<gold>", "\u00A76")
.replace("<silver>", "\u00A77") .replace("<silver>", "\u00A77")
.replace("<gray>", "\u00A78") .replace("<gray>", "\u00A78")
.replace("<blue>", "\u00A79") .replace("<blue>", "\u00A79")
.replace("<lime>", "\u00A7a") .replace("<lime>", "\u00A7a")
.replace("<aqua>", "\u00A7b") .replace("<aqua>", "\u00A7b")
.replace("<rose>", "\u00A7c") .replace("<rose>", "\u00A7c")
.replace("<pink>", "\u00A7d") .replace("<pink>", "\u00A7d")
.replace("<yellow>", "\u00A7e") .replace("<yellow>", "\u00A7e")
.replace("<white>", "\u00A7f"); .replace("<white>", "\u00A7f");
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -122,8 +123,8 @@ public class TextUtil {
} }
public static String repeat(String s, int times) { public static String repeat(String s, int times) {
if (times <= 0) return ""; if (times <= 0) { return ""; }
else return s + repeat(s, times - 1); else { return s + repeat(s, times - 1); }
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -152,10 +153,10 @@ public class TextUtil {
int eatLeft = (centerlen / 2) - titleizeBalance; int eatLeft = (centerlen / 2) - titleizeBalance;
int eatRight = (centerlen - eatLeft) + titleizeBalance; int eatRight = (centerlen - eatLeft) + titleizeBalance;
if (eatLeft < pivot) if (eatLeft < pivot) {
return parseTags("<a>") + titleizeLine.substring(0, pivot - eatLeft) + center + titleizeLine.substring(pivot + eatRight); return parseTags("<a>") + titleizeLine.substring(0, pivot - eatLeft) + center + titleizeLine.substring(pivot + eatRight);
else }
return parseTags("<a>") + center; else { return parseTags("<a>") + center; }
} }
public ArrayList<String> getPage(List<String> lines, int pageHumanBased, String title) { public ArrayList<String> getPage(List<String> lines, int pageHumanBased, String title) {
@ -169,7 +170,8 @@ public class TextUtil {
if (pagecount == 0) { if (pagecount == 0) {
ret.add(this.parseTags("<i>Sorry. No Pages available.")); ret.add(this.parseTags("<i>Sorry. No Pages available."));
return ret; return ret;
} else if (pageZeroBased < 0 || pageHumanBased > pagecount) { }
else if (pageZeroBased < 0 || pageHumanBased > pagecount) {
ret.add(this.parseTags("<i>Invalid page. Must be between 1 and " + pagecount)); ret.add(this.parseTags("<i>Invalid page. Must be between 1 and " + pagecount));
return ret; return ret;
} }
@ -192,8 +194,8 @@ public class TextUtil {
start = start.toLowerCase(); start = start.toLowerCase();
int minlength = start.length(); int minlength = start.length();
for (String candidate : candidates) { for (String candidate : candidates) {
if (candidate.length() < minlength) continue; if (candidate.length() < minlength) { continue; }
if (!candidate.toLowerCase().startsWith(start)) continue; if (!candidate.toLowerCase().startsWith(start)) { continue; }
// The closer to zero the better // The closer to zero the better
int lendiff = candidate.length() - minlength; int lendiff = candidate.length() - minlength;