From d0368a19d890d8a0b49d833fb0b795021d449875 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 27 Jun 2015 12:38:04 +1000 Subject: [PATCH] Players who quit early do not get full game worth of EXP. --- .../arcade/stats/ExperienceStatTracker.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/ExperienceStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/ExperienceStatTracker.java index 1280ce912..515c8aece 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/ExperienceStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/ExperienceStatTracker.java @@ -5,7 +5,9 @@ import java.util.List; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerQuitEvent; +import mineplex.core.common.util.NautHashMap; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GemData; @@ -14,6 +16,8 @@ public class ExperienceStatTracker extends StatTracker { private long _startTime = -1; + private NautHashMap _playerQuitTime = new NautHashMap(); + public ExperienceStatTracker(Game game) { super(game); @@ -26,6 +30,12 @@ public class ExperienceStatTracker extends StatTracker _startTime = System.currentTimeMillis(); } + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + _playerQuitTime.put(event.getPlayer().getName(), System.currentTimeMillis()); + } + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onGameEnd(GameStateChangeEvent event) { @@ -57,7 +67,15 @@ public class ExperienceStatTracker extends StatTracker gemExp = Math.min(gemExp, 250) * 6; //Game Time = 1 Exp per 3 Seconds - double timeExp = (System.currentTimeMillis() - _startTime)/1500d; + long time = System.currentTimeMillis(); + //Exp Until They Quit + if (!player.isOnline() && _playerQuitTime.containsKey(player.getName())) + time = _playerQuitTime.get(player.getName()); + //No Time Exp + else + time = _startTime; + + double timeExp = (time - _startTime)/1500d; //Mult double mult = 1;