49 lines
1.4 KiB
Java
49 lines
1.4 KiB
Java
|
package nautilus.game.arcade.stats;
|
||
|
|
||
|
import org.bukkit.entity.Player;
|
||
|
import org.bukkit.entity.Projectile;
|
||
|
import org.bukkit.entity.Villager;
|
||
|
import org.bukkit.event.EventHandler;
|
||
|
import org.bukkit.event.EventPriority;
|
||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||
|
|
||
|
import nautilus.game.arcade.game.Game;
|
||
|
|
||
|
public class KillVillagersStatTracker extends StatTracker<Game>
|
||
|
{
|
||
|
private final String _statName;
|
||
|
|
||
|
public KillVillagersStatTracker(Game game, String statName)
|
||
|
{
|
||
|
super(game);
|
||
|
|
||
|
_statName = statName;
|
||
|
}
|
||
|
|
||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||
|
public void onEntityDeath(EntityDeathEvent event)
|
||
|
{
|
||
|
if (!(event.getEntity() instanceof Villager))
|
||
|
return;
|
||
|
|
||
|
if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent))
|
||
|
return;
|
||
|
|
||
|
EntityDamageByEntityEvent edbee = (EntityDamageByEntityEvent) event.getEntity();
|
||
|
Player damager = null;
|
||
|
if (edbee.getDamager() instanceof Player)
|
||
|
damager = (Player) edbee.getDamager();
|
||
|
else if (edbee.getDamager() instanceof Projectile && ((Projectile) edbee.getDamager()).getShooter() instanceof Player)
|
||
|
damager = (Player) ((Projectile) edbee.getDamager()).getShooter();
|
||
|
|
||
|
if (damager != null)
|
||
|
addStat(damager, getStatName(), 1, false, false);
|
||
|
}
|
||
|
|
||
|
public String getStatName()
|
||
|
{
|
||
|
return _statName;
|
||
|
}
|
||
|
}
|