2014-08-21 01:20:11 +02:00
|
|
|
package nautilus.game.arcade.stats;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
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 WinFastStatTracker extends StatTracker<Game>
|
|
|
|
{
|
|
|
|
private final int _seconds;
|
2014-08-22 23:20:02 +02:00
|
|
|
private final String _stat;
|
2014-08-21 01:20:11 +02:00
|
|
|
private long _gameStartTime;
|
|
|
|
|
2014-08-22 23:20:02 +02:00
|
|
|
public WinFastStatTracker(Game game, int seconds, String stat)
|
2014-08-21 01:20:11 +02:00
|
|
|
{
|
|
|
|
super(game);
|
|
|
|
|
|
|
|
_seconds = seconds;
|
2014-08-22 23:20:02 +02:00
|
|
|
_stat = stat;
|
2014-08-21 01:20:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
|
|
|
public void onGameStateChange(GameStateChangeEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetState() == Game.GameState.Live)
|
|
|
|
_gameStartTime = System.currentTimeMillis();
|
|
|
|
else if (event.GetState() == Game.GameState.End)
|
|
|
|
{
|
|
|
|
if (System.currentTimeMillis() - _gameStartTime < _seconds * 1000)
|
|
|
|
{
|
|
|
|
List<Player> winners = getGame().getWinners();
|
|
|
|
|
|
|
|
if (winners != null)
|
|
|
|
{
|
|
|
|
for (Player winner : winners)
|
2014-08-26 22:30:55 +02:00
|
|
|
addStat(winner, getStat(), 1, true, false);
|
2014-08-21 01:20:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 23:20:02 +02:00
|
|
|
|
|
|
|
public String getStat()
|
|
|
|
{
|
|
|
|
return _stat;
|
|
|
|
}
|
2014-08-21 01:20:11 +02:00
|
|
|
}
|