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;
|
2011-10-13 19:47:37 +02:00
|
|
|
|
2012-03-02 02:16:45 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2011-09-08 13:24:55 +02:00
|
|
|
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;
|
2011-10-05 12:13:54 +02:00
|
|
|
import com.massivecraft.factions.integration.Econ;
|
2012-01-15 19:41:33 +01:00
|
|
|
import com.massivecraft.factions.integration.LWCFeatures;
|
2011-10-05 12:13:54 +02:00
|
|
|
import com.massivecraft.factions.integration.SpoutFeatures;
|
|
|
|
import com.massivecraft.factions.integration.Worldguard;
|
2011-10-12 17:25:01 +02:00
|
|
|
import com.massivecraft.factions.util.RelationUtil;
|
2013-04-18 10:35:40 +02:00
|
|
|
import com.massivecraft.mcore.mixin.Mixin;
|
2013-04-11 11:11:31 +02:00
|
|
|
import com.massivecraft.mcore.ps.PS;
|
2013-04-12 08:56:26 +02:00
|
|
|
import com.massivecraft.mcore.store.SenderEntity;
|
2013-04-18 10:35:40 +02:00
|
|
|
import com.massivecraft.mcore.util.TimeDiffUtil;
|
|
|
|
import com.massivecraft.mcore.util.TimeUnit;
|
2013-04-10 10:32:04 +02:00
|
|
|
import com.massivecraft.mcore.util.Txt;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
|
2013-04-12 08:56:26 +02:00
|
|
|
public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipator
|
2013-04-12 07:21:38 +02:00
|
|
|
{
|
|
|
|
// -------------------------------------------- //
|
2013-04-12 08:56:26 +02:00
|
|
|
// META
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-12 08:56:26 +02:00
|
|
|
public static FPlayer get(Object oid)
|
2013-04-12 07:21:38 +02:00
|
|
|
{
|
2013-04-12 08:56:26 +02:00
|
|
|
return FPlayerColl.get().get(oid);
|
2013-04-12 07:21:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE: ENTITY
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-12 08:56:26 +02:00
|
|
|
@Override
|
2013-04-12 07:21:38 +02:00
|
|
|
public FPlayer load(FPlayer that)
|
|
|
|
{
|
2013-04-17 14:44:08 +02:00
|
|
|
this.setFactionId(that.factionId);
|
2013-04-17 15:30:21 +02:00
|
|
|
this.setRole(that.role);
|
|
|
|
this.setTitle(that.title);
|
|
|
|
this.setPowerBoost(that.powerBoost);
|
|
|
|
|
2013-04-12 07:21:38 +02:00
|
|
|
this.power = that.power;
|
|
|
|
this.lastPowerUpdateTime = that.lastPowerUpdateTime;
|
|
|
|
|
|
|
|
return this;
|
2013-04-12 08:56:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDefault()
|
|
|
|
{
|
|
|
|
if (this.hasFaction()) return false;
|
2013-04-17 15:30:21 +02:00
|
|
|
|
|
|
|
// Note: we do not check role or title here since they mean nothing without a faction.
|
|
|
|
|
|
|
|
// TODO: This line looks obnoxious, investigate it.
|
2013-04-18 10:35:40 +02:00
|
|
|
if (this.getPowerRounded() != this.getPowerMaxRounded() && this.getPowerRounded() != (int) Math.round(ConfServer.powerStarting)) return false;
|
2013-04-12 08:56:26 +02:00
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
if (this.hasPowerBoost()) return false;
|
|
|
|
|
2013-04-12 08:56:26 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-04-12 07:21:38 +02:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
2013-04-17 15:30:21 +02:00
|
|
|
// FIELDS: RAW
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2013-04-17 15:30:21 +02:00
|
|
|
// In this section of the source code we place the field declarations only.
|
|
|
|
// Each field has it's own section further down since just the getter and setter logic takes up quite some place.
|
2013-04-12 07:21:38 +02:00
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
// This is a foreign key.
|
|
|
|
// A players always belongs to a faction.
|
|
|
|
// If null the player belongs to the no-faction faction called Wilderness.
|
2013-04-17 14:44:08 +02:00
|
|
|
private String factionId = null;
|
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
// What role does the player have in the faction?
|
|
|
|
// The default value here is MEMBER since that one would be one of the most common ones and our goal is to save database space.
|
|
|
|
// A note to self is that we can not change it from member to anything else just because we feel like it, that would corrupt database content.
|
|
|
|
private Rel role = null;
|
|
|
|
|
|
|
|
// What title does the player have in the faction?
|
|
|
|
// The title is just for fun. It's completely meaningless.
|
|
|
|
// The default case is no title since it's what you start with and also the most common case.
|
|
|
|
// The player title is similar to the faction description.
|
|
|
|
//
|
|
|
|
// Question: Can the title contain chat colors?
|
|
|
|
// Answer: Yes but in such case the policy is that they already must be parsed using Txt.parse.
|
|
|
|
// If they contain markup it should not be parsed in case we coded the system correctly.
|
|
|
|
private String title = null;
|
|
|
|
|
|
|
|
// Player usually do not have a powerboost. It defaults to 0.
|
|
|
|
// The powerBoost is a custom increase/decrease to default and maximum power.
|
|
|
|
// Note that player powerBoost and faction powerBoost are very similar.
|
|
|
|
private Double powerBoost = null;
|
|
|
|
|
2013-04-18 10:35:40 +02:00
|
|
|
// This field contains the last calculated value of the players power.
|
|
|
|
// The power calculation is lazy which means that the power is calculated first when you try to view the value.
|
2013-04-17 15:30:21 +02:00
|
|
|
private double power;
|
|
|
|
|
2013-04-18 10:35:40 +02:00
|
|
|
// This is the timestamp for the last calculation of the power.
|
|
|
|
// The value is used for the lazy calculation described above.
|
2013-04-17 15:30:21 +02:00
|
|
|
private long lastPowerUpdateTime;
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELDS: RAW TRANSIENT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
// Where did this player stand the last time we checked?
|
|
|
|
private transient PS currentChunk = null;
|
|
|
|
public PS getCurrentChunk() { return this.currentChunk; }
|
|
|
|
public void setCurrentChunk(PS currentChunk) { this.currentChunk = currentChunk.getChunk(true); }
|
|
|
|
|
|
|
|
// FIELD: mapAutoUpdating
|
|
|
|
private transient boolean mapAutoUpdating = false;
|
|
|
|
public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; }
|
|
|
|
public boolean isMapAutoUpdating() { return mapAutoUpdating; }
|
|
|
|
|
|
|
|
// FIELD: autoClaimEnabled
|
|
|
|
private transient Faction autoClaimFor = null;
|
|
|
|
public Faction getAutoClaimFor() { return autoClaimFor; }
|
|
|
|
public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; }
|
|
|
|
|
|
|
|
private transient boolean usingAdminMode = false;
|
|
|
|
public boolean isUsingAdminMode() { return this.usingAdminMode; }
|
|
|
|
public void setUsingAdminMode(boolean val) { this.usingAdminMode = val; }
|
|
|
|
|
|
|
|
// FIELD: loginPvpDisabled
|
|
|
|
private transient boolean loginPvpDisabled;
|
|
|
|
|
|
|
|
// FIELD: account
|
|
|
|
public String getAccountId() { return this.getId(); }
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
// GSON need this noarg constructor.
|
|
|
|
public FPlayer()
|
|
|
|
{
|
|
|
|
this.resetFactionData(false);
|
2013-04-18 10:35:40 +02:00
|
|
|
this.power = ConfServer.powerStarting;
|
2013-04-17 15:30:21 +02:00
|
|
|
this.lastPowerUpdateTime = System.currentTimeMillis();
|
|
|
|
this.loginPvpDisabled = (ConfServer.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false;
|
|
|
|
|
|
|
|
if ( ! ConfServer.newPlayerStartingFactionID.equals(Const.FACTIONID_NONE) && FactionColl.get().containsId(ConfServer.newPlayerStartingFactionID))
|
|
|
|
{
|
|
|
|
this.factionId = ConfServer.newPlayerStartingFactionID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void resetFactionData(boolean doSpoutUpdate)
|
|
|
|
{
|
|
|
|
// TODO: Should we not rather use ConfServer.newPlayerStartingFactionID here?
|
|
|
|
|
|
|
|
// The default neutral faction
|
|
|
|
this.setFactionId(null);
|
|
|
|
this.setRole(null);
|
|
|
|
this.setTitle(null);
|
|
|
|
|
|
|
|
this.autoClaimFor = null;
|
|
|
|
|
|
|
|
if (doSpoutUpdate)
|
|
|
|
{
|
|
|
|
SpoutFeatures.updateTitle(this, null);
|
|
|
|
SpoutFeatures.updateTitle(null, this);
|
|
|
|
SpoutFeatures.updateCape(this.getPlayer(), null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetFactionData()
|
|
|
|
{
|
|
|
|
this.resetFactionData(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: factionId
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
// This method never returns null
|
2013-04-17 14:44:08 +02:00
|
|
|
public String getFactionId()
|
2011-10-08 23:22:02 +02:00
|
|
|
{
|
2013-04-17 14:44:08 +02:00
|
|
|
if (this.factionId == null) return Const.FACTIONID_NONE;
|
|
|
|
return this.factionId;
|
|
|
|
}
|
2013-04-17 15:30:21 +02:00
|
|
|
|
|
|
|
// This method never returns null
|
2013-04-17 14:44:08 +02:00
|
|
|
public Faction getFaction()
|
|
|
|
{
|
|
|
|
Faction ret = FactionColl.get().get(this.getFactionId());
|
|
|
|
if (ret == null) ret = FactionColl.get().get(Const.FACTIONID_NONE);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasFaction()
|
|
|
|
{
|
|
|
|
return !this.getFactionId().equals(Const.FACTIONID_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This setter is so long because it search for default/null case and takes care of updating the faction member index
|
|
|
|
public void setFactionId(String factionId)
|
|
|
|
{
|
|
|
|
// Avoid null input
|
|
|
|
if (factionId == null) factionId = Const.FACTIONID_NONE;
|
|
|
|
|
|
|
|
// Get the old value
|
|
|
|
String oldFactionId = this.getFactionId();
|
|
|
|
|
|
|
|
// Ignore nochange
|
|
|
|
if (factionId.equals(oldFactionId)) return;
|
|
|
|
|
|
|
|
// Apply change
|
|
|
|
if (factionId.equals(Const.FACTIONID_NONE))
|
|
|
|
{
|
|
|
|
this.factionId = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.factionId = factionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next we must be attached and inited
|
|
|
|
if (!this.attached()) return;
|
|
|
|
if (!this.getColl().inited()) return;
|
|
|
|
|
|
|
|
// Spout Derp
|
2012-05-09 03:24:07 +02:00
|
|
|
SpoutFeatures.updateTitle(this, null);
|
|
|
|
SpoutFeatures.updateTitle(null, this);
|
2013-04-17 14:44:08 +02:00
|
|
|
|
|
|
|
// Update index
|
|
|
|
Faction oldFaction = FactionColl.get().get(oldFactionId);
|
|
|
|
Faction faction = FactionColl.get().get(factionId);
|
|
|
|
|
|
|
|
oldFaction.fplayers.remove(this);
|
|
|
|
faction.fplayers.add(this);
|
|
|
|
|
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFaction(Faction faction)
|
|
|
|
{
|
|
|
|
this.setFactionId(faction.getId());
|
2011-10-08 23:22:02 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
// -------------------------------------------- //
|
2011-10-08 23:22:02 +02:00
|
|
|
// FIELD: role
|
2013-04-17 15:30:21 +02:00
|
|
|
// -------------------------------------------- //
|
2011-10-08 23:22:02 +02:00
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public Rel getRole()
|
|
|
|
{
|
|
|
|
if (this.role == null) return Rel.MEMBER;
|
|
|
|
return this.role;
|
|
|
|
}
|
2011-10-08 23:22:02 +02:00
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public void setRole(Rel role)
|
|
|
|
{
|
|
|
|
if (role == null || role == Rel.MEMBER)
|
|
|
|
{
|
|
|
|
this.role = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.role = role;
|
|
|
|
}
|
|
|
|
SpoutFeatures.updateTitle(this, null);
|
|
|
|
this.changed();
|
|
|
|
}
|
2011-10-08 23:22:02 +02:00
|
|
|
|
2013-04-12 08:11:11 +02:00
|
|
|
// -------------------------------------------- //
|
2013-04-17 15:30:21 +02:00
|
|
|
// FIELD: title
|
2013-04-12 08:11:11 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public boolean hasTitle()
|
|
|
|
{
|
|
|
|
return this.title != null;
|
|
|
|
}
|
2011-10-09 18:35:39 +02:00
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public String getTitle()
|
|
|
|
{
|
|
|
|
if (this.hasTitle()) return this.title;
|
|
|
|
return Lang.PLAYER_NOTITLE;
|
|
|
|
}
|
2011-10-08 23:22:02 +02:00
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public void setTitle(String title)
|
|
|
|
{
|
|
|
|
if (title != null)
|
|
|
|
{
|
|
|
|
title = title.trim();
|
|
|
|
if (title.length() == 0)
|
|
|
|
{
|
|
|
|
title = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.title = title;
|
|
|
|
this.changed();
|
|
|
|
}
|
2011-10-12 17:25:01 +02:00
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
// -------------------------------------------- //
|
2013-04-17 15:30:21 +02:00
|
|
|
// FIELD: powerBoost
|
2011-03-22 17:20:21 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public double getPowerBoost()
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-17 15:30:21 +02:00
|
|
|
Double ret = this.powerBoost;
|
|
|
|
if (ret == null) ret = 0D;
|
|
|
|
return ret;
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public void setPowerBoost(Double powerBoost)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-17 15:30:21 +02:00
|
|
|
if (powerBoost == null || powerBoost == 0)
|
2011-10-10 01:21:05 +02:00
|
|
|
{
|
2013-04-17 15:30:21 +02:00
|
|
|
powerBoost = null;
|
2011-10-10 01:21:05 +02:00
|
|
|
}
|
2013-04-17 15:30:21 +02:00
|
|
|
this.powerBoost = powerBoost;
|
|
|
|
this.changed();
|
2011-10-10 01:21:05 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 15:30:21 +02:00
|
|
|
public boolean hasPowerBoost()
|
2011-10-10 01:21:05 +02:00
|
|
|
{
|
2013-04-17 15:30:21 +02:00
|
|
|
return this.getPowerBoost() != 0D;
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
// -------------------------------------------- //
|
2013-04-18 10:35:40 +02:00
|
|
|
// FIELD: lastPowerUpdateTime
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
// RAW
|
|
|
|
|
|
|
|
public long getLastPowerUpdateTime()
|
|
|
|
{
|
|
|
|
return this.lastPowerUpdateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLastPowerUpdateTime(long lastPowerUpdateTime)
|
|
|
|
{
|
|
|
|
this.lastPowerUpdateTime = lastPowerUpdateTime;
|
|
|
|
this.changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: power
|
2011-03-22 17:20:21 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-18 10:35:40 +02:00
|
|
|
// RAW
|
|
|
|
|
|
|
|
public double getPower()
|
|
|
|
{
|
|
|
|
this.updatePower();
|
|
|
|
return this.power;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPower(double power)
|
|
|
|
{
|
|
|
|
this.setPower(power, System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPower(double power, long now)
|
|
|
|
{
|
|
|
|
power = Math.min(power, this.getPowerMax());
|
|
|
|
power = Math.max(power, this.getPowerMin());
|
|
|
|
|
|
|
|
// Nochange
|
|
|
|
if (this.power == power) return;
|
|
|
|
|
|
|
|
this.power = power;
|
|
|
|
this.setLastPowerUpdateTime(now);
|
|
|
|
this.changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getPowerMax()
|
|
|
|
{
|
|
|
|
return ConfServer.powerMax + this.powerBoost;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getPowerMin()
|
|
|
|
{
|
|
|
|
return ConfServer.powerMin + this.powerBoost;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePower()
|
|
|
|
{
|
|
|
|
this.updatePower(this.isOnline());
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final transient long POWER_RECALCULATION_MINIMUM_WAIT_MILLIS = 10 * TimeUnit.MILLIS_PER_SECOND;
|
|
|
|
|
|
|
|
public void updatePower(boolean online)
|
|
|
|
{
|
|
|
|
// Is the player really on this server?
|
|
|
|
// We use the sender ps mixin to fetch the current player location.
|
|
|
|
// If the PS is null it's OK. We assume the player is here if we do not know.
|
|
|
|
PS ps = Mixin.getSenderPs(this.getId());
|
|
|
|
if (ps != null && !ps.isWorldLoadedOnThisServer()) return;
|
|
|
|
|
|
|
|
// Get the now
|
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
|
|
|
|
// We will only update if a certain amount of time has passed.
|
|
|
|
if (this.getLastPowerUpdateTime() + POWER_RECALCULATION_MINIMUM_WAIT_MILLIS >= now) return;
|
|
|
|
|
|
|
|
// Calculate millis passed
|
|
|
|
long millisPassed = now - this.getLastPowerUpdateTime();
|
|
|
|
|
|
|
|
// Note that we updated
|
|
|
|
this.setLastPowerUpdateTime(now);
|
|
|
|
|
|
|
|
// We consider dead players to be offline.
|
|
|
|
if (online)
|
|
|
|
{
|
|
|
|
Player thisPlayer = this.getPlayer();
|
|
|
|
if (thisPlayer != null && thisPlayer.isDead())
|
|
|
|
{
|
|
|
|
online = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Depending on online state pick the config values
|
|
|
|
double powerPerHour = online ? ConfServer.powerPerHourOnline : ConfServer.powerPerHourOffline;
|
|
|
|
double powerLimitGain = online ? ConfServer.powerLimitGainOnline : ConfServer.powerLimitGainOffline;
|
|
|
|
double powerLimitLoss = online ? ConfServer.powerLimitLossOnline : ConfServer.powerLimitLossOffline;
|
|
|
|
|
|
|
|
// Apply the negative divisor thingy
|
|
|
|
if (ConfServer.scaleNegativePower && this.power < 0)
|
|
|
|
{
|
|
|
|
powerPerHour += (Math.sqrt(Math.abs(this.power)) * Math.abs(this.power)) / ConfServer.scaleNegativeDivisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate delta and target
|
|
|
|
double powerDelta = powerPerHour * millisPassed / TimeUnit.MILLIS_PER_HOUR;
|
|
|
|
double powerTarget = this.power + powerDelta;
|
|
|
|
|
|
|
|
// Check Gain and Loss limits
|
|
|
|
if (powerDelta >= 0)
|
|
|
|
{
|
|
|
|
// Gain
|
|
|
|
if (powerTarget > powerLimitGain)
|
|
|
|
{
|
|
|
|
if (this.power > powerLimitGain)
|
|
|
|
{
|
|
|
|
// Did already cross --> Just freeze
|
|
|
|
powerTarget = this.power;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Crossing right now --> Snap to limit
|
|
|
|
powerTarget = powerLimitGain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Loss
|
|
|
|
if (powerTarget < powerLimitLoss)
|
|
|
|
{
|
|
|
|
if (this.power < powerLimitLoss)
|
|
|
|
{
|
|
|
|
// Did already cross --> Just freeze
|
|
|
|
powerTarget = this.power;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Crossing right now --> Snap to limit
|
|
|
|
powerTarget = powerLimitLoss;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setPower(powerTarget, now);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FINER
|
|
|
|
|
|
|
|
public int getPowerRounded()
|
|
|
|
{
|
|
|
|
return (int) Math.round(this.getPower());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPowerMaxRounded()
|
|
|
|
{
|
|
|
|
return (int) Math.round(this.getPowerMax());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPowerMinRounded()
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-18 10:35:40 +02:00
|
|
|
return (int) Math.round(this.getPowerMin());
|
2011-03-22 20:36:33 +01:00
|
|
|
}
|
2013-04-18 10:35:40 +02:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: loginPvpDisabled
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// TODO
|
2011-03-22 20:36:33 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void setLastLoginTime(long lastLoginTime)
|
|
|
|
{
|
2011-09-22 13:33:34 +02:00
|
|
|
losePowerFromBeingOffline();
|
2013-04-18 10:35:40 +02:00
|
|
|
//this.lastLoginTime = lastLoginTime;
|
2011-05-29 23:28:29 +02:00
|
|
|
this.lastPowerUpdateTime = lastLoginTime;
|
2013-04-09 13:15:25 +02:00
|
|
|
if (ConfServer.noPVPDamageToOthersForXSecondsAfterLogin > 0)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-06-23 03:10:42 +02:00
|
|
|
this.loginPvpDisabled = true;
|
|
|
|
}
|
2011-03-22 20:36:33 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean hasLoginPvpDisabled()
|
|
|
|
{
|
|
|
|
if (!loginPvpDisabled)
|
|
|
|
{
|
2011-06-23 03:10:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-04-09 13:15:25 +02:00
|
|
|
if (this.lastLoginTime + (ConfServer.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis())
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-06-23 03:10:42 +02:00
|
|
|
this.loginPvpDisabled = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-12 18:05:05 +01:00
|
|
|
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2013-04-11 11:11:31 +02:00
|
|
|
// TITLE, NAME, FACTION TAG AND CHAT
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getName()
|
|
|
|
{
|
2013-04-17 15:49:29 +02:00
|
|
|
return this.getFixedId();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getTag()
|
|
|
|
{
|
|
|
|
if ( ! this.hasFaction())
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return this.getFaction().getTag();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Base concatenations:
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndSomething(String something)
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
String ret = this.role.getPrefix();
|
2013-04-17 15:30:21 +02:00
|
|
|
if (something.length() > 0)
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
ret += something+" ";
|
|
|
|
}
|
|
|
|
ret += this.getName();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTitle()
|
|
|
|
{
|
2013-04-17 15:30:21 +02:00
|
|
|
if (this.hasTitle())
|
|
|
|
{
|
|
|
|
return this.getNameAndSomething(this.getTitle());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.getName();
|
|
|
|
}
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTag()
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
return this.getNameAndSomething(this.getTag());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Colored concatenations:
|
|
|
|
// These are used in information messages
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTitle(Faction faction)
|
|
|
|
{
|
2011-10-21 20:08:54 +02:00
|
|
|
return this.getColorTo(faction)+this.getNameAndTitle();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTitle(FPlayer fplayer)
|
|
|
|
{
|
2011-10-21 20:08:54 +02:00
|
|
|
return this.getColorTo(fplayer)+this.getNameAndTitle();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Chat Tag:
|
|
|
|
// These are injected into the format of global chat messages.
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getChatTag()
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
if ( ! this.hasFaction()) {
|
2011-02-12 18:05:05 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
return String.format(ConfServer.chatTagFormat, this.role.getPrefix()+this.getTag());
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Colored Chat Tag
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getChatTag(Faction faction)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
if ( ! this.hasFaction()) {
|
2011-02-12 18:05:05 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
return this.getRelationTo(faction).getColor()+getChatTag();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
|
|
|
|
public String getChatTag(FPlayer fplayer)
|
|
|
|
{
|
2011-10-21 20:08:54 +02:00
|
|
|
if ( ! this.hasFaction())
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-10-21 20:08:54 +02:00
|
|
|
return this.getColorTo(fplayer)+getChatTag();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2013-04-11 11:11:31 +02:00
|
|
|
// RELATION AND RELATION COLORS
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2011-02-12 18:05:05 +01:00
|
|
|
|
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-08 22:03:44 +02:00
|
|
|
{
|
2011-10-24 11:07:06 +02:00
|
|
|
return RelationUtil.describeThatToMe(this, observer, ucfirst);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
@Override
|
2011-10-24 11:07:06 +02:00
|
|
|
public String describeTo(RelationParticipator observer)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-24 11:07:06 +02:00
|
|
|
return RelationUtil.describeThatToMe(this, observer);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
@Override
|
2011-10-24 11:07:06 +02:00
|
|
|
public Rel getRelationTo(RelationParticipator observer)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-24 11:07:06 +02:00
|
|
|
return RelationUtil.getRelationOfThatToMe(this, observer);
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
|
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-08 22:03:44 +02:00
|
|
|
{
|
2011-10-24 11:07:06 +02:00
|
|
|
return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-23 17:30:41 +02:00
|
|
|
public Rel getRelationToLocation()
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-11 11:11:31 +02:00
|
|
|
// TODO: Use some built in system to get sender
|
|
|
|
return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
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-12 18:05:05 +01:00
|
|
|
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2013-04-11 11:11:31 +02:00
|
|
|
// HEALTH
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void heal(int amnt)
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
Player player = this.getPlayer();
|
2011-10-08 22:03:44 +02:00
|
|
|
if (player == null)
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
player.setHealth(player.getHealth() + amnt);
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2013-04-11 11:11:31 +02:00
|
|
|
// TERRITORY
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean isInOwnTerritory()
|
|
|
|
{
|
2013-04-11 11:11:31 +02:00
|
|
|
// TODO: Use Mixin to get this PS instead
|
|
|
|
return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())) == this.getFaction();
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-08-04 07:07:38 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean isInEnemyTerritory()
|
|
|
|
{
|
2013-04-11 11:11:31 +02:00
|
|
|
// TODO: Use Mixin to get this PS instead
|
|
|
|
return BoardColl.get().getFactionAt(PS.valueOf(this.getPlayer())).getRelationTo(this) == Rel.ENEMY;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-08-04 07:07:38 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void sendFactionHereMessage()
|
|
|
|
{
|
|
|
|
if (SpoutFeatures.updateTerritoryDisplay(this))
|
|
|
|
{
|
2011-10-05 12:13:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-04-11 11:27:04 +02:00
|
|
|
Faction factionHere = BoardColl.get().getFactionAt(this.getCurrentChunk());
|
2013-04-10 10:32:04 +02:00
|
|
|
String msg = Txt.parse("<i>")+" ~ "+factionHere.getTag(this);
|
2013-04-17 08:49:43 +02:00
|
|
|
if (factionHere.hasDescription())
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
msg += " - "+factionHere.getDescription();
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
this.sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2013-04-11 11:11:31 +02:00
|
|
|
// ACTIONS
|
2013-04-12 07:21:38 +02:00
|
|
|
// -------------------------------------------- //
|
2011-03-22 20:36:33 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void leave(boolean makePay)
|
|
|
|
{
|
2011-03-22 20:36:33 +01:00
|
|
|
Faction myFaction = this.getFaction();
|
2013-04-16 11:27:03 +02:00
|
|
|
makePay = makePay && Econ.shouldBeUsed() && ! this.isUsingAdminMode();
|
2011-12-18 14:50:41 +01:00
|
|
|
|
|
|
|
if (myFaction == null)
|
|
|
|
{
|
|
|
|
resetFactionData();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-24 02:33:30 +02:00
|
|
|
boolean perm = myFaction.getFlag(FFlag.PERMANENT);
|
2011-03-22 20:36:33 +01:00
|
|
|
|
2011-10-23 17:30:41 +02:00
|
|
|
if (!perm && this.getRole() == Rel.LEADER && myFaction.getFPlayers().size() > 1)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
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;
|
|
|
|
}
|
2011-04-28 22:45:43 +02:00
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
if (!ConfServer.canLeaveWithNegativePower && this.getPower() < 0)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>You cannot leave until your power is positive.");
|
2011-05-29 23:41:50 +02:00
|
|
|
return;
|
|
|
|
}
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
|
2012-03-13 15:48:34 +01:00
|
|
|
// if economy is enabled and they're not on the bypass list, make sure they can pay
|
2013-04-09 13:15:25 +02:00
|
|
|
if (makePay && ! Econ.hasAtLeast(this, ConfServer.econCostLeave, "to leave your faction.")) return;
|
2012-03-13 15:48:34 +01:00
|
|
|
|
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;
|
2012-03-13 15:48:34 +01:00
|
|
|
|
|
|
|
// then make 'em pay (if applicable)
|
2013-04-09 13:15:25 +02:00
|
|
|
if (makePay && ! Econ.modifyMoney(this, -ConfServer.econCostLeave, "to leave your faction.", "for leaving your faction.")) return;
|
2012-03-13 15:48:34 +01:00
|
|
|
|
2011-10-13 19:47:37 +02:00
|
|
|
// Am I the last one in the faction?
|
2012-01-13 10:46:31 +01:00
|
|
|
if (myFaction.getFPlayers().size() == 1)
|
2011-10-13 19:47:37 +02:00
|
|
|
{
|
|
|
|
// Transfer all money
|
|
|
|
if (Econ.shouldBeUsed())
|
2012-01-17 02:38:14 +01:00
|
|
|
Econ.transferMoney(this, myFaction, this, Econ.getBalance(myFaction.getAccountId()));
|
2011-10-13 19:47:37 +02:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (myFaction.isNormal())
|
|
|
|
{
|
2011-10-12 21:54:38 +02:00
|
|
|
for (FPlayer fplayer : myFaction.getFPlayersWhereOnline(true))
|
|
|
|
{
|
2011-10-13 19:47:37 +02:00
|
|
|
fplayer.msg("%s<i> left %s<i>.", this.describeTo(fplayer, true), myFaction.describeTo(fplayer));
|
2011-10-12 21:54:38 +02:00
|
|
|
}
|
Additional logging, with new conf.json settings to enable/disable logging of specific events:
"logFactionCreate": true, - log faction creation
"logFactionDisband": true, - log factions being disbanded, by command or by circumstance
"logFactionJoin": true, - log player joining a faction
"logFactionKick": true, - log player being kicked from a faction
"logFactionLeave": true, - log player leaving a faction
"logLandClaims": true, - log land being claimed (including safe zone and war zone)
"logLandUnclaims": true, - log land being unclaimed (including safe zone and war zone)
"logMoneyTransactions": true, - log money being deposited, withdrawn, and otherwise transferred in relation to faction banks
Also a fix for a potential NPE from players logging out and Spout appearance handler referencing them afterwards
2011-10-23 19:50:02 +02:00
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
if (ConfServer.logFactionLeave)
|
2013-04-09 13:12:13 +02:00
|
|
|
Factions.get().log(this.getName()+" left the faction: "+myFaction.getTag());
|
2011-04-28 22:45:43 +02:00
|
|
|
}
|
2011-10-13 19:47:37 +02:00
|
|
|
|
2011-10-13 06:44:59 +02:00
|
|
|
this.resetFactionData();
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty())
|
|
|
|
{
|
2011-03-22 20:36:33 +01:00
|
|
|
// Remove this faction
|
2013-04-12 08:56:26 +02:00
|
|
|
for (FPlayer fplayer : FPlayerColl.get().getAllOnline())
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-12 21:54:38 +02:00
|
|
|
fplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(fplayer, true));
|
2011-03-22 20:36:33 +01:00
|
|
|
}
|
2011-10-13 06:44:59 +02:00
|
|
|
|
2011-10-10 01:21:05 +02:00
|
|
|
myFaction.detach();
|
2013-04-09 13:15:25 +02:00
|
|
|
if (ConfServer.logFactionDisband)
|
2013-04-09 13:12:13 +02:00
|
|
|
Factions.get().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-25 08:27:58 +02:00
|
|
|
|
2011-10-22 16:00:24 +02:00
|
|
|
public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-22 16:00:24 +02:00
|
|
|
String error = null;
|
2013-04-11 11:11:31 +02:00
|
|
|
|
|
|
|
PS ps = PS.valueOf(location);
|
|
|
|
Faction myFaction = this.getFaction();
|
|
|
|
Faction currentFaction = BoardColl.get().getFactionAt(ps);
|
2013-04-17 08:49:43 +02:00
|
|
|
int ownedLand = forFaction.getLandCount();
|
2011-10-22 16:00:24 +02:00
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(location))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-08-29 14:54:04 +02:00
|
|
|
// Checks for WorldGuard regions in the chunk attempting to be claimed
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>This land is protected");
|
2011-08-29 14:54:04 +02:00
|
|
|
}
|
2013-04-11 11:11:31 +02:00
|
|
|
else if (ConfServer.worldsNoClaiming.contains(ps.getWorld()))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>Sorry, this world has land claiming disabled.");
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
2013-04-16 11:27:03 +02:00
|
|
|
else if (this.isUsingAdminMode())
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-22 16:00:24 +02:00
|
|
|
return true;
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
2011-10-22 16:00:24 +02:00
|
|
|
else if (forFaction == currentFaction)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("%s<i> already own this land.", forFaction.describeTo(this, true));
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
2011-10-25 21:18:08 +02:00
|
|
|
else if ( ! FPerm.TERRITORY.has(this, forFaction, true))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-25 21:18:08 +02:00
|
|
|
return false;
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
2013-04-09 13:15:25 +02:00
|
|
|
else if (forFaction.getFPlayers().size() < ConfServer.claimsRequireMinFactionMembers)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("Factions must have at least <h>%s<b> members to claim land.", ConfServer.claimsRequireMinFactionMembers);
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
2011-10-22 16:00:24 +02:00
|
|
|
else if (ownedLand >= forFaction.getPowerRounded())
|
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>You can't claim more land! You need more power!");
|
2011-10-22 16:00:24 +02:00
|
|
|
}
|
2013-04-09 13:15:25 +02:00
|
|
|
else if (ConfServer.claimedLandsMax != 0 && ownedLand >= ConfServer.claimedLandsMax && ! forFaction.getFlag(FFlag.INFPOWER))
|
2012-02-02 20:09:43 +01:00
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>Limit reached. You can't claim more land!");
|
2012-01-31 23:30:24 +01:00
|
|
|
}
|
2013-04-09 13:15:25 +02:00
|
|
|
else if ( ! ConfServer.claimingFromOthersAllowed && currentFaction.isNormal())
|
2012-07-30 23:28:23 +02:00
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>You may not claim land from others.");
|
2012-07-30 23:28:23 +02:00
|
|
|
}
|
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
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = 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
|
2011-10-08 22:03:44 +02:00
|
|
|
(
|
2013-04-09 13:15:25 +02:00
|
|
|
ConfServer.claimsMustBeConnected
|
2013-04-16 11:27:03 +02:00
|
|
|
&& ! this.isUsingAdminMode()
|
2013-04-17 08:49:43 +02:00
|
|
|
&& myFaction.getLandCountInWorld(ps.getWorld()) > 0
|
2013-04-11 11:11:31 +02:00
|
|
|
&& !BoardColl.get().isConnectedPs(ps, myFaction)
|
2013-04-09 13:15:25 +02:00
|
|
|
&& (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
|
2011-10-08 22:03:44 +02:00
|
|
|
)
|
|
|
|
{
|
2013-04-09 13:15:25 +02:00
|
|
|
if (ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction)
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
|
2011-07-20 21:45:18 +02:00
|
|
|
else
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>You can only claim additional land which is connected to your first claim!");
|
2011-06-21 04:15:41 +02:00
|
|
|
}
|
2011-10-22 16:00:24 +02:00
|
|
|
else if (currentFaction.isNormal())
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-23 22:08:57 +02:00
|
|
|
if ( ! currentFaction.hasLandInflation())
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-06-10 21:26:12 +02:00
|
|
|
// TODO more messages WARN current faction most importantly
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("%s<i> owns this land and is strong enough to keep it.", currentFaction.getTag(this));
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
2013-04-11 11:11:31 +02:00
|
|
|
else if ( ! BoardColl.get().isBorderPs(ps))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
error = Txt.parse("<b>You must start claiming land at the border of the territory.");
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
}
|
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
|
|
|
|
|
2013-04-11 11:11:31 +02:00
|
|
|
PS flocation = PS.valueOf(location).getChunk(true);
|
|
|
|
Faction currentFaction = BoardColl.get().getFactionAt(flocation);
|
2011-10-22 16:00:24 +02:00
|
|
|
|
2013-04-17 08:49:43 +02:00
|
|
|
int ownedLand = forFaction.getLandCount();
|
2011-10-22 16:00:24 +02:00
|
|
|
|
|
|
|
if ( ! this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) return false;
|
|
|
|
|
2011-10-23 22:08:57 +02:00
|
|
|
// TODO: Add flag no costs??
|
2012-03-13 15:48:34 +01:00
|
|
|
// if economy is enabled and they're not on the bypass list, make sure they can pay
|
2013-04-16 11:27:03 +02:00
|
|
|
boolean mustPay = Econ.shouldBeUsed() && ! this.isUsingAdminMode();
|
2012-03-13 15:48:34 +01:00
|
|
|
double cost = 0.0;
|
|
|
|
EconomyParticipator payee = null;
|
|
|
|
if (mustPay)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2012-03-13 15:48:34 +01:00
|
|
|
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
|
2012-01-19 04:10:40 +01:00
|
|
|
|
2013-04-17 08:49:43 +02:00
|
|
|
if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(flocation.getWorld()) > 0 && !BoardColl.get().isConnectedPs(flocation, forFaction))
|
2013-04-09 13:15:25 +02:00
|
|
|
cost += ConfServer.econClaimUnconnectedFee;
|
2012-01-19 04:10:40 +01:00
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts && this.hasFaction())
|
2012-03-13 15:48:34 +01:00
|
|
|
payee = this.getFaction();
|
2011-10-08 22:03:44 +02:00
|
|
|
else
|
2012-03-13 15:48:34 +01:00
|
|
|
payee = this;
|
|
|
|
|
|
|
|
if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false;
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
}
|
2012-03-13 15:48:34 +01:00
|
|
|
|
2012-03-11 18:28:31 +01:00
|
|
|
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;
|
2012-03-13 15:48:34 +01:00
|
|
|
|
|
|
|
// then make 'em pay (if applicable)
|
|
|
|
if (mustPay && ! Econ.modifyMoney(payee, -cost, "to claim this land", "for claiming this land")) return false;
|
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
if (LWCFeatures.getEnabled() && forFaction.isNormal() && ConfServer.onCaptureResetLwcLocks)
|
2012-01-15 19:41:33 +01:00
|
|
|
LWCFeatures.clearOtherChests(flocation, this.getFaction());
|
|
|
|
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +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-08 22:03:44 +02:00
|
|
|
{
|
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));
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
}
|
2011-10-22 16:00:24 +02:00
|
|
|
|
2013-04-11 11:11:31 +02:00
|
|
|
BoardColl.get().setFactionAt(flocation, forFaction);
|
2011-10-23 16:03:28 +02:00
|
|
|
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
|
Additional logging, with new conf.json settings to enable/disable logging of specific events:
"logFactionCreate": true, - log faction creation
"logFactionDisband": true, - log factions being disbanded, by command or by circumstance
"logFactionJoin": true, - log player joining a faction
"logFactionKick": true, - log player being kicked from a faction
"logFactionLeave": true, - log player leaving a faction
"logLandClaims": true, - log land being claimed (including safe zone and war zone)
"logLandUnclaims": true, - log land being unclaimed (including safe zone and war zone)
"logMoneyTransactions": true, - log money being deposited, withdrawn, and otherwise transferred in relation to faction banks
Also a fix for a potential NPE from players logging out and Spout appearance handler referencing them afterwards
2011-10-23 19:50:02 +02:00
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
if (ConfServer.logLandClaims)
|
2013-04-11 11:11:31 +02:00
|
|
|
Factions.get().log(this.getName()+" claimed land at ("+flocation.getChunkX()+","+flocation.getChunkZ()+") for the faction: "+forFaction.getTag());
|
Additional logging, with new conf.json settings to enable/disable logging of specific events:
"logFactionCreate": true, - log faction creation
"logFactionDisband": true, - log factions being disbanded, by command or by circumstance
"logFactionJoin": true, - log player joining a faction
"logFactionKick": true, - log player being kicked from a faction
"logFactionLeave": true, - log player leaving a faction
"logLandClaims": true, - log land being claimed (including safe zone and war zone)
"logLandUnclaims": true, - log land being unclaimed (including safe zone and war zone)
"logMoneyTransactions": true, - log money being deposited, withdrawn, and otherwise transferred in relation to faction banks
Also a fix for a potential NPE from players logging out and Spout appearance handler referencing them afterwards
2011-10-23 19:50:02 +02:00
|
|
|
|
2011-06-10 21:26:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2013-01-06 21:44:29 +01:00
|
|
|
}
|