Fixed TimeInGame stat not recording sometimes
This commit is contained in:
parent
17e34e2060
commit
cda9234ad3
@ -49,17 +49,7 @@ import nautilus.game.arcade.kit.KitAvailability;
|
|||||||
import nautilus.game.arcade.kit.Perk;
|
import nautilus.game.arcade.kit.Perk;
|
||||||
import nautilus.game.arcade.managers.GameLobbyManager;
|
import nautilus.game.arcade.managers.GameLobbyManager;
|
||||||
import nautilus.game.arcade.scoreboard.GameScoreboard;
|
import nautilus.game.arcade.scoreboard.GameScoreboard;
|
||||||
import nautilus.game.arcade.stats.AssistsStatTracker;
|
import nautilus.game.arcade.stats.*;
|
||||||
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.stats.WinStatTracker;
|
||||||
import nautilus.game.arcade.world.WorldData;
|
import nautilus.game.arcade.world.WorldData;
|
||||||
|
|
||||||
@ -286,8 +276,7 @@ public abstract class Game implements Listener
|
|||||||
new DamageTakenStatTracker(this),
|
new DamageTakenStatTracker(this),
|
||||||
new TeamDeathsStatTracker(this),
|
new TeamDeathsStatTracker(this),
|
||||||
new TeamKillsStatTracker(this),
|
new TeamKillsStatTracker(this),
|
||||||
new GamesPlayedStatTracker(this),
|
new GamesPlayedStatTracker(this)
|
||||||
new TimeInGameStatTracker(this)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
System.out.println("Loading " + GetName() + "...");
|
System.out.println("Loading " + GetName() + "...");
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package nautilus.game.arcade.managers;
|
package nautilus.game.arcade.managers;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import nautilus.game.arcade.ArcadeManager;
|
import nautilus.game.arcade.ArcadeManager;
|
||||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||||
@ -8,13 +11,18 @@ import nautilus.game.arcade.stats.StatTracker;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class GameStatManager implements Listener
|
public class GameStatManager implements Listener
|
||||||
{
|
{
|
||||||
ArcadeManager Manager;
|
ArcadeManager Manager;
|
||||||
|
|
||||||
|
private final HashMap<UUID, Long> _joinTimes = new HashMap<>();
|
||||||
|
|
||||||
public GameStatManager(ArcadeManager manager)
|
public GameStatManager(ArcadeManager manager)
|
||||||
{
|
{
|
||||||
Manager = manager;
|
Manager = manager;
|
||||||
@ -74,4 +82,23 @@ public class GameStatManager implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void playTimeStatJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
_joinTimes.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playTimeStatQuit(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
Long joinTime = _joinTimes.remove(event.getPlayer().getUniqueId());
|
||||||
|
|
||||||
|
if (joinTime != null)
|
||||||
|
{
|
||||||
|
int timeInGame = (int) ((System.currentTimeMillis() - joinTime) / 1000);
|
||||||
|
|
||||||
|
Manager.GetStatsManager().incrementStat(event.getPlayer(), "Global.TimeInGame", timeInGame);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
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