2014-09-17 13:17:33 +02:00
|
|
|
package com.massivecraft.factions.entity;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.Factions;
|
2017-03-24 22:59:44 +01:00
|
|
|
import com.massivecraft.factions.FactionsIndex;
|
2017-03-15 18:22:17 +01:00
|
|
|
import com.massivecraft.factions.FactionsParticipator;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
|
|
|
import com.massivecraft.factions.Rel;
|
|
|
|
import com.massivecraft.factions.RelationParticipator;
|
2014-10-13 11:42:40 +02:00
|
|
|
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
|
|
|
import com.massivecraft.factions.event.EventFactionsChunksChange;
|
2014-10-21 07:48:42 +02:00
|
|
|
import com.massivecraft.factions.event.EventFactionsDisband;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
|
|
|
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
2017-03-15 18:22:17 +01:00
|
|
|
import com.massivecraft.factions.event.EventFactionsRemovePlayerMillis;
|
2017-02-10 18:34:42 +01:00
|
|
|
import com.massivecraft.factions.mixin.PowerMixin;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.util.RelationUtil;
|
2016-05-13 12:32:05 +02:00
|
|
|
import com.massivecraft.massivecore.mixin.MixinSenderPs;
|
|
|
|
import com.massivecraft.massivecore.mixin.MixinTitle;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.massivecore.ps.PS;
|
|
|
|
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
|
|
|
|
import com.massivecraft.massivecore.store.SenderEntity;
|
|
|
|
import com.massivecraft.massivecore.util.IdUtil;
|
|
|
|
import com.massivecraft.massivecore.util.MUtil;
|
|
|
|
import com.massivecraft.massivecore.util.Txt;
|
2016-02-02 19:03:11 +01:00
|
|
|
import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
|
2017-03-24 13:05:58 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
import java.lang.ref.WeakReference;
|
2017-03-24 13:05:58 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Set;
|
2014-09-17 13:17:33 +02:00
|
|
|
|
2017-03-15 18:22:17 +01:00
|
|
|
public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipator
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// META
|
|
|
|
// -------------------------------------------- //
|
2017-03-24 14:29:26 +01:00
|
|
|
|
|
|
|
public static final transient String NOTITLE = Txt.parse("<em><silver>no title set");
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// META
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public static MPlayer get(Object oid)
|
|
|
|
{
|
|
|
|
return MPlayerColl.get().get(oid);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
2016-07-30 12:09:20 +02:00
|
|
|
// LOAD
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public MPlayer load(MPlayer that)
|
|
|
|
{
|
2014-10-06 13:08:34 +02:00
|
|
|
this.setLastActivityMillis(that.lastActivityMillis);
|
2014-09-17 13:17:33 +02:00
|
|
|
this.setFactionId(that.factionId);
|
|
|
|
this.setRole(that.role);
|
|
|
|
this.setTitle(that.title);
|
|
|
|
this.setPowerBoost(that.powerBoost);
|
|
|
|
this.setPower(that.power);
|
|
|
|
this.setMapAutoUpdating(that.mapAutoUpdating);
|
2016-02-02 19:03:11 +01:00
|
|
|
this.setOverriding(that.overriding);
|
2015-08-28 09:00:24 +02:00
|
|
|
this.setTerritoryInfoTitles(that.territoryInfoTitles);
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
return this;
|
|
|
|
}
|
2017-04-20 11:05:56 +02:00
|
|
|
|
2016-07-30 12:09:20 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// IS DEFAULT
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public boolean isDefault()
|
|
|
|
{
|
2014-10-06 13:08:34 +02:00
|
|
|
// Last activity millis is data we use for clearing out inactive players. So it does not in itself make the player data worth keeping.
|
2014-09-17 13:17:33 +02:00
|
|
|
if (this.hasFaction()) return false;
|
|
|
|
// Role means nothing without a faction.
|
|
|
|
// Title means nothing without a faction.
|
2014-10-06 13:08:34 +02:00
|
|
|
if (this.hasPowerBoost()) return false;
|
2014-09-17 13:17:33 +02:00
|
|
|
if (this.getPowerRounded() != (int) Math.round(MConf.get().defaultPlayerPower)) return false;
|
2014-10-06 13:08:34 +02:00
|
|
|
// if (this.isMapAutoUpdating()) return false; // Just having an auto updating map is not in itself reason enough for database storage.
|
2016-02-02 19:03:11 +01:00
|
|
|
if (this.isOverriding()) return false;
|
2015-08-28 09:00:24 +02:00
|
|
|
if (this.isTerritoryInfoTitles() != MConf.get().territoryInfoTitlesDefault) return false;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2016-07-30 12:09:20 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// UPDATE FACTION INDEXES
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public void postAttach(String id)
|
|
|
|
{
|
2017-03-24 22:59:44 +01:00
|
|
|
FactionsIndex.get().update(this);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public void preDetach(String id)
|
|
|
|
{
|
2017-03-24 22:59:44 +01:00
|
|
|
FactionsIndex.get().update(this);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELDS: RAW
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// 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.
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// The last known time of explicit player activity, such as login or logout.
|
2014-11-21 09:59:04 +01:00
|
|
|
// This value is most importantly used for removing inactive players.
|
|
|
|
// For that reason it defaults to the current time.
|
|
|
|
// Really inactive players will be considered newly active when upgrading Factions from 2.6 --> 2.7.
|
|
|
|
// There is actually more than one reason we store this data ourselves and don't use the OfflinePlayer#getLastPlayed.
|
|
|
|
// 1. I don't trust that method. It's been very buggy or even completely broken in previous Bukkit versions.
|
|
|
|
// 2. The method depends on the player.dat files being present.
|
2016-08-03 12:51:06 +02:00
|
|
|
// Server owners clear those files at times, or move their database data around between different servers.
|
2014-11-21 09:59:04 +01:00
|
|
|
private long lastActivityMillis = System.currentTimeMillis();
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// This is a foreign key.
|
|
|
|
// Each player belong to a faction.
|
2014-09-17 13:33:09 +02:00
|
|
|
// Null means default.
|
2014-09-17 13:17:33 +02:00
|
|
|
private String factionId = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// What role does the player have in the faction?
|
2014-09-17 13:33:09 +02:00
|
|
|
// Null means default.
|
2014-09-17 13:17:33 +02:00
|
|
|
private Rel role = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// What title does the player have in the faction?
|
|
|
|
// The title is just for fun. It's not connected to any game mechanic.
|
|
|
|
// The player title is similar to the faction description.
|
2016-08-03 12:51:06 +02:00
|
|
|
//
|
2014-09-17 13:17:33 +02:00
|
|
|
// 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.
|
2016-08-03 12:51:06 +02:00
|
|
|
// If the title contains raw markup, such as "<white>" instead of "§f" it will not be parsed and "<white>" will be displayed.
|
2014-09-17 13:17:33 +02:00
|
|
|
//
|
|
|
|
// Null means the player has no title.
|
|
|
|
private String title = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// 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.
|
2016-08-03 12:51:06 +02:00
|
|
|
private Double powerBoost = null;
|
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Each player has an individual power level.
|
|
|
|
// The power level for online players is occasionally updated by a recurring task and the power should stay the same for offline players.
|
|
|
|
// For that reason the value is to be considered correct when you pick it. Do not call the power update method.
|
2014-09-17 13:33:09 +02:00
|
|
|
// Null means default.
|
2014-09-17 13:17:33 +02:00
|
|
|
private Double power = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Has this player requested an auto-updating ascii art map?
|
|
|
|
// Null means false
|
|
|
|
private Boolean mapAutoUpdating = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2016-02-02 19:03:11 +01:00
|
|
|
// Is this player overriding?
|
2014-09-17 13:17:33 +02:00
|
|
|
// Null means false
|
2016-02-02 19:03:11 +01:00
|
|
|
@SerializedName(value = "usingAdminMode")
|
|
|
|
private Boolean overriding = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2015-08-28 09:00:24 +02:00
|
|
|
// Does this player use titles for territory info?
|
|
|
|
// Null means default specified in MConf.
|
|
|
|
private Boolean territoryInfoTitles = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
// The Faction this player is currently autoclaiming for.
|
2014-09-17 13:17:33 +02:00
|
|
|
// Null means the player isn't auto claiming.
|
2014-10-08 06:38:26 +02:00
|
|
|
// NOTE: This field will not be saved to the database ever.
|
2017-03-25 00:47:01 +01:00
|
|
|
private transient WeakReference<Faction> autoClaimFaction = new WeakReference<>(null);
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
public Faction getAutoClaimFaction()
|
|
|
|
{
|
|
|
|
if (this.isFactionOrphan()) return null;
|
|
|
|
Faction ret = this.autoClaimFaction.get();
|
|
|
|
if (ret == null) return null;
|
|
|
|
if (ret.detached()) return null;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = new WeakReference<>(autoClaimFaction); }
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-08 06:38:26 +02:00
|
|
|
// Does the player have /f seechunk activated?
|
|
|
|
// NOTE: This field will not be saved to the database ever.
|
|
|
|
private transient boolean seeingChunk = false;
|
|
|
|
public boolean isSeeingChunk() { return this.seeingChunk; }
|
|
|
|
public void setSeeingChunk(boolean seeingChunk) { this.seeingChunk = seeingChunk; }
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CORE UTILITIES
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void resetFactionData()
|
|
|
|
{
|
|
|
|
// The default neutral faction
|
|
|
|
this.setFactionId(null);
|
|
|
|
this.setRole(null);
|
|
|
|
this.setTitle(null);
|
|
|
|
this.setAutoClaimFaction(null);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: lastActivityMillis
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-11-21 09:59:04 +01:00
|
|
|
public long getLastActivityMillis()
|
2014-10-06 13:08:34 +02:00
|
|
|
{
|
|
|
|
return this.lastActivityMillis;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-11-21 09:59:04 +01:00
|
|
|
public void setLastActivityMillis(long lastActivityMillis)
|
2014-10-06 13:08:34 +02:00
|
|
|
{
|
|
|
|
// Clean input
|
2014-11-21 09:59:04 +01:00
|
|
|
long target = lastActivityMillis;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Detect Nochange
|
|
|
|
if (MUtil.equals(this.lastActivityMillis, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Apply
|
|
|
|
this.lastActivityMillis = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
public void setLastActivityMillis()
|
|
|
|
{
|
|
|
|
this.setLastActivityMillis(System.currentTimeMillis());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: factionId
|
|
|
|
// -------------------------------------------- //
|
2017-03-25 00:47:01 +01:00
|
|
|
|
|
|
|
private Faction getFactionInternal()
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2017-03-25 00:47:01 +01:00
|
|
|
String effectiveFactionId = this.convertGet(this.factionId, MConf.get().defaultPlayerFactionId);
|
|
|
|
return Faction.get(effectiveFactionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFactionOrphan()
|
|
|
|
{
|
|
|
|
return this.getFactionInternal() == null;
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2017-03-25 00:47:01 +01:00
|
|
|
@Deprecated
|
2014-09-17 13:17:33 +02:00
|
|
|
public String getFactionId()
|
|
|
|
{
|
2017-03-25 00:47:01 +01:00
|
|
|
return this.getFaction().getId();
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// This method never returns null
|
|
|
|
public Faction getFaction()
|
|
|
|
{
|
2017-03-25 00:47:01 +01:00
|
|
|
Faction ret;
|
|
|
|
|
|
|
|
ret = this.getFactionInternal();
|
|
|
|
|
|
|
|
// Adopt orphans
|
|
|
|
if (ret == null)
|
|
|
|
{
|
|
|
|
ret = FactionColl.get().getNone();
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2017-03-25 00:47:01 +01:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public boolean hasFaction()
|
|
|
|
{
|
2017-03-25 00:47:01 +01:00
|
|
|
return !this.getFaction().isNone();
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
|
|
|
// This setter is so long because it search for default/null case and takes
|
|
|
|
// care of updating the faction member index
|
2014-09-17 13:17:33 +02:00
|
|
|
public void setFactionId(String factionId)
|
|
|
|
{
|
2016-08-03 12:51:06 +02:00
|
|
|
// Before
|
|
|
|
String beforeId = this.factionId;
|
|
|
|
|
|
|
|
// After
|
|
|
|
String afterId = factionId;
|
|
|
|
|
|
|
|
// NoChange
|
|
|
|
if (MUtil.equals(beforeId, afterId)) return;
|
2014-09-17 13:17:33 +02:00
|
|
|
|
|
|
|
// Apply
|
2016-08-03 12:51:06 +02:00
|
|
|
this.factionId = afterId;
|
|
|
|
|
2017-03-24 22:59:44 +01:00
|
|
|
// Index
|
|
|
|
FactionsIndex.get().update(this);
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void setFaction(Faction faction)
|
|
|
|
{
|
|
|
|
this.setFactionId(faction.getId());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: role
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public Rel getRole()
|
|
|
|
{
|
2017-03-25 00:47:01 +01:00
|
|
|
if (this.isFactionOrphan()) return Rel.RECRUIT;
|
|
|
|
|
2014-11-14 08:41:58 +01:00
|
|
|
if (this.role == null) return MConf.get().defaultPlayerRole;
|
2014-09-17 13:17:33 +02:00
|
|
|
return this.role;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void setRole(Rel role)
|
|
|
|
{
|
|
|
|
// Clean input
|
|
|
|
Rel target = role;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Detect Nochange
|
|
|
|
if (MUtil.equals(this.role, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Apply
|
|
|
|
this.role = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: title
|
|
|
|
// -------------------------------------------- //
|
2017-03-25 00:47:01 +01:00
|
|
|
// TODO: Improve upon the has and get stuff.
|
|
|
|
// TODO: Has should depend on get. Visualisation should be done elsewhere.
|
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public boolean hasTitle()
|
|
|
|
{
|
2017-03-25 00:47:01 +01:00
|
|
|
return !this.isFactionOrphan() && this.title != null;
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public String getTitle()
|
|
|
|
{
|
2017-03-25 00:47:01 +01:00
|
|
|
if (this.isFactionOrphan()) return NOTITLE;
|
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
if (this.hasTitle()) return this.title;
|
2017-03-25 00:47:01 +01:00
|
|
|
|
2017-03-24 14:29:26 +01:00
|
|
|
return NOTITLE;
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void setTitle(String title)
|
|
|
|
{
|
|
|
|
// Clean input
|
2017-04-21 20:12:41 +02:00
|
|
|
String target = Faction.clean(title);
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Detect Nochange
|
|
|
|
if (MUtil.equals(this.title, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Apply
|
|
|
|
this.title = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: powerBoost
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2017-03-15 18:22:17 +01:00
|
|
|
@Override
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getPowerBoost()
|
|
|
|
{
|
|
|
|
Double ret = this.powerBoost;
|
|
|
|
if (ret == null) ret = 0D;
|
|
|
|
return ret;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2017-03-15 18:22:17 +01:00
|
|
|
@Override
|
2014-09-17 13:17:33 +02:00
|
|
|
public void setPowerBoost(Double powerBoost)
|
|
|
|
{
|
|
|
|
// Clean input
|
|
|
|
Double target = powerBoost;
|
|
|
|
if (target == null || target == 0) target = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Detect Nochange
|
|
|
|
if (MUtil.equals(this.powerBoost, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Apply
|
|
|
|
this.powerBoost = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public boolean hasPowerBoost()
|
|
|
|
{
|
|
|
|
return this.getPowerBoost() != 0D;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: power
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// MIXIN: RAW
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getPowerMaxUniversal()
|
|
|
|
{
|
2017-02-10 18:34:42 +01:00
|
|
|
return PowerMixin.get().getMaxUniversal(this);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getPowerMax()
|
|
|
|
{
|
2017-02-10 18:34:42 +01:00
|
|
|
return PowerMixin.get().getMax(this);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getPowerMin()
|
|
|
|
{
|
2017-02-10 18:34:42 +01:00
|
|
|
return PowerMixin.get().getMin(this);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getPowerPerHour()
|
|
|
|
{
|
2017-02-10 18:34:42 +01:00
|
|
|
return PowerMixin.get().getPerHour(this);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getPowerPerDeath()
|
|
|
|
{
|
2017-02-10 18:34:42 +01:00
|
|
|
return PowerMixin.get().getPerDeath(this);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// MIXIN: FINER
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getLimitedPower(double power)
|
|
|
|
{
|
|
|
|
power = Math.max(power, this.getPowerMin());
|
|
|
|
power = Math.min(power, this.getPowerMax());
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
return power;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public int getPowerMaxRounded()
|
|
|
|
{
|
|
|
|
return (int) Math.round(this.getPowerMax());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public int getPowerMinRounded()
|
|
|
|
{
|
|
|
|
return (int) Math.round(this.getPowerMin());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public int getPowerMaxUniversalRounded()
|
|
|
|
{
|
|
|
|
return (int) Math.round(this.getPowerMaxUniversal());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// RAW
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-11-14 08:41:58 +01:00
|
|
|
@Deprecated
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getDefaultPower()
|
|
|
|
{
|
|
|
|
return MConf.get().defaultPlayerPower;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public double getPower()
|
|
|
|
{
|
|
|
|
Double ret = this.power;
|
2014-11-14 08:41:58 +01:00
|
|
|
if (ret == null) ret = MConf.get().defaultPlayerPower;
|
2014-09-17 13:17:33 +02:00
|
|
|
ret = this.getLimitedPower(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void setPower(Double power)
|
|
|
|
{
|
|
|
|
// Clean input
|
|
|
|
Double target = power;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Detect Nochange
|
|
|
|
if (MUtil.equals(this.power, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Apply
|
|
|
|
this.power = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// FINER
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public int getPowerRounded()
|
|
|
|
{
|
|
|
|
return (int) Math.round(this.getPower());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: mapAutoUpdating
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public boolean isMapAutoUpdating()
|
|
|
|
{
|
|
|
|
if (this.mapAutoUpdating == null) return false;
|
|
|
|
if (this.mapAutoUpdating == false) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void setMapAutoUpdating(Boolean mapAutoUpdating)
|
|
|
|
{
|
|
|
|
// Clean input
|
|
|
|
Boolean target = mapAutoUpdating;
|
2014-09-17 16:15:33 +02:00
|
|
|
if (MUtil.equals(target, false)) target = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Detect Nochange
|
|
|
|
if (MUtil.equals(this.mapAutoUpdating, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Apply
|
|
|
|
this.mapAutoUpdating = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
2016-02-02 19:03:11 +01:00
|
|
|
// FIELD: overriding
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2016-02-02 19:03:11 +01:00
|
|
|
public boolean isOverriding()
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2016-02-02 19:03:11 +01:00
|
|
|
if (this.overriding == null) return false;
|
|
|
|
if (this.overriding == false) return false;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2016-06-16 19:25:07 +02:00
|
|
|
if (!this.hasPermission(Perm.OVERRIDE, true))
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2016-02-02 19:03:11 +01:00
|
|
|
this.setOverriding(false);
|
2014-11-14 08:41:58 +01:00
|
|
|
return false;
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2016-02-02 19:03:11 +01:00
|
|
|
public void setOverriding(Boolean overriding)
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
|
|
|
// Clean input
|
2016-02-02 19:03:11 +01:00
|
|
|
Boolean target = overriding;
|
2014-09-17 16:15:33 +02:00
|
|
|
if (MUtil.equals(target, false)) target = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Detect Nochange
|
2016-02-02 19:03:11 +01:00
|
|
|
if (MUtil.equals(this.overriding, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Apply
|
2016-02-02 19:03:11 +01:00
|
|
|
this.overriding = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2015-08-28 09:00:24 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELD: territoryInfoTitles
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2015-08-28 09:00:24 +02:00
|
|
|
public boolean isTerritoryInfoTitles()
|
|
|
|
{
|
2016-08-03 12:51:06 +02:00
|
|
|
if (!MixinTitle.get().isAvailable()) return false;
|
2015-08-28 09:00:24 +02:00
|
|
|
if (this.territoryInfoTitles == null) return MConf.get().territoryInfoTitlesDefault;
|
|
|
|
return this.territoryInfoTitles;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2015-08-28 09:00:24 +02:00
|
|
|
public void setTerritoryInfoTitles(Boolean territoryInfoTitles)
|
|
|
|
{
|
|
|
|
// Clean input
|
|
|
|
Boolean target = territoryInfoTitles;
|
|
|
|
if (MUtil.equals(target, MConf.get().territoryInfoTitlesDefault)) target = null;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2015-08-28 09:00:24 +02:00
|
|
|
// Detect Nochange
|
|
|
|
if (MUtil.equals(this.territoryInfoTitles, target)) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2015-08-28 09:00:24 +02:00
|
|
|
// Apply
|
|
|
|
this.territoryInfoTitles = target;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2015-08-28 09:00:24 +02:00
|
|
|
// Mark as changed
|
|
|
|
this.changed();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// TITLE, NAME, FACTION NAME AND CHAT
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public String getFactionName()
|
|
|
|
{
|
|
|
|
Faction faction = this.getFaction();
|
|
|
|
if (faction.isNone()) return "";
|
|
|
|
return faction.getName();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Base concatenations:
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public String getNameAndSomething(String color, String something)
|
|
|
|
{
|
|
|
|
String ret = "";
|
|
|
|
ret += color;
|
|
|
|
ret += this.getRole().getPrefix();
|
|
|
|
if (something != null && something.length() > 0)
|
|
|
|
{
|
|
|
|
ret += something;
|
|
|
|
ret += " ";
|
|
|
|
ret += color;
|
|
|
|
}
|
|
|
|
ret += this.getName();
|
|
|
|
return ret;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public String getNameAndFactionName()
|
|
|
|
{
|
|
|
|
return this.getNameAndSomething("", this.getFactionName());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public String getNameAndTitle(String color)
|
|
|
|
{
|
|
|
|
if (this.hasTitle())
|
|
|
|
{
|
|
|
|
return this.getNameAndSomething(color, this.getTitle());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.getNameAndSomething(color, null);
|
|
|
|
}
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Colored concatenations:
|
|
|
|
// These are used in information messages
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public String getNameAndTitle(Faction faction)
|
|
|
|
{
|
|
|
|
return this.getNameAndTitle(this.getColorTo(faction).toString());
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:29:58 +02:00
|
|
|
public String getNameAndTitle(MPlayer mplayer)
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
return this.getNameAndTitle(this.getColorTo(mplayer).toString());
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// RELATION AND RELATION COLORS
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public String describeTo(RelationParticipator observer, boolean ucfirst)
|
|
|
|
{
|
|
|
|
return RelationUtil.describeThatToMe(this, observer, ucfirst);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public String describeTo(RelationParticipator observer)
|
|
|
|
{
|
|
|
|
return RelationUtil.describeThatToMe(this, observer);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public Rel getRelationTo(RelationParticipator observer)
|
|
|
|
{
|
|
|
|
return RelationUtil.getRelationOfThatToMe(this, observer);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful)
|
|
|
|
{
|
|
|
|
return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
@Override
|
|
|
|
public ChatColor getColorTo(RelationParticipator observer)
|
|
|
|
{
|
|
|
|
return RelationUtil.getColorOfThatToMe(this, observer);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// HEALTH
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void heal(int amnt)
|
|
|
|
{
|
|
|
|
Player player = this.getPlayer();
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
player.setHealth(player.getHealth() + amnt);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// TERRITORY
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public boolean isInOwnTerritory()
|
|
|
|
{
|
2016-05-13 12:32:05 +02:00
|
|
|
PS ps = MixinSenderPs.get().getSenderPs(this.getId());
|
2014-09-17 13:17:33 +02:00
|
|
|
if (ps == null) return false;
|
|
|
|
return BoardColl.get().getFactionAt(ps) == this.getFaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInEnemyTerritory()
|
|
|
|
{
|
2016-05-13 12:32:05 +02:00
|
|
|
PS ps = MixinSenderPs.get().getSenderPs(this.getId());
|
2014-09-17 13:17:33 +02:00
|
|
|
if (ps == null) return false;
|
|
|
|
return BoardColl.get().getFactionAt(ps).getRelationTo(this) == Rel.ENEMY;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// INACTIVITY TIMEOUT
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
public long getRemovePlayerMillis(boolean async)
|
|
|
|
{
|
|
|
|
EventFactionsRemovePlayerMillis event = new EventFactionsRemovePlayerMillis(async, this);
|
|
|
|
event.run();
|
|
|
|
return event.getMillis();
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
public boolean considerRemovePlayerMillis(boolean async)
|
|
|
|
{
|
|
|
|
// This may or may not be required.
|
2016-08-03 12:51:06 +02:00
|
|
|
// Some users have been reporting a loop issue with the same player
|
|
|
|
// detaching over and over again.
|
2014-10-06 13:08:34 +02:00
|
|
|
// Maybe skipping ahead if the player is detached will solve the issue.
|
|
|
|
if (this.detached()) return false;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Get the last activity millis.
|
2014-11-21 09:59:04 +01:00
|
|
|
long lastActivityMillis = this.getLastActivityMillis();
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Consider
|
|
|
|
long toleranceMillis = this.getRemovePlayerMillis(async);
|
|
|
|
if (System.currentTimeMillis() - lastActivityMillis <= toleranceMillis) return false;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Inform
|
|
|
|
if (MConf.get().logFactionLeave || MConf.get().logFactionKick)
|
|
|
|
{
|
|
|
|
Factions.get().log("Player " + this.getName() + " was auto-removed due to inactivity.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Promote a new leader if required.
|
|
|
|
if (this.getRole() == Rel.LEADER)
|
|
|
|
{
|
|
|
|
Faction faction = this.getFaction();
|
|
|
|
if (faction != null)
|
|
|
|
{
|
|
|
|
this.getFaction().promoteNewLeader();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.leave();
|
|
|
|
this.detach();
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// ACTIONS
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
public void leave()
|
|
|
|
{
|
|
|
|
Faction myFaction = this.getFaction();
|
|
|
|
|
2014-10-07 12:30:44 +02:00
|
|
|
boolean permanent = myFaction.getFlag(MFlag.getFlagPermanent());
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:29:58 +02:00
|
|
|
if (myFaction.getMPlayers().size() > 1)
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
|
|
|
if (!permanent && this.getRole() == Rel.LEADER)
|
|
|
|
{
|
|
|
|
msg("<b>You must give the leader role to someone else first.");
|
|
|
|
return;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
if (!MConf.get().canLeaveWithNegativePower && this.getPower() < 0)
|
|
|
|
{
|
|
|
|
msg("<b>You cannot leave until your power is positive.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Event
|
|
|
|
EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(this.getSender(), this, myFaction, MembershipChangeReason.LEAVE);
|
|
|
|
membershipChangeEvent.run();
|
|
|
|
if (membershipChangeEvent.isCancelled()) return;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
if (myFaction.isNormal())
|
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
for (MPlayer mplayer : myFaction.getMPlayersWhereOnline(true))
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
mplayer.msg("%s<i> left %s<i>.", this.describeTo(mplayer, true), myFaction.describeTo(mplayer));
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (MConf.get().logFactionLeave)
|
|
|
|
{
|
2016-08-03 12:51:06 +02:00
|
|
|
Factions.get().log(this.getName() + " left the faction: " + myFaction.getName());
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
this.resetFactionData();
|
|
|
|
|
2014-09-17 13:29:58 +02:00
|
|
|
if (myFaction.isNormal() && !permanent && myFaction.getMPlayers().isEmpty())
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-21 07:48:42 +02:00
|
|
|
EventFactionsDisband eventFactionsDisband = new EventFactionsDisband(this.getSender(), myFaction);
|
|
|
|
eventFactionsDisband.run();
|
2016-08-03 12:51:06 +02:00
|
|
|
if (!eventFactionsDisband.isCancelled())
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-21 07:48:42 +02:00
|
|
|
// Remove this faction
|
|
|
|
this.msg("%s <i>was disbanded since you were the last player.", myFaction.describeTo(this, true));
|
|
|
|
if (MConf.get().logFactionDisband)
|
|
|
|
{
|
2016-08-03 12:51:06 +02:00
|
|
|
Factions.get().log("The faction " + myFaction.getName() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving.");
|
2014-10-21 07:48:42 +02:00
|
|
|
}
|
|
|
|
myFaction.detach();
|
2016-08-03 12:51:06 +02:00
|
|
|
}
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
// NEW
|
|
|
|
public boolean tryClaim(Faction newFaction, Collection<PS> pss)
|
2014-10-14 08:56:07 +02:00
|
|
|
{
|
|
|
|
return this.tryClaim(newFaction, pss, null, null);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-14 08:56:07 +02:00
|
|
|
public boolean tryClaim(Faction newFaction, Collection<PS> pss, String formatOne, String formatMany)
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-13 11:42:40 +02:00
|
|
|
// Args
|
2014-10-14 08:56:07 +02:00
|
|
|
if (formatOne == null) formatOne = "<h>%s<i> %s <h>%d <i>chunk %s<i>.";
|
|
|
|
if (formatMany == null) formatMany = "<h>%s<i> %s <h>%d <i>chunks near %s<i>.";
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
if (newFaction == null) throw new NullPointerException("newFaction");
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
if (pss == null) throw new NullPointerException("pss");
|
|
|
|
final Set<PS> chunks = PS.getDistinctChunks(pss);
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-07 17:08:40 +02:00
|
|
|
// NoChange
|
2014-10-13 11:42:40 +02:00
|
|
|
// We clean the chunks further by removing what does not change.
|
2016-08-03 12:51:06 +02:00
|
|
|
// This is also very suggested cleaning of EventFactionsChunksChange input.
|
2014-10-13 11:42:40 +02:00
|
|
|
Iterator<PS> iter = chunks.iterator();
|
|
|
|
while (iter.hasNext())
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-13 11:42:40 +02:00
|
|
|
PS chunk = iter.next();
|
|
|
|
Faction oldFaction = BoardColl.get().getFactionAt(chunk);
|
|
|
|
if (newFaction == oldFaction) iter.remove();
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2014-10-13 11:42:40 +02:00
|
|
|
if (chunks.isEmpty())
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-13 11:42:40 +02:00
|
|
|
msg("%s<i> already owns this land.", newFaction.describeTo(this, true));
|
|
|
|
return true;
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Event
|
2014-10-13 11:42:40 +02:00
|
|
|
// NOTE: We listen to this event ourselves at LOW.
|
|
|
|
// NOTE: That is where we apply the standard checks.
|
2014-12-10 10:27:56 +01:00
|
|
|
CommandSender sender = this.getSender();
|
|
|
|
if (sender == null)
|
|
|
|
{
|
2015-08-21 14:58:04 +02:00
|
|
|
msg("<b>ERROR: Your \"CommandSender Link\" has been severed.");
|
|
|
|
msg("<b>It's likely that you are using Cauldron.");
|
|
|
|
msg("<b>We do currently not support Cauldron.");
|
|
|
|
msg("<b>We would love to but lack time to develop support ourselves.");
|
|
|
|
msg("<g>Do you know how to code? Please send us a pull request <3, sorry.");
|
2014-12-10 10:27:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EventFactionsChunksChange event = new EventFactionsChunksChange(sender, chunks, newFaction);
|
2014-09-17 13:17:33 +02:00
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return false;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Apply
|
2014-10-13 11:42:40 +02:00
|
|
|
for (PS chunk : chunks)
|
|
|
|
{
|
|
|
|
BoardColl.get().setFactionAt(chunk, newFaction);
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// Inform
|
2014-10-13 11:42:40 +02:00
|
|
|
for (Entry<Faction, Set<PS>> entry : event.getOldFactionChunks().entrySet())
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-13 11:42:40 +02:00
|
|
|
final Faction oldFaction = entry.getKey();
|
|
|
|
final Set<PS> oldChunks = entry.getValue();
|
|
|
|
final PS oldChunk = oldChunks.iterator().next();
|
|
|
|
final Set<MPlayer> informees = getClaimInformees(this, oldFaction, newFaction);
|
|
|
|
final EventFactionsChunkChangeType type = EventFactionsChunkChangeType.get(oldFaction, newFaction, this.getFaction());
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
String chunkString = oldChunk.toString(PSFormatHumanSpace.get());
|
|
|
|
String typeString = type.past;
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
for (MPlayer informee : informees)
|
|
|
|
{
|
2014-10-14 08:56:07 +02:00
|
|
|
informee.msg((oldChunks.size() == 1 ? formatOne : formatMany), this.describeTo(informee, true), typeString, oldChunks.size(), chunkString);
|
2014-10-13 11:42:40 +02:00
|
|
|
informee.msg(" <h>%s<i> --> <h>%s", oldFaction.describeTo(informee, true), newFaction.describeTo(informee, true));
|
|
|
|
}
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
// Success
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// UTIL
|
|
|
|
// -------------------------------------------- //
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
public static Set<MPlayer> getClaimInformees(MPlayer msender, Faction... factions)
|
|
|
|
{
|
2017-03-24 14:03:29 +01:00
|
|
|
Set<MPlayer> ret = new HashSet<>();
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-22 07:50:30 +02:00
|
|
|
if (msender != null) ret.add(msender);
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
for (Faction faction : factions)
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-22 07:50:30 +02:00
|
|
|
if (faction == null) continue;
|
|
|
|
if (faction.isNone()) continue;
|
|
|
|
ret.addAll(faction.getMPlayers());
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
if (MConf.get().logLandClaims)
|
|
|
|
{
|
2014-10-13 11:42:40 +02:00
|
|
|
ret.add(MPlayer.get(IdUtil.getConsole()));
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
return ret;
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
2016-08-03 12:51:06 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|