2014-10-11 03:49:03 +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 KillsWithinGameStatTracker extends StatTracker<Game>
|
|
|
|
{
|
2014-10-29 06:40:34 +01:00
|
|
|
private final int _necessaryKillCount;
|
2014-10-11 03:49:03 +02:00
|
|
|
private final String _statName;
|
|
|
|
private final Map<UUID, Integer> _kills = new HashMap<>();
|
|
|
|
|
2014-10-29 06:40:34 +01:00
|
|
|
public KillsWithinGameStatTracker(Game game, int necessaryKillCount, String statName)
|
2014-10-11 03:49:03 +02:00
|
|
|
{
|
|
|
|
super(game);
|
|
|
|
|
2014-10-29 06:40:34 +01:00
|
|
|
_necessaryKillCount = necessaryKillCount;
|
2014-10-11 03:49:03 +02:00
|
|
|
_statName = statName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getStatName()
|
|
|
|
{
|
|
|
|
return _statName;
|
|
|
|
}
|
|
|
|
|
2014-10-29 06:40:34 +01:00
|
|
|
public int getNecessaryKillCount()
|
2014-10-11 03:49:03 +02:00
|
|
|
{
|
2014-10-29 06:40:34 +01:00
|
|
|
return _necessaryKillCount;
|
2014-10-11 03:49:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
|
|
|
public void onCombatDeath(CombatDeathEvent event)
|
|
|
|
{
|
|
|
|
if (getGame().GetState() != Game.GameState.Live)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetLog().GetKiller() == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!event.GetLog().GetKiller().IsPlayer())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player player = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
|
|
|
|
if (player == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Integer killCount = _kills.get(player.getUniqueId());
|
|
|
|
killCount = (killCount == null ? 0 : killCount) + 1;
|
|
|
|
_kills.put(player.getUniqueId(), killCount);
|
|
|
|
|
2014-10-29 06:40:34 +01:00
|
|
|
if (killCount == getNecessaryKillCount())
|
2014-10-11 03:49:03 +02:00
|
|
|
addStat(player, getStatName(), 1, true, false);
|
|
|
|
}
|
|
|
|
}
|