2014-08-20 03:16:28 +02:00
|
|
|
package nautilus.game.arcade.stats;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
|
|
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
|
|
|
|
import nautilus.game.arcade.game.Game;
|
|
|
|
|
|
|
|
public class FastKillsStatTracker extends StatTracker<Game>
|
|
|
|
{
|
|
|
|
private final Map<UUID, Integer> _killCount = new HashMap<>();
|
|
|
|
private final Map<UUID, Long> _lastKillTime = new HashMap<>();
|
|
|
|
|
|
|
|
private final int _requiredKillCount;
|
2014-08-22 23:20:02 +02:00
|
|
|
private final String _stat;
|
2014-08-20 03:16:28 +02:00
|
|
|
private final int _timeBetweenKills;
|
|
|
|
|
2014-08-22 23:20:02 +02:00
|
|
|
public FastKillsStatTracker(Game game, int requiredKillCount, int timeBetweenKills, String stat)
|
2014-08-20 03:16:28 +02:00
|
|
|
{
|
|
|
|
super(game);
|
|
|
|
|
|
|
|
_requiredKillCount = requiredKillCount;
|
2014-08-22 23:20:02 +02:00
|
|
|
_stat = stat;
|
2014-08-20 03:16:28 +02:00
|
|
|
_timeBetweenKills = timeBetweenKills * 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
|
|
|
public void onCombatDeath(CombatDeathEvent event)
|
|
|
|
{
|
2014-08-25 22:27:02 +02:00
|
|
|
if (getGame().GetState() != Game.GameState.Live)
|
|
|
|
return;
|
|
|
|
|
2014-08-20 03:16:28 +02:00
|
|
|
if (event.GetLog().GetKiller() == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!event.GetLog().GetKiller().IsPlayer())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
|
|
|
|
if (killer == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetLog().GetPlayer() == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!event.GetLog().GetPlayer().IsPlayer())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player player = UtilPlayer.searchExact(event.GetLog().GetPlayer().GetName());
|
|
|
|
if (player == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Long lastTime = _lastKillTime.get(killer.getUniqueId());
|
|
|
|
|
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
|
|
|
|
Integer killCount;
|
|
|
|
if (lastTime == null || now - lastTime > getTimeBetweenKills())
|
|
|
|
killCount = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
killCount = _killCount.get(killer.getUniqueId());
|
|
|
|
if (killCount == null)
|
|
|
|
killCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
killCount++;
|
|
|
|
|
|
|
|
_killCount.put(killer.getUniqueId(), killCount);
|
|
|
|
_lastKillTime.put(killer.getUniqueId(), now);
|
|
|
|
|
|
|
|
_killCount.remove(player.getUniqueId());
|
|
|
|
_lastKillTime.remove(player.getUniqueId());
|
|
|
|
|
|
|
|
if (killCount >= getRequiredKillCount())
|
2014-08-26 22:30:55 +02:00
|
|
|
addStat(killer, getStat(), 1, true, false);
|
2014-08-20 03:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getRequiredKillCount()
|
|
|
|
{
|
|
|
|
return _requiredKillCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTimeBetweenKills()
|
|
|
|
{
|
|
|
|
return _timeBetweenKills;
|
|
|
|
}
|
2014-08-22 23:20:02 +02:00
|
|
|
|
|
|
|
public String getStat()
|
|
|
|
{
|
|
|
|
return _stat;
|
|
|
|
}
|
2014-08-20 03:16:28 +02:00
|
|
|
}
|