Added GamesPlayed and TimeInGame stats
This commit is contained in:
parent
1bf5debc06
commit
70fd8835ac
@ -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() + "...");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user