Factions3/src/com/massivecraft/factions/FPlayer.java

696 lines
20 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions;
2011-02-06 13:36:11 +01:00
2011-10-22 16:00:24 +02:00
import java.util.HashSet;
import java.util.Set;
2012-03-02 02:16:45 +01:00
import org.bukkit.Bukkit;
2011-02-06 13:36:11 +01:00
import org.bukkit.ChatColor;
import org.bukkit.Location;
2011-02-06 13:36:11 +01:00
import org.bukkit.entity.Player;
2011-07-18 22:06:02 +02:00
2012-03-02 02:16:45 +01:00
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.LandClaimEvent;
2011-10-12 17:25:01 +02:00
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Rel;
2011-10-12 17:25:01 +02:00
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.zcore.persist.PlayerEntity;
2011-02-06 13:36:11 +01:00
/**
* Logged in players always have exactly one FPlayer instance.
* Logged out players may or may not have an FPlayer instance. They will always have one if they are part of a faction.
* This is because only players with a faction are saved to disk (in order to not waste disk space).
*
2011-03-23 12:00:38 +01:00
* The FPlayer is linked to a minecraft player using the player name.
*
* The same instance is always returned for the same player.
* This means you can use the == operator. No .equals method necessary.
*/
2011-10-24 03:02:25 +02:00
// TODO: The players are saved in non order.
2011-10-12 17:25:01 +02:00
public class FPlayer extends PlayerEntity implements EconomyParticipator
2011-10-08 23:22:02 +02:00
{
// FIELD: lastStoodAt
2011-03-22 17:20:21 +01:00
private transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked?
2011-10-24 03:02:25 +02:00
public FLocation getLastStoodAt() { return this.lastStoodAt; }
public void setLastStoodAt(FLocation flocation) { this.lastStoodAt = flocation; }
2011-03-22 17:20:21 +01:00
2011-10-08 23:22:02 +02:00
// FIELD: factionId
private String factionId;
2011-10-10 01:21:05 +02:00
public Faction getFaction() { if(this.factionId == null) {return null;} return Factions.i.get(this.factionId); }
2011-10-08 23:22:02 +02:00
public String getFactionId() { return this.factionId; }
public boolean hasFaction() { return ! factionId.equals("0"); }
public void setFaction(Faction faction)
{
Faction oldFaction = this.getFaction();
if (oldFaction != null) oldFaction.removeFPlayer(this);
faction.addFPlayer(this);
2011-10-08 23:22:02 +02:00
this.factionId = faction.getId();
SpoutFeatures.updateTitle(this, null);
SpoutFeatures.updateTitle(null, this);
2011-10-08 23:22:02 +02:00
}
// FIELD: role
private Rel role;
public Rel getRole() { return this.role; }
public void setRole(Rel role) { this.role = role; SpoutFeatures.updateTitle(this, null); }
2011-10-08 23:22:02 +02:00
// FIELD: title
2011-02-06 13:36:11 +01:00
private String title;
2011-10-24 03:02:25 +02:00
public String getTitle() { return this.title; }
public void setTitle(String title) { this.title = title; }
2011-10-08 23:22:02 +02:00
// FIELD: power
2011-02-06 13:36:11 +01:00
private double power;
// FIELD: powerBoost
// special increase/decrease to min and max power for this player
private double powerBoost;
public double getPowerBoost() { return this.powerBoost; }
public void setPowerBoost(double powerBoost) { this.powerBoost = powerBoost; }
2011-10-08 23:22:02 +02:00
// FIELD: lastPowerUpdateTime
2011-02-06 13:36:11 +01:00
private long lastPowerUpdateTime;
2011-10-08 23:22:02 +02:00
// FIELD: lastLoginTime
2011-03-22 20:36:33 +01:00
private long lastLoginTime;
2011-10-08 23:22:02 +02:00
// FIELD: mapAutoUpdating
private transient boolean mapAutoUpdating;
2011-10-24 03:02:25 +02:00
public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; }
public boolean isMapAutoUpdating() { return mapAutoUpdating; }
2011-10-08 23:22:02 +02:00
// FIELD: autoClaimEnabled
private transient Faction autoClaimFor;
2011-10-24 03:02:25 +02:00
public Faction getAutoClaimFor() { return autoClaimFor; }
public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; }
2011-10-23 22:08:57 +02:00
private transient boolean hasAdminMode = false;
public boolean hasAdminMode() { return this.hasAdminMode; }
public void setHasAdminMode(boolean val) { this.hasAdminMode = val; }
2011-10-09 18:35:39 +02:00
2011-10-08 23:22:02 +02:00
// FIELD: loginPvpDisabled
2011-09-24 12:04:49 +02:00
private transient boolean loginPvpDisabled;
2011-10-08 23:22:02 +02:00
2011-10-12 17:25:01 +02:00
// FIELD: account
public String getAccountId() { return this.getId(); }
2011-10-12 17:25:01 +02:00
2011-03-22 17:20:21 +01:00
// -------------------------------------------- //
// Construct
// -------------------------------------------- //
2011-03-18 17:33:23 +01:00
// GSON need this noarg constructor.
public FPlayer()
{
2011-10-10 01:21:05 +02:00
this.resetFactionData(false);
this.power = Conf.powerPlayerStarting;
2011-03-19 13:00:03 +01:00
this.lastPowerUpdateTime = System.currentTimeMillis();
2011-03-22 20:36:33 +01:00
this.lastLoginTime = System.currentTimeMillis();
2011-03-19 13:00:03 +01:00
this.mapAutoUpdating = false;
this.autoClaimFor = null;
this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false;
this.powerBoost = 0.0;
if ( ! Conf.newPlayerStartingFactionID.equals("0") && Factions.i.exists(Conf.newPlayerStartingFactionID))
{
this.factionId = Conf.newPlayerStartingFactionID;
}
2011-03-19 13:00:03 +01:00
}
2012-02-19 15:32:50 +01:00
public final void resetFactionData(boolean doSpoutUpdate)
{
2012-01-28 17:15:20 +01:00
if (this.factionId != null && Factions.i.exists(this.factionId)) // Avoid infinite loop! TODO: I think that this is needed is a sign we need to refactor.
{
Faction currentFaction = this.getFaction();
if (currentFaction != null)
{
currentFaction.removeFPlayer(this);
}
}
this.factionId = "0"; // The default neutral faction
this.role = Rel.MEMBER;
2011-03-19 13:00:03 +01:00
this.title = "";
this.autoClaimFor = null;
2012-02-19 15:32:50 +01:00
if (doSpoutUpdate)
2011-10-10 01:21:05 +02:00
{
SpoutFeatures.updateTitle(this, null);
SpoutFeatures.updateTitle(null, this);
SpoutFeatures.updateCape(this.getPlayer(), null);
2011-10-10 01:21:05 +02:00
}
}
public void resetFactionData()
{
this.resetFactionData(true);
2011-03-18 17:33:23 +01:00
}
2011-03-22 17:20:21 +01:00
// -------------------------------------------- //
// Getters And Setters
// -------------------------------------------- //
public long getLastLoginTime()
{
2011-03-22 20:36:33 +01:00
return lastLoginTime;
}
public void setLastLoginTime(long lastLoginTime)
{
losePowerFromBeingOffline();
2011-03-22 20:36:33 +01:00
this.lastLoginTime = lastLoginTime;
this.lastPowerUpdateTime = lastLoginTime;
if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0)
{
this.loginPvpDisabled = true;
}
2011-03-22 20:36:33 +01:00
}
public boolean hasLoginPvpDisabled()
{
if (!loginPvpDisabled)
{
return false;
}
if (this.lastLoginTime + (Conf.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis())
{
this.loginPvpDisabled = false;
return false;
}
return true;
}
//----------------------------------------------//
// Title, Name, Faction Tag and Chat
//----------------------------------------------//
public String getName()
{
return getId();
}
public String getTag()
{
if ( ! this.hasFaction())
{
return "";
}
return this.getFaction().getTag();
}
// Base concatenations:
public String getNameAndSomething(String something)
{
String ret = this.role.getPrefix();
if (something.length() > 0) {
ret += something+" ";
}
ret += this.getName();
return ret;
}
public String getNameAndTitle()
{
return this.getNameAndSomething(this.getTitle());
}
public String getNameAndTag()
{
return this.getNameAndSomething(this.getTag());
}
// Colored concatenations:
// These are used in information messages
public String getNameAndTitle(Faction faction)
{
return this.getColorTo(faction)+this.getNameAndTitle();
}
public String getNameAndTitle(FPlayer fplayer)
{
return this.getColorTo(fplayer)+this.getNameAndTitle();
}
// Chat Tag:
// These are injected into the format of global chat messages.
public String getChatTag()
{
2011-03-19 13:00:03 +01:00
if ( ! this.hasFaction()) {
return "";
}
return String.format(Conf.chatTagFormat, this.role.getPrefix()+this.getTag());
}
// Colored Chat Tag
public String getChatTag(Faction faction)
{
2011-03-19 13:00:03 +01:00
if ( ! this.hasFaction()) {
return "";
}
2011-10-12 17:25:01 +02:00
return this.getRelationTo(faction).getColor()+getChatTag();
}
public String getChatTag(FPlayer fplayer)
{
if ( ! this.hasFaction())
{
return "";
}
return this.getColorTo(fplayer)+getChatTag();
}
// -------------------------------
// Relation and relation colors
// -------------------------------
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public String describeTo(RelationParticipator observer, boolean ucfirst)
{
2011-10-24 11:07:06 +02:00
return RelationUtil.describeThatToMe(this, observer, ucfirst);
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public String describeTo(RelationParticipator observer)
{
2011-10-24 11:07:06 +02:00
return RelationUtil.describeThatToMe(this, observer);
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public Rel getRelationTo(RelationParticipator observer)
{
2011-10-24 11:07:06 +02:00
return RelationUtil.getRelationOfThatToMe(this, observer);
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful)
{
2011-10-24 11:07:06 +02:00
return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful);
}
public Rel getRelationToLocation()
{
2011-10-12 17:25:01 +02:00
return Board.getFactionAt(new FLocation(this)).getRelationTo(this);
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public ChatColor getColorTo(RelationParticipator observer)
2011-10-12 17:25:01 +02:00
{
2011-10-24 11:07:06 +02:00
return RelationUtil.getColorOfThatToMe(this, observer);
2011-10-12 17:25:01 +02:00
}
2011-02-06 13:36:11 +01:00
//----------------------------------------------//
// Health
//----------------------------------------------//
public void heal(int amnt)
{
2011-02-06 13:36:11 +01:00
Player player = this.getPlayer();
if (player == null)
{
2011-02-06 13:36:11 +01:00
return;
}
player.setHealth(player.getHealth() + amnt);
}
//----------------------------------------------//
// Power
//----------------------------------------------//
public double getPower()
{
2011-02-06 13:36:11 +01:00
this.updatePower();
return this.power;
}
protected void alterPower(double delta)
{
2011-02-06 13:36:11 +01:00
this.power += delta;
if (this.power > this.getPowerMax())
2011-02-06 13:36:11 +01:00
this.power = this.getPowerMax();
else if (this.power < this.getPowerMin())
2011-02-06 13:36:11 +01:00
this.power = this.getPowerMin();
}
public double getPowerMax()
{
return Conf.powerPlayerMax + this.powerBoost;
2011-02-06 13:36:11 +01:00
}
public double getPowerMin()
{
return Conf.powerPlayerMin + this.powerBoost;
2011-02-06 13:36:11 +01:00
}
public int getPowerRounded()
{
2011-02-06 13:36:11 +01:00
return (int) Math.round(this.getPower());
}
public int getPowerMaxRounded()
{
2011-02-06 13:36:11 +01:00
return (int) Math.round(this.getPowerMax());
}
public int getPowerMinRounded()
{
2011-02-06 13:36:11 +01:00
return (int) Math.round(this.getPowerMin());
}
protected void updatePower()
{
if (this.isOffline())
{
losePowerFromBeingOffline();
if (!Conf.powerRegenOffline)
{
return;
}
}
2011-02-06 13:36:11 +01:00
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now;
Player thisPlayer = this.getPlayer();
if (thisPlayer != null && thisPlayer.isDead()) return; // don't let dead players regain power until they respawn
int millisPerMinute = 60*1000;
double powerPerMinute = Conf.powerPerMinute;
if(Conf.scaleNegativePower && this.power < 0)
{
powerPerMinute += (Math.sqrt(Math.abs(this.power)) * Math.abs(this.power)) / Conf.scaleNegativeDivisor;
}
this.alterPower(millisPassed * powerPerMinute / millisPerMinute);
2011-02-06 13:36:11 +01:00
}
protected void losePowerFromBeingOffline()
{
if (Conf.powerOfflineLossPerDay > 0.0 && this.power > Conf.powerOfflineLossLimit)
{
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now;
double loss = millisPassed * Conf.powerOfflineLossPerDay / (24*60*60*1000);
if (this.power - loss < Conf.powerOfflineLossLimit)
{
loss = this.power;
}
this.alterPower(-loss);
}
}
2011-02-06 13:36:11 +01:00
public void onDeath()
{
2011-02-06 13:36:11 +01:00
this.updatePower();
this.alterPower(-Conf.powerPerDeath);
}
//----------------------------------------------//
// Territory
//----------------------------------------------//
public boolean isInOwnTerritory()
{
2011-03-22 17:20:21 +01:00
return Board.getFactionAt(new FLocation(this)) == this.getFaction();
2011-02-06 13:36:11 +01:00
}
/*public boolean isInOthersTerritory()
{
Faction factionHere = Board.getFactionAt(new FLocation(this));
return factionHere != null && factionHere.isNormal() && factionHere != this.getFaction();
}*/
2011-10-24 03:02:25 +02:00
/*public boolean isInAllyTerritory()
{
return Board.getFactionAt(new FLocation(this)).getRelationTo(this) == Rel.ALLY;
2011-10-24 03:02:25 +02:00
}*/
2011-10-24 03:02:25 +02:00
/*public boolean isInNeutralTerritory()
{
return Board.getFactionAt(new FLocation(this)).getRelationTo(this) == Rel.NEUTRAL;
2011-10-24 03:02:25 +02:00
}*/
public boolean isInEnemyTerritory()
{
return Board.getFactionAt(new FLocation(this)).getRelationTo(this) == Rel.ENEMY;
2011-02-06 13:36:11 +01:00
}
public void sendFactionHereMessage()
{
if (SpoutFeatures.updateTerritoryDisplay(this))
{
return;
}
Faction factionHere = Board.getFactionAt(this.getLastStoodAt());
String msg = P.p.txt.parse("<i>")+" ~ "+factionHere.getTag(this);
if (factionHere.getDescription().length() > 0)
{
msg += " - "+factionHere.getDescription();
}
2011-02-06 13:36:11 +01:00
this.sendMessage(msg);
}
2011-03-22 20:36:33 +01:00
// -------------------------------
// Actions
// -------------------------------
public void leave(boolean makePay)
{
2011-03-22 20:36:33 +01:00
Faction myFaction = this.getFaction();
makePay = makePay && Econ.shouldBeUsed() && ! this.hasAdminMode();
if (myFaction == null)
{
resetFactionData();
return;
}
boolean perm = myFaction.getFlag(FFlag.PERMANENT);
2011-03-22 20:36:33 +01:00
if (!perm && this.getRole() == Rel.LEADER && myFaction.getFPlayers().size() > 1)
{
2011-10-10 13:40:24 +02:00
msg("<b>You must give the admin role to someone else first.");
2011-03-22 20:36:33 +01:00
return;
}
if (!Conf.canLeaveWithNegativePower && this.getPower() < 0)
{
2011-10-10 13:40:24 +02:00
msg("<b>You cannot leave until your power is positive.");
return;
}
// if economy is enabled and they're not on the bypass list, make sure they can pay
if (makePay && ! Econ.hasAtLeast(this, Conf.econCostLeave, "to leave your faction.")) return;
2012-03-02 02:16:45 +01:00
FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this,myFaction,FPlayerLeaveEvent.PlayerLeaveReason.LEAVE);
Bukkit.getServer().getPluginManager().callEvent(leaveEvent);
if (leaveEvent.isCancelled()) return;
// then make 'em pay (if applicable)
if (makePay && ! Econ.modifyMoney(this, -Conf.econCostLeave, "to leave your faction.", "for leaving your faction.")) return;
// Am I the last one in the faction?
if (myFaction.getFPlayers().size() == 1)
{
// Transfer all money
if (Econ.shouldBeUsed())
Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId()));
}
if (myFaction.isNormal())
{
for (FPlayer fplayer : myFaction.getFPlayersWhereOnline(true))
{
fplayer.msg("%s<i> left %s<i>.", this.describeTo(fplayer, true), myFaction.describeTo(fplayer));
}
if (Conf.logFactionLeave)
P.p.log(this.getName()+" left the faction: "+myFaction.getTag());
}
this.resetFactionData();
if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty())
{
2011-03-22 20:36:33 +01:00
// Remove this faction
for (FPlayer fplayer : FPlayers.i.getOnline())
{
fplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(fplayer, true));
2011-03-22 20:36:33 +01:00
}
2011-10-10 01:21:05 +02:00
myFaction.detach();
if (Conf.logFactionDisband)
P.p.log("The faction "+myFaction.getTag()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving.");
2011-03-22 20:36:33 +01:00
}
}
2011-10-22 16:00:24 +02:00
public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure)
{
2011-10-22 16:00:24 +02:00
String error = null;
FLocation flocation = new FLocation(location);
Faction myFaction = getFaction();
2011-10-22 16:00:24 +02:00
Faction currentFaction = Board.getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded();
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(location))
{
// Checks for WorldGuard regions in the chunk attempting to be claimed
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("<b>This land is protected");
}
2011-10-22 16:00:24 +02:00
else if (Conf.worldsNoClaiming.contains(flocation.getWorldName()))
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("<b>Sorry, this world has land claiming disabled.");
}
else if (this.hasAdminMode())
{
2011-10-22 16:00:24 +02:00
return true;
}
2011-10-22 16:00:24 +02:00
else if (forFaction == currentFaction)
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("%s<i> already own this land.", forFaction.describeTo(this, true));
}
else if ( ! FPerm.TERRITORY.has(this, forFaction, true))
{
return false;
}
2011-10-22 16:00:24 +02:00
else if (forFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers)
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("Factions must have at least <h>%s<b> members to claim land.", Conf.claimsRequireMinFactionMembers);
}
2011-10-22 16:00:24 +02:00
else if (ownedLand >= forFaction.getPowerRounded())
{
error = P.p.txt.parse("<b>You can't claim more land! You need more power!");
}
else if (Conf.claimedLandsMax != 0 && ownedLand >= Conf.claimedLandsMax && ! forFaction.getFlag(FFlag.INFPOWER))
{
error = P.p.txt.parse("<b>Limit reached. You can't claim more land!");
}
else if ( ! Conf.claimingFromOthersAllowed && currentFaction.isNormal())
{
error = P.p.txt.parse("<b>You may not claim land from others.");
}
2011-10-25 22:18:54 +02:00
else if (currentFaction.getRelationTo(forFaction).isAtLeast(Rel.TRUCE) && ! currentFaction.isNone())
2011-10-22 16:00:24 +02:00
{
2011-10-23 22:08:57 +02:00
error = P.p.txt.parse("<b>You can't claim this land due to your relation with the current owner.");
2011-10-22 16:00:24 +02:00
}
else if
(
Conf.claimsMustBeConnected
&& ! this.hasAdminMode()
&& myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0
&& !Board.isConnectedLocation(flocation, myFaction)
2011-10-22 16:00:24 +02:00
&& (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
)
{
if (Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
2011-10-22 16:00:24 +02:00
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
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("<b>You can only claim additional land which is connected to your first claim!");
}
2011-10-22 16:00:24 +02:00
else if (currentFaction.isNormal())
{
2011-10-23 22:08:57 +02:00
if ( ! currentFaction.hasLandInflation())
{
// TODO more messages WARN current faction most importantly
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("%s<i> owns this land and is strong enough to keep it.", currentFaction.getTag(this));
}
2011-10-22 16:00:24 +02:00
else if ( ! Board.isBorderLocation(flocation))
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("<b>You must start claiming land at the border of the territory.");
}
}
2011-10-22 16:00:24 +02:00
if (notifyFailure && error != null)
{
msg(error);
}
return error == null;
}
public boolean attemptClaim(Faction forFaction, Location location, boolean notifyFailure)
{
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
// return value is false on failure, true on success
FLocation flocation = new FLocation(location);
Faction currentFaction = Board.getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded();
if ( ! this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) return false;
2011-10-23 22:08:57 +02:00
// TODO: Add flag no costs??
// if economy is enabled and they're not on the bypass list, make sure they can pay
boolean mustPay = Econ.shouldBeUsed() && ! this.hasAdminMode();
double cost = 0.0;
EconomyParticipator payee = null;
if (mustPay)
{
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (Conf.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, forFaction))
cost += Conf.econClaimUnconnectedFee;
if(Conf.bankEnabled && Conf.bankFactionPaysLandCosts && this.hasFaction())
payee = this.getFaction();
else
payee = this;
if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false;
}
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this);
2012-03-02 02:16:45 +01:00
Bukkit.getServer().getPluginManager().callEvent(claimEvent);
if(claimEvent.isCancelled()) return false;
// then make 'em pay (if applicable)
if (mustPay && ! Econ.modifyMoney(payee, -cost, "to claim this land", "for claiming this land")) return false;
if (LWCFeatures.getEnabled() && forFaction.isNormal() && Conf.onCaptureResetLwcLocks)
LWCFeatures.clearOtherChests(flocation, this.getFaction());
// announce success
2011-10-22 16:00:24 +02:00
Set<FPlayer> informTheseFPlayers = new HashSet<FPlayer>();
informTheseFPlayers.add(this);
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true));
for (FPlayer fp : informTheseFPlayers)
{
2011-10-22 16:00:24 +02:00
fp.msg("<h>%s<i> claimed land for <h>%s<i> from <h>%s<i>.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
}
2011-10-22 16:00:24 +02:00
Board.setFactionAt(forFaction, flocation);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
if (Conf.logLandClaims)
P.p.log(this.getName()+" claimed land at ("+flocation.getCoordString()+") for the faction: "+forFaction.getTag());
return true;
}
2011-03-19 13:00:03 +01:00
2011-03-18 17:33:23 +01:00
// -------------------------------------------- //
// Persistance
// -------------------------------------------- //
@Override
public boolean shouldBeSaved()
{
if (this.hasFaction()) return true;
if (this.getPowerRounded() != this.getPowerMaxRounded() && this.getPowerRounded() != (int) Math.round(Conf.powerPlayerStarting)) return true;
return false;
2011-03-18 17:33:23 +01:00
}
2011-10-10 13:40:24 +02:00
public void msg(String str, Object... args)
{
this.sendMessage(P.p.txt.parse(str, args));
}
2011-02-06 13:36:11 +01:00
}