2011-07-18 22:06:02 +02:00
|
|
|
package com.massivecraft.factions;
|
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
|
|
|
|
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;
|
|
|
|
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;
|
2011-10-12 17:25:01 +02:00
|
|
|
import com.massivecraft.factions.util.RelationUtil;
|
2011-10-08 22:03:44 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
2011-03-22 15:45:41 +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.
|
2011-03-22 15:45:41 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2011-10-08 22:03:44 +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
|
2011-10-08 22:03:44 +02:00
|
|
|
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
|
2011-03-22 15:45:41 +01:00
|
|
|
private transient boolean mapAutoUpdating;
|
2011-10-08 23:22:02 +02:00
|
|
|
|
|
|
|
// FIELD: autoClaimEnabled
|
2011-06-10 21:26:12 +02:00
|
|
|
private transient boolean autoClaimEnabled;
|
2011-10-09 14:53:38 +02:00
|
|
|
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
|
2011-06-10 21:26:12 +02:00
|
|
|
private transient boolean autoSafeZoneEnabled;
|
2011-10-09 14:53:38 +02:00
|
|
|
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
|
2011-06-10 21:26:12 +02:00
|
|
|
private transient boolean autoWarZoneEnabled;
|
2011-10-09 14:53:38 +02:00
|
|
|
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
|
2011-10-05 07:33:15 +02:00
|
|
|
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-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.
|
2011-10-08 22:03:44 +02:00
|
|
|
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;
|
2011-06-21 07:38:31 +02:00
|
|
|
this.autoClaimEnabled = false;
|
|
|
|
this.autoSafeZoneEnabled = false;
|
|
|
|
this.autoWarZoneEnabled = false;
|
2011-06-23 03:10:42 +02:00
|
|
|
this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false;
|
2011-10-05 07:33:15 +02:00
|
|
|
this.deleteMe = false;
|
2011-09-13 05:46:20 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if ( ! Conf.newPlayerStartingFactionID.equals("0") && Factions.i.exists(Conf.newPlayerStartingFactionID))
|
|
|
|
{
|
2011-09-13 05:46:20 +02:00
|
|
|
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-10-08 22:03:44 +02:00
|
|
|
{
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
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-08 22:03:44 +02:00
|
|
|
{
|
2011-10-10 01:21:05 +02:00
|
|
|
Faction currentFaction = this.getFaction();
|
|
|
|
if (currentFaction.isNormal())
|
|
|
|
{
|
|
|
|
currentFaction.clearClaimOwnership(this.getId());
|
|
|
|
}
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +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 = "";
|
2011-10-01 13:10:49 +02:00
|
|
|
this.autoClaimEnabled = false;
|
2011-08-20 03:36:23 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public ChatMode getChatMode()
|
|
|
|
{
|
|
|
|
if(this.factionId.equals("0"))
|
|
|
|
{
|
2011-09-24 12:04:49 +02:00
|
|
|
return ChatMode.PUBLIC;
|
2011-02-13 09:08:20 +01:00
|
|
|
}
|
2011-09-24 12:04:49 +02:00
|
|
|
return chatMode;
|
2011-02-13 09:08:20 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void setChatMode(ChatMode chatMode)
|
|
|
|
{
|
2011-09-24 12:04:49 +02:00
|
|
|
this.chatMode = chatMode;
|
2011-02-13 09:08:20 +01:00
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public long getLastLoginTime()
|
|
|
|
{
|
2011-03-22 20:36:33 +01:00
|
|
|
return lastLoginTime;
|
|
|
|
}
|
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2011-06-10 21:26:12 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void setLastLoginTime(long lastLoginTime)
|
|
|
|
{
|
2011-09-22 13:33:34 +02:00
|
|
|
losePowerFromBeingOffline();
|
2011-03-22 20:36:33 +01:00
|
|
|
this.lastLoginTime = lastLoginTime;
|
2011-05-29 23:28:29 +02:00
|
|
|
this.lastPowerUpdateTime = lastLoginTime;
|
2011-10-08 22:03:44 +02:00
|
|
|
if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0)
|
|
|
|
{
|
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 isMapAutoUpdating()
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
return mapAutoUpdating;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void setMapAutoUpdating(boolean mapAutoUpdating)
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
this.mapAutoUpdating = mapAutoUpdating;
|
|
|
|
}
|
2011-06-23 03:10:42 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean hasLoginPvpDisabled()
|
|
|
|
{
|
|
|
|
if (!loginPvpDisabled)
|
|
|
|
{
|
2011-06-23 03:10:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
if (this.lastLoginTime + (Conf.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis())
|
|
|
|
{
|
2011-06-23 03:10:42 +02:00
|
|
|
this.loginPvpDisabled = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-12 18:05:05 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public FLocation getLastStoodAt()
|
|
|
|
{
|
2011-03-22 17:20:21 +01:00
|
|
|
return this.lastStoodAt;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void setLastStoodAt(FLocation flocation)
|
|
|
|
{
|
2011-03-22 17:20:21 +01:00
|
|
|
this.lastStoodAt = flocation;
|
|
|
|
}
|
2011-10-05 07:33:15 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void markForDeletion(boolean delete)
|
|
|
|
{
|
2011-10-05 07:33:15 +02:00
|
|
|
deleteMe = delete;
|
|
|
|
}
|
2011-03-22 17:20:21 +01:00
|
|
|
|
2011-02-12 18:05:05 +01:00
|
|
|
//----------------------------------------------//
|
|
|
|
// Title, Name, Faction Tag and Chat
|
|
|
|
//----------------------------------------------//
|
|
|
|
|
|
|
|
// Base:
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getTitle()
|
|
|
|
{
|
2011-03-22 19:25:11 +01:00
|
|
|
return this.title;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void setTitle(String title)
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
this.title = title;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return this.getId(); // TODO: ... display name or remove completeley
|
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();
|
|
|
|
if (something.length() > 0) {
|
|
|
|
ret += something+" ";
|
|
|
|
}
|
|
|
|
ret += this.getName();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTitle()
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
return this.getNameAndSomething(this.getTitle());
|
|
|
|
}
|
|
|
|
|
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-02-12 18:05:05 +01:00
|
|
|
return this.getRelationColor(faction)+this.getNameAndTitle();
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTitle(FPlayer fplayer)
|
|
|
|
{
|
2011-03-23 12:00:38 +01:00
|
|
|
return this.getRelationColor(fplayer)+this.getNameAndTitle();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTag(Faction faction)
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
return this.getRelationColor(faction)+this.getNameAndTag();
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndTag(FPlayer fplayer)
|
|
|
|
{
|
2011-03-23 12:00:38 +01:00
|
|
|
return this.getRelationColor(fplayer)+this.getNameAndTag();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndRelevant(Faction faction)
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
// Which relation?
|
2011-10-12 17:25:01 +02:00
|
|
|
Relation rel = this.getRelationTo(faction);
|
2011-02-12 18:05:05 +01:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
public String getNameAndRelevant(FPlayer fplayer)
|
|
|
|
{
|
2011-03-23 12:00:38 +01:00
|
|
|
return getNameAndRelevant(fplayer.getFaction());
|
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 "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return String.format(Conf.chatTagFormat, this.role.getPrefix()+this.getTag());
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-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(fplayer).getColor()+getChatTag();
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// Relation and relation colors
|
|
|
|
// -------------------------------
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
@Override
|
|
|
|
public String describeTo(RelationParticipator that, boolean ucfirst)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return RelationUtil.describeThatToMe(that, this, ucfirst);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
@Override
|
|
|
|
public String describeTo(RelationParticipator that)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return RelationUtil.describeThatToMe(that, this);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
@Override
|
|
|
|
public Relation getRelationTo(RelationParticipator rp)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return RelationUtil.getRelationTo(this, rp);
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
@Override
|
|
|
|
public Relation getRelationTo(RelationParticipator rp, boolean ignorePeaceful)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return RelationUtil.getRelationTo(this, rp, ignorePeaceful);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
public Relation getRelationToLocation()
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return Board.getFactionAt(new FLocation(this)).getRelationTo(this);
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
@Override
|
|
|
|
public ChatColor getRelationColor(RelationParticipator rp)
|
|
|
|
{
|
|
|
|
return RelationUtil.getRelationColor(this, rp);
|
|
|
|
}
|
2011-02-12 18:05:05 +01:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
//----------------------------------------------//
|
|
|
|
// Health
|
|
|
|
//----------------------------------------------//
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// Power
|
|
|
|
//----------------------------------------------//
|
2011-10-08 22:03:44 +02:00
|
|
|
public double getPower()
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
this.updatePower();
|
|
|
|
return this.power;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
protected void alterPower(double delta)
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
this.power += delta;
|
2011-10-08 22:03:44 +02:00
|
|
|
if (this.power > this.getPowerMax())
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
this.power = this.getPowerMax();
|
2011-10-08 22:03:44 +02:00
|
|
|
} else if (this.power < this.getPowerMin())
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
this.power = this.getPowerMin();
|
|
|
|
}
|
2011-02-13 17:02:51 +01:00
|
|
|
//Log.debug("Power of "+this.getName()+" is now: "+this.power);
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public double getPowerMax()
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
return Conf.powerPlayerMax;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public double getPowerMin()
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
return Conf.powerPlayerMin;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public int getPowerRounded()
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
return (int) Math.round(this.getPower());
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public int getPowerMaxRounded()
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
return (int) Math.round(this.getPowerMax());
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public int getPowerMinRounded()
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
return (int) Math.round(this.getPowerMin());
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
protected void updatePower()
|
|
|
|
{
|
|
|
|
if (this.isOffline())
|
|
|
|
{
|
2011-09-22 13:33:34 +02:00
|
|
|
losePowerFromBeingOffline();
|
2011-10-08 22:03:44 +02:00
|
|
|
if (!Conf.powerRegenOffline)
|
|
|
|
{
|
2011-09-22 13:33:34 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-05-29 23:28:29 +02:00
|
|
|
}
|
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);
|
|
|
|
}
|
2011-09-22 13:33:34 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
protected void losePowerFromBeingOffline()
|
|
|
|
{
|
|
|
|
if (Conf.powerOfflineLossPerDay > 0.0 && this.power > Conf.powerOfflineLossLimit)
|
|
|
|
{
|
2011-09-22 13:33:34 +02:00
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
long millisPassed = now - this.lastPowerUpdateTime;
|
|
|
|
this.lastPowerUpdateTime = now;
|
|
|
|
|
|
|
|
double loss = millisPassed * Conf.powerOfflineLossPerDay / (24*60*60*1000);
|
2011-10-08 22:03:44 +02:00
|
|
|
if (this.power - loss < Conf.powerOfflineLossLimit)
|
|
|
|
{
|
2011-09-22 13:33:34 +02:00
|
|
|
loss = this.power;
|
|
|
|
}
|
|
|
|
this.alterPower(-loss);
|
|
|
|
}
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public void onDeath()
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
this.updatePower();
|
|
|
|
this.alterPower(-Conf.powerPerDeath);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// Territory
|
|
|
|
//----------------------------------------------//
|
2011-10-08 22:03:44 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean isInOthersTerritory()
|
|
|
|
{
|
2011-10-09 14:53:38 +02:00
|
|
|
Faction factionHere = Board.getFactionAt(new FLocation(this));
|
|
|
|
return factionHere != null && factionHere.isNormal() && factionHere != this.getFaction();
|
2011-06-19 10:56:21 +02:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean isInAllyTerritory()
|
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return Board.getFactionAt(new FLocation(this)).getRelationTo(this).isAlly();
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean isInNeutralTerritory()
|
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return Board.getFactionAt(new FLocation(this)).getRelationTo(this).isNeutral();
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean isInEnemyTerritory()
|
|
|
|
{
|
2011-10-12 17:25:01 +02:00
|
|
|
return Board.getFactionAt(new FLocation(this)).getRelationTo(this).isEnemy();
|
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;
|
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
Faction factionHere = Board.getFactionAt(new FLocation(this));
|
2011-10-08 22:03:44 +02:00
|
|
|
String msg = P.p.txt.parse("<i>")+" ~ "+factionHere.getTag(this);
|
|
|
|
if (factionHere.getDescription().length() > 0)
|
|
|
|
{
|
2011-02-12 18:05:05 +01:00
|
|
|
msg += " - "+factionHere.getDescription();
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
this.sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
2011-03-22 20:36:33 +01:00
|
|
|
// -------------------------------
|
|
|
|
// Actions
|
|
|
|
// -------------------------------
|
|
|
|
|
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();
|
2011-09-13 20:14:09 +02:00
|
|
|
boolean perm = myFaction.isPermanent();
|
2011-03-22 20:36:33 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (!perm && this.getRole() == Role.ADMIN && 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;
|
|
|
|
}
|
2011-04-28 22:45:43 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (!Conf.CanLeaveWithNegativePower && this.getPower() < 0)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
// 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())
|
2011-10-08 22:03:44 +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
|
|
|
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;
|
|
|
|
/*
|
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
|
|
|
// pay up
|
|
|
|
if (cost > 0.0) {
|
|
|
|
String costString = Econ.moneyString(cost);
|
2011-10-12 17:25:01 +02:00
|
|
|
if ( ! Econ.deductMoney(this.getName(), cost)) {
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>It costs <h>%s<b> to leave your faction, which you can't currently afford.", costString);
|
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
|
|
|
return;
|
|
|
|
}
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<i>You have paid <h>%s<i> to leave your faction.", costString);
|
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
|
|
|
}
|
|
|
|
// wait... we pay you to leave?
|
2011-10-08 22:03:44 +02:00
|
|
|
else if (cost < 0.0)
|
|
|
|
{
|
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
|
|
|
String costString = Econ.moneyString(-cost);
|
|
|
|
Econ.addMoney(this.getName(), -cost);
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<i>You have been paid <h>%s<i> for leaving your faction.", costString);
|
2011-10-12 17:25:01 +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-08 22:03:44 +02:00
|
|
|
if (myFaction.isNormal())
|
|
|
|
{
|
2011-10-12 21:54:38 +02:00
|
|
|
//myFaction.msg("%s<i> left your faction.", this.getNameAndRelevant(myFaction));
|
|
|
|
for (FPlayer fplayer : myFaction.getFPlayersWhereOnline(true))
|
|
|
|
{
|
|
|
|
fplayer.msg("%s<i> left your faction.", this.describeTo(fplayer, true));
|
|
|
|
}
|
2011-04-28 22:45:43 +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-10-12 21:54:38 +02:00
|
|
|
// Transfer all money
|
2011-10-13 06:44:59 +02:00
|
|
|
if (Econ.shouldBeUsed())
|
|
|
|
Econ.transferMoney(this, myFaction, this, myFaction.getAccount().balance());
|
|
|
|
|
2011-03-22 20:36:33 +01:00
|
|
|
// Remove this faction
|
2011-10-08 22:03:44 +02:00
|
|
|
for (FPlayer fplayer : FPlayers.i.getOnline())
|
|
|
|
{
|
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();
|
2011-03-22 20:36:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean attemptClaim(boolean notifyFailure)
|
|
|
|
{
|
2011-07-24 13:12:01 +02:00
|
|
|
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
|
2011-06-10 21:26:12 +02:00
|
|
|
// return value is false on failure, true on success
|
|
|
|
|
|
|
|
Faction myFaction = getFaction();
|
2011-09-08 13:24:55 +02:00
|
|
|
Location loc = this.getPlayer().getLocation();
|
|
|
|
FLocation flocation = new FLocation(loc);
|
2011-06-10 21:26:12 +02:00
|
|
|
Faction otherFaction = Board.getFactionAt(flocation);
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(loc))
|
|
|
|
{
|
2011-08-29 14:54:04 +02:00
|
|
|
// Checks for WorldGuard regions in the chunk attempting to be claimed
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>This land is protected");
|
2011-08-29 14:54:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (myFaction == otherFaction)
|
|
|
|
{
|
2011-06-10 21:26:12 +02:00
|
|
|
if (notifyFailure)
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<i>You already own this land.");
|
2011-06-10 21:26:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (this.getRole().value < Role.MODERATOR.value)
|
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<i>You must be "+Role.MODERATOR+" to claim land.");
|
2011-06-10 21:26:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
if (myFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers && ! this.isAdminBypassing())
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>Your faction must have at least <h>%s<b> members to claim land.", Conf.claimsRequireMinFactionMembers);
|
2011-07-25 20:16:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (Conf.worldsNoClaiming.contains(flocation.getWorldName()))
|
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>Sorry, this world has land claiming disabled.");
|
2011-06-10 21:26:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
|
|
|
|
if (otherFaction.isSafeZone())
|
|
|
|
{
|
2011-06-10 21:26:12 +02:00
|
|
|
if (notifyFailure)
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>You can not claim a Safe Zone.");
|
2011-06-10 21:26:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
else if (otherFaction.isWarZone())
|
|
|
|
{
|
2011-06-10 21:26:12 +02:00
|
|
|
if (notifyFailure)
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>You can not claim a War Zone.");
|
2011-06-10 21:26:12 +02:00
|
|
|
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
|
|
|
int ownedLand = myFaction.getLandRounded();
|
2011-10-08 22:03:44 +02:00
|
|
|
if (ownedLand >= myFaction.getPowerRounded())
|
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>You can't claim more land! You need more power!");
|
2011-06-10 21:26:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
if (otherFaction.getRelationTo(this) == Relation.ALLY)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-06-10 21:26:12 +02:00
|
|
|
if (notifyFailure)
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>You can't claim the land of your allies.");
|
2011-06-10 21:26:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if
|
|
|
|
(
|
|
|
|
Conf.claimsMustBeConnected
|
2011-10-09 18:35:39 +02:00
|
|
|
&& ! this.isAdminBypassing()
|
2011-10-08 22:03:44 +02:00
|
|
|
&& myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0
|
|
|
|
&& !Board.isConnectedLocation(flocation, myFaction)
|
|
|
|
&& (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !otherFaction.isNormal())
|
|
|
|
)
|
|
|
|
{
|
2011-07-20 21:45:18 +02:00
|
|
|
if (Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<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
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>You can only claim additional land which is connected to your first claim!");
|
2011-06-21 04:15:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (otherFaction.isNormal())
|
|
|
|
{
|
|
|
|
if (myFaction.isPeaceful())
|
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("%s<i> owns this land. Your faction is peaceful, so you cannot claim land from other factions.", otherFaction.getTag(this));
|
2011-08-05 10:50:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
|
|
|
|
if (otherFaction.isPeaceful())
|
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("%s<i> owns this land, and is a peaceful faction. You cannot claim land from them.", otherFaction.getTag(this));
|
2011-08-05 10:50:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if ( ! otherFaction.hasLandInflation())
|
|
|
|
{
|
2011-06-10 21:26:12 +02:00
|
|
|
// TODO more messages WARN current faction most importantly
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("%s<i> owns this land and is strong enough to keep it.", otherFaction.getTag(this));
|
2011-06-10 21:26:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if ( ! Board.isBorderLocation(flocation))
|
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>You must start claiming land at the border of the territory.");
|
2011-06-10 21:26:12 +02:00
|
|
|
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
|
|
|
}
|
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
|
|
|
// if economy is enabled and they're not on the bypass list, make 'em pay
|
2011-10-12 17:25:01 +02:00
|
|
|
if (Econ.shouldBeUsed() && ! this.isAdminBypassing())
|
2011-10-08 22:03:44 +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
|
|
|
double cost = Econ.calculateClaimCost(ownedLand, otherFaction.isNormal());
|
2011-10-12 17:25:01 +02:00
|
|
|
//String costString = Econ.moneyString(cost);
|
2011-09-24 03:22:53 +02:00
|
|
|
|
2011-10-08 22:03:44 +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-10 01:21:05 +02:00
|
|
|
if( ! faction.removeMoney(cost))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<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;
|
2011-10-08 22:03:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-10 01:21:05 +02:00
|
|
|
// TODO: Only I can see this right?
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("%s<i> has paid <h>%s<i> to claim some land.", faction.getTag(this), costString);
|
2011-10-12 17:25:01 +02:00
|
|
|
}*/
|
2011-10-08 22:03:44 +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;
|
|
|
|
/*if ( ! Econ.deductMoney(this.getId(), cost))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<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;
|
|
|
|
}
|
2011-10-12 17:25:01 +02:00
|
|
|
sendMessage("You have paid "+costString+" to claim this land.");*/
|
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-08 22:03:44 +02:00
|
|
|
if (otherFaction.isNormal())
|
|
|
|
{
|
2011-06-10 21:26:12 +02:00
|
|
|
// ASDF claimed some of your land 450 blocks NNW of you.
|
|
|
|
// ASDf claimed some land from FACTION NAME
|
2011-10-08 22:03:44 +02:00
|
|
|
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)));
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
myFaction.sendMessage(P.p.txt.parse(this.getNameAndRelevant(myFaction)+"<i> claimed some new land :D"));
|
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-06-10 21:26:12 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
/*private static FPlayer get(String playerName)
|
|
|
|
{
|
|
|
|
if (instances.containsKey(playerName))
|
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
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;
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
instances.put(playerName, vplayer);
|
2011-03-18 17:33:23 +01:00
|
|
|
return vplayer;
|
2011-10-08 22:03:44 +02:00
|
|
|
}*/
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-03-18 17:33:23 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// Persistance
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
@Override
|
|
|
|
public boolean shouldBeSaved()
|
|
|
|
{
|
|
|
|
return ! this.deleteMe;
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02: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 {
|
2011-10-08 22:03:44 +02:00
|
|
|
DiscUtil.write(file, P.p.gson.toJson(playersToSave));
|
2011-04-06 11:08:08 +02:00
|
|
|
} catch (Exception e) {
|
2011-03-18 17:33:23 +01:00
|
|
|
e.printStackTrace();
|
2011-10-08 22:03:44 +02:00
|
|
|
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() {
|
2011-10-08 22:03:44 +02:00
|
|
|
P.log("Loading players from disk");
|
2011-03-18 17:33:23 +01:00
|
|
|
if ( ! file.exists()) {
|
2011-03-26 15:01:48 +01:00
|
|
|
if ( ! loadOld())
|
2011-10-08 22:03:44 +02:00
|
|
|
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();
|
2011-10-08 22:03:44 +02:00
|
|
|
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);
|
2011-04-06 11:08:08 +02:00
|
|
|
} catch (Exception e) {
|
2011-03-18 17:33:23 +01:00
|
|
|
e.printStackTrace();
|
2011-10-08 22:03:44 +02:00
|
|
|
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()) {
|
2011-03-22 15:45:41 +01:00
|
|
|
entry.getValue().playerName = entry.getKey();
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
*/
|
2011-03-18 17:33:23 +01:00
|
|
|
|
2011-03-26 15:01:48 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
/*private static boolean loadOld()
|
|
|
|
{
|
|
|
|
File folderFollower = new File(P.p.getDataFolder(), "follower");
|
2011-03-26 15:01:48 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if ( ! folderFollower.isDirectory()) return false;
|
2011-03-26 15:01:48 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
p.log("Players file doesn't exist, attempting to load old pre-1.1 data.");
|
2011-03-26 15:01:48 +01:00
|
|
|
|
|
|
|
String ext = ".json";
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
class jsonFileFilter implements FileFilter
|
|
|
|
{
|
2011-03-26 15:01:48 +01:00
|
|
|
@Override
|
2011-10-08 22:03:44 +02:00
|
|
|
public boolean accept(File file)
|
|
|
|
{
|
2011-03-26 15:01:48 +01:00
|
|
|
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 {
|
2011-10-08 22:03:44 +02:00
|
|
|
FPlayer follower = P.p.gson.fromJson(DiscUtil.read(jsonFile), FPlayer.class);
|
2011-03-26 15:01:48 +01:00
|
|
|
follower.playerName = name;
|
|
|
|
follower.lastLoginTime = System.currentTimeMillis();
|
|
|
|
instances.put(follower.playerName, follower);
|
2011-10-08 22:03:44 +02:00
|
|
|
P.log("loaded pre-1.1 follower "+name);
|
2011-03-26 15:01:48 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2011-10-08 22:03:44 +02:00
|
|
|
P.log(Level.WARNING, "failed to load follower "+name);
|
2011-03-26 15:01:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-10-08 22:03:44 +02:00
|
|
|
}*/
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2011-10-10 13:40:24 +02:00
|
|
|
public void msg(String str, Object... args)
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
|
|
|
this.sendMessage(P.p.txt.parse(str, args));
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|