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

61 lines
1.6 KiB
Java
Raw Normal View History

2014-10-11 03:49:03 +02:00
package nautilus.game.arcade.stats;
import org.bukkit.entity.EntityType;
2014-10-11 03:49:03 +02:00
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
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 KillEntityStatTracker extends StatTracker<Game>
2014-10-11 03:49:03 +02:00
{
private final String _statName;
private EntityType _entityType;
2014-10-11 03:49:03 +02:00
public KillEntityStatTracker(Game game, String statName, EntityType entityType)
2014-10-11 03:49:03 +02:00
{
super(game);
_statName = statName;
setEntityType(entityType);
2014-10-11 03:49:03 +02:00
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event)
{
if (event.getEntity().getType() != getEntityType())
2014-10-11 03:49:03 +02:00
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;
}
public EntityType getEntityType()
{
return _entityType;
}
public void setEntityType(EntityType entityType)
{
_entityType = entityType;
}
2014-10-11 03:49:03 +02:00
}