Added GamesPlayed and TimeInGame stats

This commit is contained in:
CoderTim 2014-09-30 02:45:20 -04:00
parent 1bf5debc06
commit 70fd8835ac
3 changed files with 70 additions and 1 deletions

View File

@ -53,11 +53,13 @@ import nautilus.game.arcade.stats.AssistsStatTracker;
import nautilus.game.arcade.stats.DamageDealtStatTracker;
import nautilus.game.arcade.stats.DamageTakenStatTracker;
import nautilus.game.arcade.stats.DeathsStatTracker;
import nautilus.game.arcade.stats.GamesPlayedStatTracker;
import nautilus.game.arcade.stats.KillsStatTracker;
import nautilus.game.arcade.stats.LoseStatTracker;
import nautilus.game.arcade.stats.StatTracker;
import nautilus.game.arcade.stats.TeamDeathsStatTracker;
import nautilus.game.arcade.stats.TeamKillsStatTracker;
import nautilus.game.arcade.stats.TimeInGameStatTracker;
import nautilus.game.arcade.stats.WinStatTracker;
import nautilus.game.arcade.world.WorldData;
@ -282,7 +284,9 @@ public abstract class Game implements Listener
new DamageDealtStatTracker(this),
new DamageTakenStatTracker(this),
new TeamDeathsStatTracker(this),
new TeamKillsStatTracker(this)
new TeamKillsStatTracker(this),
new GamesPlayedStatTracker(this),
new TimeInGameStatTracker(this)
);
System.out.println("Loading " + GetName() + "...");

View File

@ -0,0 +1,26 @@
package nautilus.game.arcade.stats;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
public class GamesPlayedStatTracker extends StatTracker<Game>
{
public GamesPlayedStatTracker(Game game)
{
super(game);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onGameStateChange(GameStateChangeEvent event)
{
if (event.GetState() == Game.GameState.Live)
{
for (Player player : getGame().GetPlayers(true))
getGame().AddStat(player, "GamesPlayed", 1, false, true);
}
}
}

View File

@ -0,0 +1,39 @@
package nautilus.game.arcade.stats;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import nautilus.game.arcade.game.Game;
public class TimeInGameStatTracker extends StatTracker<Game>
{
private final HashMap<UUID, Long> _joinTimes = new HashMap<>();
public TimeInGameStatTracker(Game game)
{
super(game);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
_joinTimes.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
Long joinTime = _joinTimes.remove(event.getPlayer().getUniqueId());
if (joinTime != null)
{
int timeInGame = (int) ((System.currentTimeMillis() - joinTime) / 1000);
getGame().AddStat(event.getPlayer(), "TimeInGame", timeInGame, false, true);
}
}
}