Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/KillAllOpposingStatTracker.java

95 lines
2.1 KiB
Java
Raw Normal View History

2014-08-18 22:41:16 +02:00
package nautilus.game.arcade.stats;
import mineplex.core.common.util.*;
import mineplex.minecraft.game.core.combat.event.*;
import nautilus.game.arcade.events.*;
import nautilus.game.arcade.game.*;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import java.util.*;
public class KillAllOpposingStatTracker extends StatTracker<TeamGame>
{
private final Map<UUID, Set<UUID>> _kills = new HashMap<>();
public KillAllOpposingStatTracker(TeamGame game)
{
super(game);
}
@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-18 22:41:16 +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 killed = UtilPlayer.searchExact(event.GetLog().GetPlayer().GetName());
if (killed == null)
return;
Set<UUID> kills = _kills.get(killer.getUniqueId());
if (kills == null)
{
kills = new HashSet<>();
_kills.put(killer.getUniqueId(), kills);
}
kills.add(killed.getUniqueId());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onGameStateChange(GameStateChangeEvent event)
{
if (event.GetState() == Game.GameState.End)
{
for (GameTeam team : getGame().GetTeamList())
{
for (Player player : team.GetPlayers(false))
{
Set<UUID> kills = _kills.get(player.getUniqueId());
if (kills == null)
continue;
for (GameTeam otherTeam : getGame().GetTeamList())
{
if (otherTeam == team)
continue;
boolean killedAll = true;
for (Player otherPlayer : otherTeam.GetPlayers(true))
{
if (!kills.contains(otherPlayer.getUniqueId()))
{
killedAll = false;
break;
}
}
if (killedAll)
getGame().AddStat(player, "Ace", 1, true, false);
}
}
}
}
}
}