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

801 lines
21 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
import java.util.ArrayList;
2011-10-22 16:00:24 +02:00
import java.util.HashSet;
import java.util.Set;
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
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.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard;
2011-09-24 12:04:49 +02:00
import com.massivecraft.factions.struct.ChatMode;
2011-10-23 20:50:49 +02:00
import com.massivecraft.factions.struct.FactionFlag;
import com.massivecraft.factions.struct.Permission;
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-10-12 17:25:01 +02:00
import com.nijikokun.register.payment.Method.MethodAccount;
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-12 17:25:01 +02:00
public class FPlayer extends PlayerEntity implements EconomyParticipator
2011-10-08 23:22:02 +02:00
{
//private transient String playerName;
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-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)
{
this.factionId = faction.getId();
SpoutFeatures.updateAppearances(this.getPlayer());
}
// FIELD: role
private Rel role;
public Rel getRole() { return this.role; }
public void setRole(Rel role) { this.role = role; SpoutFeatures.updateAppearances(this.getPlayer()); }
2011-10-08 23:22:02 +02:00
// FIELD: title
2011-02-06 13:36:11 +01:00
private String title;
2011-10-08 23:22:02 +02:00
// FIELD: power
2011-02-06 13:36:11 +01:00
private double power;
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-08 23:22:02 +02:00
// FIELD: autoClaimEnabled
private transient Faction autoClaimFor;
public Faction getAutoClaimFor()
{
return autoClaimFor;
}
public void setAutoClaimFor(Faction faction)
{
this.autoClaimFor = faction;
if (this.autoClaimFor != null)
{
// TODO: merge these into same autoclaim
this.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = false;
}
}
2011-10-08 23:22:02 +02:00
// FIELD: autoSafeZoneEnabled
private transient boolean autoSafeZoneEnabled;
public boolean isAutoSafeClaimEnabled() { return autoSafeZoneEnabled; }
public void setIsAutoSafeClaimEnabled(boolean enabled)
{
this.autoSafeZoneEnabled = enabled;
if (enabled)
{
this.autoClaimFor = null;
this.autoWarZoneEnabled = false;
}
}
2011-10-08 23:22:02 +02:00
// FIELD: autoWarZoneEnabled
private transient boolean autoWarZoneEnabled;
public boolean isAutoWarClaimEnabled() { return autoWarZoneEnabled; }
public void setIsAutoWarClaimEnabled(boolean enabled)
{
this.autoWarZoneEnabled = enabled;
if (enabled)
{
this.autoClaimFor = null;
this.autoSafeZoneEnabled = false;
}
}
2011-10-08 23:22:02 +02:00
2011-10-09 18:35:39 +02:00
private transient boolean isAdminBypassing = false;
public boolean isAdminBypassing() { return this.isAdminBypassing; }
public void setIsAdminBypassing(boolean val) { this.isAdminBypassing = val; }
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
// FIELD: deleteMe
private transient boolean deleteMe;
2011-10-08 23:22:02 +02:00
// FIELD: chatMode
2011-09-24 12:04:49 +02:00
private ChatMode chatMode;
2011-10-14 15:40:03 +02:00
public void setChatMode(ChatMode chatMode) { this.chatMode = chatMode; }
public ChatMode getChatMode()
{
if(this.factionId.equals("0") || ! Conf.factionOnlyChat)
{
this.chatMode = ChatMode.PUBLIC;
}
return chatMode;
}
2011-02-06 13:36:11 +01:00
2011-10-12 17:25:01 +02:00
// FIELD: account
public MethodAccount getAccount()
{
if ( ! Econ.shouldBeUsed()) return null;
return Econ.getMethod().getAccount(this.getId());
}
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);
2011-03-19 13:00:03 +01:00
this.power = this.getPowerMax();
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.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = false;
this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false;
this.deleteMe = false;
if ( ! Conf.newPlayerStartingFactionID.equals("0") && Factions.i.exists(Conf.newPlayerStartingFactionID))
{
this.factionId = Conf.newPlayerStartingFactionID;
}
2011-03-19 13:00:03 +01:00
}
public final void resetFactionData(boolean doSpotUpdate)
{
2011-07-31 03:17:00 +02:00
// clean up any territory ownership in old faction, if there is one
2011-10-10 01:21:05 +02:00
if (Factions.i.exists(this.getFactionId()))
{
2011-10-10 01:21:05 +02:00
Faction currentFaction = this.getFaction();
if (currentFaction.isNormal())
{
currentFaction.clearClaimOwnership(this.getId());
}
2011-07-31 03:17:00 +02:00
}
this.factionId = "0"; // The default neutral faction
2011-09-24 12:04:49 +02:00
this.chatMode = ChatMode.PUBLIC;
this.role = Rel.MEMBER;
2011-03-19 13:00:03 +01:00
this.title = "";
this.autoClaimFor = null;
2011-10-10 01:21:05 +02:00
if (doSpotUpdate)
{
SpoutFeatures.updateAppearances(this.getPlayer());
}
}
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
// -------------------------------------------- //
2011-03-22 19:25:11 +01:00
2011-03-22 17:20:21 +01:00
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 isMapAutoUpdating()
{
2011-02-06 13:36:11 +01:00
return mapAutoUpdating;
}
public void setMapAutoUpdating(boolean mapAutoUpdating)
{
2011-02-06 13:36:11 +01:00
this.mapAutoUpdating = mapAutoUpdating;
}
public boolean hasLoginPvpDisabled()
{
if (!loginPvpDisabled)
{
return false;
}
if (this.lastLoginTime + (Conf.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis())
{
this.loginPvpDisabled = false;
return false;
}
return true;
}
public FLocation getLastStoodAt()
{
2011-03-22 17:20:21 +01:00
return this.lastStoodAt;
}
public void setLastStoodAt(FLocation flocation)
{
2011-03-22 17:20:21 +01:00
this.lastStoodAt = flocation;
}
public void markForDeletion(boolean delete)
{
deleteMe = delete;
}
2011-03-22 17:20:21 +01:00
//----------------------------------------------//
// Title, Name, Faction Tag and Chat
//----------------------------------------------//
// Base:
public String getTitle()
{
2011-03-22 19:25:11 +01:00
return this.title;
2011-02-06 13:36:11 +01:00
}
public void setTitle(String title)
{
2011-02-06 13:36:11 +01:00
this.title = title;
}
public String getName()
{
return this.getId(); // TODO: ... display name or remove completeley
}
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();
}
2011-10-21 19:20:33 +02:00
/*public String getNameAndTag(Faction faction)
{
return this.getRelationColor(faction)+this.getNameAndTag();
}
public String getNameAndTag(FPlayer fplayer)
{
2011-03-23 12:00:38 +01:00
return this.getRelationColor(fplayer)+this.getNameAndTag();
2011-10-21 19:20:33 +02:00
}*/
// TODO: REmovded for refactoring.
2011-10-21 19:20:33 +02:00
/*public String getNameAndRelevant(Faction faction)
{
// Which relation?
2011-10-12 17:25:01 +02:00
Relation rel = this.getRelationTo(faction);
// For member we show title
if (rel == Relation.MEMBER) {
return rel.getColor() + this.getNameAndTitle();
}
// For non members we show tag
return rel.getColor() + this.getNameAndTag();
}
public String getNameAndRelevant(FPlayer fplayer)
{
2011-03-23 12:00:38 +01:00
return getNameAndRelevant(fplayer.getFaction());
2011-10-21 19:20:33 +02:00
}*/
// 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
public String describeTo(RelationParticipator that, boolean ucfirst)
{
return RelationUtil.describeThatToMe(this, that, ucfirst);
}
2011-10-12 17:25:01 +02:00
@Override
public String describeTo(RelationParticipator that)
{
return RelationUtil.describeThatToMe(this, that);
}
2011-10-12 17:25:01 +02:00
@Override
public Rel getRelationTo(RelationParticipator rp)
{
2011-10-12 17:25:01 +02:00
return RelationUtil.getRelationTo(this, rp);
}
2011-10-12 17:25:01 +02:00
@Override
public Rel getRelationTo(RelationParticipator rp, boolean ignorePeaceful)
{
2011-10-12 17:25:01 +02:00
return RelationUtil.getRelationTo(this, rp, 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
public ChatColor getColorTo(RelationParticipator rp)
2011-10-12 17:25:01 +02:00
{
return RelationUtil.getColorOfThatToMe(this, rp);
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();
}
//Log.debug("Power of "+this.getName()+" is now: "+this.power);
2011-02-06 13:36:11 +01:00
}
public double getPowerMax()
{
return Conf.powerPlayerMax;
2011-02-06 13:36:11 +01:00
}
public double getPowerMin()
{
return Conf.powerPlayerMin;
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;
int millisPerMinute = 60*1000;
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
}
protected void losePowerFromBeingOffline()
{
if (Conf.powerOfflineLossPerDay > 0.0 && this.power > Conf.powerOfflineLossLimit)
{
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
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();
}
public boolean isInAllyTerritory()
{
return Board.getFactionAt(new FLocation(this)).getRelationTo(this) == Rel.ALLY;
}
public boolean isInNeutralTerritory()
{
return Board.getFactionAt(new FLocation(this)).getRelationTo(this) == Rel.NEUTRAL;
}
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;
}
2011-03-19 13:00:03 +01:00
Faction factionHere = Board.getFactionAt(new FLocation(this));
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();
2011-10-23 20:50:49 +02:00
boolean perm = myFaction.getFlag(FactionFlag.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 'em pay
2011-10-12 17:25:01 +02:00
if (makePay && Econ.shouldBeUsed() && ! this.isAdminBypassing())
{
double cost = Conf.econCostLeave;
2011-10-12 17:25:01 +02:00
if ( ! Econ.modifyMoney(this, -cost, "to leave your faction.", "for leaving your faction.")) return;
}
// Am I the last one in the faction?
ArrayList<FPlayer> fplayers = myFaction.getFPlayers();
if (fplayers.size() == 1 && fplayers.get(0) == this)
{
// Transfer all money
if (Econ.shouldBeUsed())
Econ.transferMoney(this, myFaction, this, myFaction.getAccount().balance());
}
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.");
}
2011-10-22 16:00:24 +02:00
else if (this.isAdminBypassing())
{
2011-10-22 16:00:24 +02:00
return true;
}
else if (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer()))
{
return true;
}
else if (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))
{
return true;
}
2011-10-22 16:00:24 +02:00
else if (myFaction != forFaction)
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(this));
}
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 ( ! this.getRole().isAtLeast(Rel.OFFICER))
{
error = P.p.txt.parse("<b>You must be <h>%s<b> to claim land.", Rel.OFFICER.toString());
}
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 (currentFaction.isSafeZone())
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("<b>You can not claim a Safe Zone.");
}
2011-10-22 16:00:24 +02:00
else if (currentFaction.isWarZone())
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("<b>You can not claim a War Zone.");
}
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 (currentFaction.getRelationTo(forFaction) == Rel.ALLY)
2011-10-22 16:00:24 +02:00
{
error = P.p.txt.parse("<b>You can't claim the land of your allies.");
}
else if
(
Conf.claimsMustBeConnected
2011-10-09 18:35:39 +02:00
&& ! this.isAdminBypassing()
&& 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())
{
if (myFaction.isPeaceful())
{
2011-10-22 16:00:24 +02:00
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));
New "peaceful" status for factions which can only be set by server admins/moderators. Members of peaceful factions cannot deal or receive PvP damage (unless in a war zone which has friendly fire enabled), cannot claim land from another faction and likewise can't have their land claimed, and cannot be considered as ally or enemy of any other faction. Faction admins and moderators of peaceful factions can enable/disable all explosions inside their faction's territory at will. The main purpose of this is to provide a way for more peaceful players who don't want to take part in faction wars (or just want to take a break from them) to still have fun on the server. It is also meant to allow groups of players to make protected buildings, monuments, grand constructions, and so forth without having to worry about another faction destroying them. New conf.json settings: "peacefulTerritoryDisablePVP" (default true) prevents PvP damage for anyone inside a peaceful faction's territory "peacefulTerritoryDisableMonsters" (default false) provides protection against monsters spawning or attacking inside a peaceful faction's territory "peacefulMembersDisablePowerLoss" (default true) which keeps members of peaceful factions from suffering power loss when they die. New commands: /f peaceful [faction tag] - toggle the indicated faction's "peaceful" status /f noboom - enable/disable explosions inside your faction's territory; only available to faction admin and faction moderators for peaceful factions New permission nodes: factions.setPeaceful - ability to use the /f peaceful command (admins) factions.peacefulExplosionToggle - ability to use /f noboom (everyone)
2011-08-05 10:50:47 +02:00
}
2011-10-22 16:00:24 +02:00
else if (currentFaction.isPeaceful())
{
2011-10-22 16:00:24 +02:00
error = P.p.txt.parse("%s<i> owns this land, and is a peaceful faction. You cannot claim land from them.", currentFaction.getTag(this));
New "peaceful" status for factions which can only be set by server admins/moderators. Members of peaceful factions cannot deal or receive PvP damage (unless in a war zone which has friendly fire enabled), cannot claim land from another faction and likewise can't have their land claimed, and cannot be considered as ally or enemy of any other faction. Faction admins and moderators of peaceful factions can enable/disable all explosions inside their faction's territory at will. The main purpose of this is to provide a way for more peaceful players who don't want to take part in faction wars (or just want to take a break from them) to still have fun on the server. It is also meant to allow groups of players to make protected buildings, monuments, grand constructions, and so forth without having to worry about another faction destroying them. New conf.json settings: "peacefulTerritoryDisablePVP" (default true) prevents PvP damage for anyone inside a peaceful faction's territory "peacefulTerritoryDisableMonsters" (default false) provides protection against monsters spawning or attacking inside a peaceful faction's territory "peacefulMembersDisablePowerLoss" (default true) which keeps members of peaceful factions from suffering power loss when they die. New commands: /f peaceful [faction tag] - toggle the indicated faction's "peaceful" status /f noboom - enable/disable explosions inside your faction's territory; only available to faction admin and faction moderators for peaceful factions New permission nodes: factions.setPeaceful - ability to use the /f peaceful command (admins) factions.peacefulExplosionToggle - ability to use /f noboom (everyone)
2011-08-05 10:50:47 +02:00
}
2011-10-22 16:00:24 +02:00
else 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;
// if economy is enabled and they're not on the bypass list, make 'em pay
if (Econ.shouldBeUsed() && ! this.isAdminBypassing() && ! forFaction.isSafeZone() && ! forFaction.isWarZone())
{
2011-10-22 16:00:24 +02:00
double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
2011-10-12 17:25:01 +02:00
//String costString = Econ.moneyString(cost);
2011-09-24 03:22:53 +02:00
if(Conf.bankFactionPaysLandCosts && this.hasFaction())
{
2011-09-24 03:22:53 +02:00
Faction faction = this.getFaction();
2011-10-12 17:25:01 +02:00
if ( ! Econ.modifyMoney(faction, -cost, "to claim this land", "for claiming this land")) return false;
2011-10-22 16:00:24 +02:00
}
else
{
2011-10-12 17:25:01 +02:00
if ( ! Econ.modifyMoney(this, -cost, "to claim this land", "for claiming this land")) return false;
2011-10-22 16:00:24 +02:00
}
}
2011-10-22 16:00:24 +02:00
// 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()
{
return ! this.deleteMe;
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
}