Add faction and player kills / deaths stats.

This commit is contained in:
drtshock 2015-08-06 16:53:00 -05:00
parent bf0382ca76
commit 3b8bc19460
7 changed files with 86 additions and 45 deletions

View File

@ -25,6 +25,10 @@ import java.util.List;
*/ */
public interface FPlayer extends EconomyParticipator { public interface FPlayer extends EconomyParticipator {
public void login();
public void logout();
public Faction getFaction(); public Faction getFaction();
public String getFactionId(); public String getFactionId();
@ -133,6 +137,11 @@ public interface FPlayer extends EconomyParticipator {
public String getChatTag(FPlayer fplayer); public String getChatTag(FPlayer fplayer);
public int getKills();
public int getDeaths();
// ------------------------------- // -------------------------------
// Relation and relation colors // Relation and relation colors
// ------------------------------- // -------------------------------

View File

@ -119,6 +119,10 @@ public interface Faction extends EconomyParticipator {
public void setLastDeath(long time); public void setLastDeath(long time);
public int getKills();
public int getDeaths();
// ------------------------------- // -------------------------------
// Relation and relation colors // Relation and relation colors
// ------------------------------- // -------------------------------

View File

@ -59,6 +59,8 @@ public class FactionsPlayerListener implements Listener {
// Store player's current FLocation and notify them where they are // Store player's current FLocation and notify them where they are
me.setLastStoodAt(new FLocation(player.getLocation())); me.setLastStoodAt(new FLocation(player.getLocation()));
me.login(); // set kills / deaths
// Check for Faction announcements. Let's delay this so they actually see it. // Check for Faction announcements. Let's delay this so they actually see it.
Bukkit.getScheduler().runTaskLater(P.p, new Runnable() { Bukkit.getScheduler().runTaskLater(P.p, new Runnable() {
@Override @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 // and update their last login time to point to when the logged off, for auto-remove routine
me.setLastLoginTime(System.currentTimeMillis()); me.setLastLoginTime(System.currentTimeMillis());
me.logout(); // cache kills / deaths
// if player is waiting for fstuck teleport but leaves, remove // if player is waiting for fstuck teleport but leaves, remove
if (P.p.getStuckMap().containsKey(me.getPlayer().getUniqueId())) { if (P.p.getStuckMap().containsKey(me.getPlayer().getUniqueId())) {
FPlayers.getInstance().getByPlayer(me.getPlayer()).msg(TL.COMMAND_STUCK_CANCELLED); FPlayers.getInstance().getByPlayer(me.getPlayer()).msg(TL.COMMAND_STUCK_CANCELLED);

View File

@ -17,10 +17,7 @@ import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashSet; import java.util.HashSet;
@ -41,63 +38,43 @@ import java.util.UUID;
*/ */
public abstract class MemoryFPlayer implements FPlayer { public abstract class MemoryFPlayer implements FPlayer {
// FIELD: factionId
protected String factionId; protected String factionId;
// FIELD: role
protected Role role; protected Role role;
// FIELD: title
protected String title; protected String title;
// FIELD: power
protected double power; protected double power;
// FIELD: powerBoost
// special increase/decrease to min and max power for this player
protected double powerBoost; protected double powerBoost;
// FIELD: lastPowerUpdateTime
protected long lastPowerUpdateTime; protected long lastPowerUpdateTime;
// FIELD: lastLoginTime
protected long lastLoginTime; protected long lastLoginTime;
// FIELD: chatMode
protected ChatMode chatMode; protected ChatMode chatMode;
// FIELD: ignoreAllianceChat
protected boolean ignoreAllianceChat = false; protected boolean ignoreAllianceChat = false;
protected String id; protected String id;
protected String name; protected String name;
protected boolean monitorJoins; 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 spyingChat = false;
protected boolean showScoreboard = true; protected boolean showScoreboard = true;
protected WarmUpUtil.Warmup warmup; protected WarmUpUtil.Warmup warmup;
protected int warmupTask; 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() { public Faction getFaction() {
if (this.factionId == null) { if (this.factionId == null) {
@ -244,6 +221,8 @@ public abstract class MemoryFPlayer implements FPlayer {
this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0; this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0;
this.powerBoost = 0.0; this.powerBoost = 0.0;
this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", false); 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)) { if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.getInstance().isValidFactionId(Conf.newPlayerStartingFactionID)) {
this.factionId = Conf.newPlayerStartingFactionID; this.factionId = Conf.newPlayerStartingFactionID;
@ -268,6 +247,8 @@ public abstract class MemoryFPlayer implements FPlayer {
this.lastStoodAt = other.lastStoodAt; this.lastStoodAt = other.lastStoodAt;
this.isAdminBypassing = other.isAdminBypassing; this.isAdminBypassing = other.isAdminBypassing;
this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", true); this.showScoreboard = P.p.getConfig().getBoolean("scoreboard.default-enabled", true);
this.kills = other.kills;
this.deaths = other.deaths;
} }
public void resetFactionData(boolean doSpoutUpdate) { public void resetFactionData(boolean doSpoutUpdate) {
@ -416,6 +397,15 @@ public abstract class MemoryFPlayer implements FPlayer {
return this.hasFaction() ? this.getColorTo(fplayer) + getChatTag() : ""; 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 // Relation and relation colors
// ------------------------------- // -------------------------------

View File

@ -277,6 +277,24 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return this.lastDeath; 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 // Construct
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -33,6 +33,8 @@ public enum TagReplacer {
PLAYER_BALANCE(TagType.PLAYER, "{balance}"), PLAYER_BALANCE(TagType.PLAYER, "{balance}"),
PLAYER_POWER(TagType.PLAYER, "{player-power}"), PLAYER_POWER(TagType.PLAYER, "{player-power}"),
PLAYER_MAXPOWER(TagType.PLAYER, "{player-maxpower}"), 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 * Faction variables, require at least a player
@ -65,6 +67,8 @@ public enum TagReplacer {
ONLINE_COUNT(TagType.FACTION, "{online}"), ONLINE_COUNT(TagType.FACTION, "{online}"),
OFFLINE_COUNT(TagType.FACTION, "{offline}"), OFFLINE_COUNT(TagType.FACTION, "{offline}"),
FACTION_SIZE(TagType.FACTION, "{members}"), FACTION_SIZE(TagType.FACTION, "{members}"),
FACTION_KILLS(TagType.FACTION, "{faction-kills}"),
FACTION_DEATHS(TagType.FACTION, "{faction-deaths}"),
/** /**
* General variables, require no faction or player * General variables, require no faction or player
@ -150,6 +154,10 @@ public enum TagReplacer {
return String.valueOf(fp.getPowerRounded()); return String.valueOf(fp.getPowerRounded());
case PLAYER_MAXPOWER: case PLAYER_MAXPOWER:
return String.valueOf(fp.getPowerMaxRounded()); return String.valueOf(fp.getPowerMaxRounded());
case PLAYER_KILLS:
return String.valueOf(fp.getKills());
case PLAYER_DEATHS:
return String.valueOf(fp.getDeaths());
} }
} }
switch (this) { switch (this) {
@ -209,6 +217,10 @@ public enum TagReplacer {
return String.valueOf(fac.getFPlayers().size() - fac.getOnlinePlayers().size()); return String.valueOf(fac.getFPlayers().size() - fac.getOnlinePlayers().size());
case FACTION_SIZE: case FACTION_SIZE:
return String.valueOf(fac.getFPlayers().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; return null;
} }

View File

@ -314,6 +314,8 @@ help:
# - {name} : Players name # - {name} : Players name
# - {lastSeen} : Last time player was seen (if offline), or just 'Online' # - {lastSeen} : Last time player was seen (if offline), or just 'Online'
# - {balance} : Players balance # - {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 # Faction variables. Can be used in tooltips.list, scoreboards, or /f show
# - {header} : Default factions header (ex. /f show) # - {header} : Default factions header (ex. /f show)
# - {faction} : Factions tag (if none, uses lang.yml for factionless name) # - {faction} : Factions tag (if none, uses lang.yml for factionless name)
@ -335,6 +337,8 @@ help:
# - {members} : # of faction members (includes offline) # - {members} : # of faction members (includes offline)
# - {faction-balance} : Faction bank balance # - {faction-balance} : Faction bank balance
# - {world}, {x}, {y}, {z} : Faction home variables. You don't need to use them all. # - {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. # General variables. Can be used anywhere.
# - {total-online} : Total # of players on the server # - {total-online} : Total # of players on the server
# - {max-warps} : Max # of warps a faction can set # - {max-warps} : Max # of warps a faction can set