diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index da2e6d88..3f2ddf5e 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -25,6 +25,10 @@ import java.util.List; */ public interface FPlayer extends EconomyParticipator { + public void login(); + + public void logout(); + public Faction getFaction(); public String getFactionId(); @@ -133,6 +137,11 @@ public interface FPlayer extends EconomyParticipator { public String getChatTag(FPlayer fplayer); + public int getKills(); + + public int getDeaths(); + + // ------------------------------- // Relation and relation colors // ------------------------------- diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index b1327ded..07ad3804 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -119,6 +119,10 @@ public interface Faction extends EconomyParticipator { public void setLastDeath(long time); + public int getKills(); + + public int getDeaths(); + // ------------------------------- // Relation and relation colors // ------------------------------- diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index a0e4011c..0cc0da32 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -59,6 +59,8 @@ public class FactionsPlayerListener implements Listener { // Store player's current FLocation and notify them where they are me.setLastStoodAt(new FLocation(player.getLocation())); + me.login(); // set kills / deaths + // Check for Faction announcements. Let's delay this so they actually see it. Bukkit.getScheduler().runTaskLater(P.p, new Runnable() { @Override @@ -94,6 +96,8 @@ public class FactionsPlayerListener implements Listener { // and update their last login time to point to when the logged off, for auto-remove routine me.setLastLoginTime(System.currentTimeMillis()); + me.logout(); // cache kills / deaths + // if player is waiting for fstuck teleport but leaves, remove if (P.p.getStuckMap().containsKey(me.getPlayer().getUniqueId())) { FPlayers.getInstance().getByPlayer(me.getPlayer()).msg(TL.COMMAND_STUCK_CANCELLED); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index 3742c61e..4e1ec1b3 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -17,10 +17,7 @@ import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.zcore.util.TL; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; +import org.bukkit.*; import org.bukkit.entity.Player; import java.util.HashSet; @@ -41,63 +38,43 @@ import java.util.UUID; */ public abstract class MemoryFPlayer implements FPlayer { - // FIELD: factionId + protected String factionId; - - // FIELD: role protected Role role; - // FIELD: title protected String title; - - // FIELD: power protected double power; - - // FIELD: powerBoost - // special increase/decrease to min and max power for this player protected double powerBoost; - - // FIELD: lastPowerUpdateTime protected long lastPowerUpdateTime; - - // FIELD: lastLoginTime protected long lastLoginTime; - - // FIELD: chatMode protected ChatMode chatMode; - - // FIELD: ignoreAllianceChat protected boolean ignoreAllianceChat = false; - protected String id; protected String name; - protected boolean monitorJoins; - - //private transient String playerName; - protected transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked? - - // FIELD: mapAutoUpdating - protected transient boolean mapAutoUpdating; - - // FIELD: autoClaimEnabled - protected transient Faction autoClaimFor; - - // FIELD: autoSafeZoneEnabled - protected transient boolean autoSafeZoneEnabled; - - // FIELD: autoWarZoneEnabled - protected transient boolean autoWarZoneEnabled; - - protected transient boolean isAdminBypassing = false; - - // FIELD: loginPvpDisabled - protected transient boolean loginPvpDisabled; - protected boolean spyingChat = false; protected boolean showScoreboard = true; - protected WarmUpUtil.Warmup warmup; protected int warmupTask; + protected boolean isAdminBypassing = false; + protected int kills, deaths; + + protected transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked? + protected transient boolean mapAutoUpdating; + protected transient Faction autoClaimFor; + protected transient boolean autoSafeZoneEnabled; + protected transient boolean autoWarZoneEnabled; + protected transient boolean loginPvpDisabled; + + + public void login() { + this.kills = getPlayer().getStatistic(Statistic.PLAYER_KILLS); + this.deaths = getPlayer().getStatistic(Statistic.DEATHS); + } + + public void logout() { + this.kills = getPlayer().getStatistic(Statistic.PLAYER_KILLS); + this.deaths = getPlayer().getStatistic(Statistic.DEATHS); + } public Faction getFaction() { if (this.factionId == null) { @@ -244,6 +221,8 @@ public abstract class MemoryFPlayer implements FPlayer { this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0; this.powerBoost = 0.0; this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", false); + this.kills = 0; + this.deaths = 0; if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.getInstance().isValidFactionId(Conf.newPlayerStartingFactionID)) { this.factionId = Conf.newPlayerStartingFactionID; @@ -268,6 +247,8 @@ public abstract class MemoryFPlayer implements FPlayer { this.lastStoodAt = other.lastStoodAt; this.isAdminBypassing = other.isAdminBypassing; this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", true); + this.kills = other.kills; + this.deaths = other.deaths; } public void resetFactionData(boolean doSpoutUpdate) { @@ -416,6 +397,15 @@ public abstract class MemoryFPlayer implements FPlayer { return this.hasFaction() ? this.getColorTo(fplayer) + getChatTag() : ""; } + public int getKills() { + return isOnline() ? getPlayer().getStatistic(Statistic.PLAYER_KILLS) : this.kills; + } + + public int getDeaths() { + return isOnline() ? getPlayer().getStatistic(Statistic.DEATHS) : this.deaths; + + } + // ------------------------------- // Relation and relation colors // ------------------------------- diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index 8ca5448e..d6da8636 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -277,6 +277,24 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { return this.lastDeath; } + public int getKills() { + int kills = 0; + for (FPlayer fp : getFPlayers()) { + kills += fp.getKills(); + } + + return kills; + } + + public int getDeaths() { + int deaths = 0; + for (FPlayer fp : getFPlayers()) { + deaths += fp.getDeaths(); + } + + return deaths; + } + // -------------------------------------------- // // Construct // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java b/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java index 0c18c8f0..59d4db0c 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java @@ -33,6 +33,8 @@ public enum TagReplacer { PLAYER_BALANCE(TagType.PLAYER, "{balance}"), PLAYER_POWER(TagType.PLAYER, "{player-power}"), PLAYER_MAXPOWER(TagType.PLAYER, "{player-maxpower}"), + PLAYER_KILLS(TagType.PLAYER, "{player-kills}"), + PLAYER_DEATHS(TagType.PLAYER, "{player-deaths}"), /** * Faction variables, require at least a player @@ -65,6 +67,8 @@ public enum TagReplacer { ONLINE_COUNT(TagType.FACTION, "{online}"), OFFLINE_COUNT(TagType.FACTION, "{offline}"), FACTION_SIZE(TagType.FACTION, "{members}"), + FACTION_KILLS(TagType.FACTION, "{faction-kills}"), + FACTION_DEATHS(TagType.FACTION, "{faction-deaths}"), /** * General variables, require no faction or player @@ -150,6 +154,10 @@ public enum TagReplacer { return String.valueOf(fp.getPowerRounded()); case PLAYER_MAXPOWER: return String.valueOf(fp.getPowerMaxRounded()); + case PLAYER_KILLS: + return String.valueOf(fp.getKills()); + case PLAYER_DEATHS: + return String.valueOf(fp.getDeaths()); } } switch (this) { @@ -209,6 +217,10 @@ public enum TagReplacer { return String.valueOf(fac.getFPlayers().size() - fac.getOnlinePlayers().size()); case FACTION_SIZE: return String.valueOf(fac.getFPlayers().size()); + case FACTION_KILLS: + return String.valueOf(fac.getKills()); + case FACTION_DEATHS: + return String.valueOf(fac.getDeaths()); } return null; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 47952b36..ed7e78ab 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -314,6 +314,8 @@ help: # - {name} : Players name # - {lastSeen} : Last time player was seen (if offline), or just 'Online' # - {balance} : Players balance +# - {player-kills} : # of kills the player has +# - {player-deaths}: # of deaths the player has # Faction variables. Can be used in tooltips.list, scoreboards, or /f show # - {header} : Default factions header (ex. /f show) # - {faction} : Factions tag (if none, uses lang.yml for factionless name) @@ -335,6 +337,8 @@ help: # - {members} : # of faction members (includes offline) # - {faction-balance} : Faction bank balance # - {world}, {x}, {y}, {z} : Faction home variables. You don't need to use them all. +# - {faction-kills} : # of kills the faction has +# - {faction-deaths}: # of deaths the faction has # General variables. Can be used anywhere. # - {total-online} : Total # of players on the server # - {max-warps} : Max # of warps a faction can set