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

901 lines
22 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 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
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-07-18 22:06:02 +02:00
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
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.
*/
public class FPlayer extends PlayerEntity
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
2011-03-22 17:20:21 +01:00
private Role role;
2011-10-08 23:22:02 +02:00
public Role getRole() { return this.role; }
public void setRole(Role role) { this.role = role; SpoutFeatures.updateAppearances(this.getPlayer()); }
// 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 boolean autoClaimEnabled;
public boolean isAutoClaimEnabled()
{
if (this.factionId.equals("0")) return false;
return autoClaimEnabled;
}
public void setIsAutoClaimEnabled(boolean enabled)
{
this.autoClaimEnabled = enabled;
if (enabled)
{
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.autoClaimEnabled = false;
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.autoClaimEnabled = false;
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-02-06 13:36:11 +01: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);
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.autoClaimEnabled = false;
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
}
2011-10-10 01:21:05 +02:00
public 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;
2011-03-19 13:00:03 +01:00
this.role = Role.NORMAL;
this.title = "";
this.autoClaimEnabled = false;
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 ChatMode getChatMode()
{
if(this.factionId.equals("0"))
{
2011-09-24 12:04:49 +02:00
return ChatMode.PUBLIC;
}
2011-09-24 12:04:49 +02:00
return chatMode;
}
public void setChatMode(ChatMode chatMode)
{
2011-09-24 12:04:49 +02:00
this.chatMode = chatMode;
}
2011-02-06 13:36:11 +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.getRelationColor(faction)+this.getNameAndTitle();
}
public String getNameAndTitle(FPlayer fplayer)
{
2011-03-23 12:00:38 +01:00
return this.getRelationColor(fplayer)+this.getNameAndTitle();
}
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();
}
public String getNameAndRelevant(Faction faction)
{
// Which relation?
Relation rel = this.getRelation(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());
}
// 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 "";
}
return this.getRelation(faction).getColor()+getChatTag();
}
public String getChatTag(FPlayer fplayer)
{
2011-03-19 13:00:03 +01:00
if ( ! this.hasFaction()) {
return "";
}
2011-03-23 12:00:38 +01:00
return this.getRelation(fplayer).getColor()+getChatTag();
}
// -------------------------------
// Relation and relation colors
// -------------------------------
public Relation getRelation(Faction faction)
{
return faction.getRelation(this);
}
public Relation getRelation(FPlayer fplayer)
{
2011-03-23 12:00:38 +01:00
return this.getFaction().getRelation(fplayer);
}
public Relation getRelationToLocation()
{
return Board.getFactionAt(new FLocation(this)).getRelation(this);
}
public ChatColor getRelationColor(Faction faction)
{
return faction.getRelationColor(this);
}
public ChatColor getRelationColor(FPlayer fplayer)
{
2011-03-23 12:00:38 +01:00
return this.getRelation(fplayer).getColor();
}
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)).getRelation(this).isAlly();
}
public boolean isInNeutralTerritory()
{
return Board.getFactionAt(new FLocation(this)).getRelation(this).isNeutral();
}
public boolean isInEnemyTerritory()
{
return Board.getFactionAt(new FLocation(this)).getRelation(this).isEnemy();
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();
boolean perm = myFaction.isPermanent();
2011-03-22 20:36:33 +01:00
if (!perm && this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1)
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<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 01:21:05 +02:00
sendMessageParsed("<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-09 18:35:39 +02:00
if (makePay && Econ.enabled() && ! this.isAdminBypassing())
{
double cost = Conf.econCostLeave;
// pay up
if (cost > 0.0) {
String costString = Econ.moneyString(cost);
if (!Econ.deductMoney(this.getName(), cost)) {
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>It costs <h>%s<b> to leave your faction, which you can't currently afford.", costString);
return;
}
2011-10-10 01:21:05 +02:00
sendMessageParsed("<i>You have paid <h>%s<i> to leave your faction.", costString);
}
// wait... we pay you to leave?
else if (cost < 0.0)
{
String costString = Econ.moneyString(-cost);
Econ.addMoney(this.getName(), -cost);
2011-10-10 01:21:05 +02:00
sendMessageParsed("<i>You have been paid <h>%s<i> for leaving your faction.", costString);
}
}
if (myFaction.isNormal())
{
2011-10-10 01:21:05 +02:00
myFaction.sendMessageParsed("%s<i> left your faction.", this.getNameAndRelevant(myFaction));
}
2011-03-22 20:36:33 +01:00
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())
{
2011-10-10 01:21:05 +02:00
fplayer.sendMessageParsed("<i>The faction %s<i> was disbanded.", myFaction.getTag(fplayer));
2011-03-22 20:36:33 +01:00
}
//Faction.delete(myFaction.getId());
2011-10-10 01:21:05 +02:00
myFaction.detach();
2011-03-22 20:36:33 +01:00
}
}
public boolean attemptClaim(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
Faction myFaction = getFaction();
Location loc = this.getPlayer().getLocation();
FLocation flocation = new FLocation(loc);
Faction otherFaction = Board.getFactionAt(flocation);
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(loc))
{
// Checks for WorldGuard regions in the chunk attempting to be claimed
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>This land is protected");
return false;
}
if (myFaction == otherFaction)
{
if (notifyFailure)
2011-10-10 01:21:05 +02:00
sendMessageParsed("<i>You already own this land.");
return false;
}
if (this.getRole().value < Role.MODERATOR.value)
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<i>You must be "+Role.MODERATOR+" to claim land.");
return false;
}
2011-10-09 18:35:39 +02:00
if (myFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers && ! this.isAdminBypassing())
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>Your faction must have at least <h>%s<b> members to claim land.", Conf.claimsRequireMinFactionMembers);
return false;
}
if (Conf.worldsNoClaiming.contains(flocation.getWorldName()))
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>Sorry, this world has land claiming disabled.");
return false;
}
if (otherFaction.isSafeZone())
{
if (notifyFailure)
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>You can not claim a Safe Zone.");
return false;
}
else if (otherFaction.isWarZone())
{
if (notifyFailure)
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>You can not claim a War Zone.");
return false;
}
int ownedLand = myFaction.getLandRounded();
if (ownedLand >= myFaction.getPowerRounded())
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>You can't claim more land! You need more power!");
return false;
}
if (otherFaction.getRelation(this) == Relation.ALLY)
{
if (notifyFailure)
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>You can't claim the land of your allies.");
return false;
}
if
(
Conf.claimsMustBeConnected
2011-10-09 18:35:39 +02:00
&& ! this.isAdminBypassing()
&& myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0
&& !Board.isConnectedLocation(flocation, myFaction)
&& (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !otherFaction.isNormal())
)
{
if (Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
else
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>You can only claim additional land which is connected to your first claim!");
return false;
}
if (otherFaction.isNormal())
{
if (myFaction.isPeaceful())
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("%s<i> owns this land. Your faction is peaceful, so you cannot claim land from other factions.", otherFaction.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
return false;
}
if (otherFaction.isPeaceful())
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("%s<i> owns this land, and is a peaceful faction. You cannot claim land from them.", otherFaction.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
return false;
}
if ( ! otherFaction.hasLandInflation())
{
// TODO more messages WARN current faction most importantly
2011-10-10 01:21:05 +02:00
sendMessageParsed("%s<i> owns this land and is strong enough to keep it.", otherFaction.getTag(this));
return false;
}
if ( ! Board.isBorderLocation(flocation))
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>You must start claiming land at the border of the territory.");
return false;
}
}
// if economy is enabled and they're not on the bypass list, make 'em pay
2011-10-09 18:35:39 +02:00
if (Econ.enabled() && ! this.isAdminBypassing())
{
double cost = Econ.calculateClaimCost(ownedLand, otherFaction.isNormal());
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-10 01:21:05 +02:00
if( ! faction.removeMoney(cost))
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>It costs <h>%s<b> to claim this land, which your faction can't currently afford.", costString);
2011-09-24 03:22:53 +02:00
return false;
}
else
{
2011-10-10 01:21:05 +02:00
// TODO: Only I can see this right?
sendMessageParsed("%s<i> has paid <h>%s<i> to claim some land.", faction.getTag(this), costString);
2011-09-24 03:22:53 +02:00
}
}
else
{
2011-10-10 01:21:05 +02:00
if ( ! Econ.deductMoney(this.getId(), cost))
{
2011-10-10 01:21:05 +02:00
sendMessageParsed("<b>Claiming this land will cost <h>%s<b>, which you can't currently afford.", costString);
2011-09-24 03:22:53 +02:00
return false;
}
sendMessage("You have paid "+costString+" to claim this land.");
}
}
// announce success
if (otherFaction.isNormal())
{
// ASDF claimed some of your land 450 blocks NNW of you.
// ASDf claimed some land from FACTION NAME
otherFaction.sendMessage(P.p.txt.parse(this.getNameAndRelevant(otherFaction)+"<i> stole some of your land :O"));
myFaction.sendMessage(P.p.txt.parse(this.getNameAndRelevant(myFaction)+"<i> claimed some land from "+otherFaction.getTag(myFaction)));
}
else
{
myFaction.sendMessage(P.p.txt.parse(this.getNameAndRelevant(myFaction)+"<i> claimed some new land :D"));
}
Board.setFactionAt(myFaction, flocation);
return true;
}
2011-03-22 17:20:21 +01:00
2011-03-18 17:33:23 +01:00
// -------------------------------------------- //
2011-03-19 13:00:03 +01:00
// Get and search
2011-03-18 17:33:23 +01:00
// -------------------------------------------- //
2011-03-23 12:00:38 +01:00
/*private static FPlayer get(String playerName)
{
if (instances.containsKey(playerName))
{
return instances.get(playerName);
2011-03-18 17:33:23 +01:00
}
2011-03-22 19:25:11 +01:00
FPlayer vplayer = new FPlayer();
vplayer.playerName = playerName;
instances.put(playerName, vplayer);
2011-03-18 17:33:23 +01:00
return vplayer;
}*/
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
}
/*
public static boolean save()
{
2011-03-22 22:31:04 +01:00
//Factions.log("Saving players to disk");
2011-03-18 17:33:23 +01:00
2011-03-23 12:00:38 +01:00
// We only wan't to save the players with non default values
Map<String, FPlayer> playersToSave = new HashMap<String, FPlayer>();
2011-03-18 17:33:23 +01:00
for (Entry<String, FPlayer> entry : instances.entrySet()) {
if (entry.getValue().shouldBeSaved()) {
2011-03-23 12:00:38 +01:00
playersToSave.put(entry.getKey(), entry.getValue());
2011-03-18 17:33:23 +01:00
}
}
try {
DiscUtil.write(file, P.p.gson.toJson(playersToSave));
} catch (Exception e) {
2011-03-18 17:33:23 +01:00
e.printStackTrace();
P.log("Failed to save the players to disk.");
2011-03-18 17:33:23 +01:00
return false;
}
return true;
}
public static boolean load() {
P.log("Loading players from disk");
2011-03-18 17:33:23 +01:00
if ( ! file.exists()) {
if ( ! loadOld())
P.log("No players to load from disk. Creating new file.");
2011-03-18 17:33:23 +01:00
save();
return true;
}
try {
Type type = new TypeToken<Map<String, FPlayer>>(){}.getType();
Map<String, FPlayer> instancesFromFile = P.p.gson.fromJson(DiscUtil.read(file), type);
2011-03-23 12:00:38 +01:00
instances.clear();
instances.putAll(instancesFromFile);
} catch (Exception e) {
2011-03-18 17:33:23 +01:00
e.printStackTrace();
P.log("Failed to load the players from disk.");
2011-03-18 17:33:23 +01:00
return false;
}
fillPlayernames();
return true;
}
public static void fillPlayernames() {
for(Entry<String, FPlayer> entry : instances.entrySet()) {
entry.getValue().playerName = entry.getKey();
2011-03-18 17:33:23 +01:00
}
}
*/
2011-03-18 17:33:23 +01:00
/*private static boolean loadOld()
{
File folderFollower = new File(P.p.getDataFolder(), "follower");
if ( ! folderFollower.isDirectory()) return false;
p.log("Players file doesn't exist, attempting to load old pre-1.1 data.");
String ext = ".json";
class jsonFileFilter implements FileFilter
{
@Override
public boolean accept(File file)
{
return (file.getName().toLowerCase().endsWith(".json") && file.isFile());
}
}
File[] jsonFiles = folderFollower.listFiles(new jsonFileFilter());
for (File jsonFile : jsonFiles) {
// Extract the name from the filename. The name is filename minus ".json"
String name = jsonFile.getName();
name = name.substring(0, name.length() - ext.length());
try {
FPlayer follower = P.p.gson.fromJson(DiscUtil.read(jsonFile), FPlayer.class);
follower.playerName = name;
follower.lastLoginTime = System.currentTimeMillis();
instances.put(follower.playerName, follower);
P.log("loaded pre-1.1 follower "+name);
} catch (Exception e) {
e.printStackTrace();
P.log(Level.WARNING, "failed to load follower "+name);
}
}
return true;
}*/
public void sendMessageParsed(String str, Object... args)
{
this.sendMessage(P.p.txt.parse(str, args));
}
2011-02-06 13:36:11 +01:00
}