2014-10-14 02:38:58 +02:00
|
|
|
package nautilus.game.arcade.stats;
|
|
|
|
|
2014-11-13 02:56:57 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2014-10-14 02:38:58 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2014-10-28 00:00:34 +01:00
|
|
|
import mineplex.minecraft.game.core.combat.CombatComponent;
|
|
|
|
import mineplex.minecraft.game.core.combat.CombatDamage;
|
2014-10-14 02:38:58 +02:00
|
|
|
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
|
2014-11-13 02:56:57 +01:00
|
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
2014-10-28 00:00:34 +01:00
|
|
|
import mineplex.minecraft.game.core.damage.DamageChange;
|
2014-10-14 02:38:58 +02:00
|
|
|
import nautilus.game.arcade.game.Game;
|
|
|
|
|
|
|
|
public class KillReasonStatTracker extends StatTracker<Game>
|
|
|
|
{
|
|
|
|
private final String _reason;
|
|
|
|
private final String _statName;
|
2014-11-13 02:56:57 +01:00
|
|
|
private final boolean _canBeDamagedByKilledPlayer;
|
|
|
|
private final Map<UUID, Set<UUID>> _damaged = new HashMap<>();
|
2014-10-14 02:38:58 +02:00
|
|
|
|
2014-11-13 02:56:57 +01:00
|
|
|
public KillReasonStatTracker(Game game, String reason, String statName, boolean canBeDamagedByKilledPlayer)
|
2014-10-14 02:38:58 +02:00
|
|
|
{
|
|
|
|
super(game);
|
|
|
|
|
|
|
|
_reason = reason;
|
|
|
|
_statName = statName;
|
2014-11-13 02:56:57 +01:00
|
|
|
_canBeDamagedByKilledPlayer = canBeDamagedByKilledPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
|
|
|
public void onCustomDamage(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (canBeDamagedByKilledPlayer())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (getGame().GetState() != Game.GameState.Live)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player damager = event.GetDamagerPlayer(false);
|
|
|
|
if (damager == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player damagee = event.GetDamageePlayer();
|
|
|
|
if (damagee == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Set<UUID> set = _damaged.get(damagee.getUniqueId());
|
|
|
|
if (set == null)
|
|
|
|
{
|
|
|
|
set = new HashSet<>();
|
|
|
|
_damaged.put(damagee.getUniqueId(), set);
|
|
|
|
}
|
|
|
|
set.add(damager.getUniqueId());
|
2014-10-14 02:38:58 +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 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;
|
|
|
|
|
2014-11-13 02:56:57 +01:00
|
|
|
if (!canBeDamagedByKilledPlayer())
|
|
|
|
{
|
|
|
|
Set<UUID> set = _damaged.remove(killer.getUniqueId());
|
|
|
|
if (set != null && set.contains(player.getUniqueId()))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-14 02:38:58 +02:00
|
|
|
if (event.GetLog().GetLastDamager() != null && event.GetLog().GetLastDamager().GetReason() != null && event.GetLog().GetLastDamager().GetReason().contains(getReason()))
|
|
|
|
addStat(killer, getStatName(), 1, false, false);
|
2014-10-28 00:00:34 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (CombatComponent component : event.GetLog().GetAttackers())
|
|
|
|
{
|
|
|
|
for (CombatDamage damage : component.GetDamage())
|
|
|
|
{
|
|
|
|
if (damage.getDamageMod() != null)
|
|
|
|
{
|
|
|
|
for (DamageChange mod : damage.getDamageMod())
|
|
|
|
{
|
|
|
|
if (mod.GetReason() != null && mod.GetReason().contains(getReason()))
|
|
|
|
{
|
|
|
|
addStat(killer, getStatName(), 1, false, false);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 02:38:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getStatName()
|
|
|
|
{
|
|
|
|
return _statName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getReason()
|
|
|
|
{
|
|
|
|
return _reason;
|
|
|
|
}
|
2014-11-13 02:56:57 +01:00
|
|
|
|
|
|
|
public boolean canBeDamagedByKilledPlayer()
|
|
|
|
{
|
|
|
|
return _canBeDamagedByKilledPlayer;
|
|
|
|
}
|
2014-10-14 02:38:58 +02:00
|
|
|
}
|