64 lines
1.5 KiB
Java
64 lines
1.5 KiB
Java
|
package nautilus.game.arcade.stats;
|
||
|
|
||
|
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 KillReasonStatTracker extends StatTracker<Game>
|
||
|
{
|
||
|
private final String _reason;
|
||
|
private final String _statName;
|
||
|
|
||
|
public KillReasonStatTracker(Game game, String reason, String statName)
|
||
|
{
|
||
|
super(game);
|
||
|
|
||
|
_reason = reason;
|
||
|
_statName = statName;
|
||
|
}
|
||
|
|
||
|
@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;
|
||
|
|
||
|
if (event.GetLog().GetLastDamager() != null && event.GetLog().GetLastDamager().GetReason() != null && event.GetLog().GetLastDamager().GetReason().contains(getReason()))
|
||
|
addStat(killer, getStatName(), 1, false, false);
|
||
|
}
|
||
|
|
||
|
public String getStatName()
|
||
|
{
|
||
|
return _statName;
|
||
|
}
|
||
|
|
||
|
public String getReason()
|
||
|
{
|
||
|
return _reason;
|
||
|
}
|
||
|
}
|