use of org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection in project modules-extra by CubeEngine.
the class ListenerDeath method onEntityDeath.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
// TODO handle when there is no reference on lookup of dependent actions
DeathKill killAction = this.newAction(DeathKill.class, event.getEntity().getWorld());
if (killAction != null) {
// TODO check config for killer type
killAction.setLocation(event.getEntity().getLocation());
EntityDamageEvent cause = event.getEntity().getLastDamageCause();
if (cause == null) {
killAction.otherKiller = DamageCause.CUSTOM;
} else if (cause instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) cause).getDamager();
if (damager instanceof Player) {
killAction.playerKiller = new PlayerSection((Player) damager);
} else if (damager instanceof Projectile) {
killAction.projectile = true;
if (((Projectile) damager).getShooter() instanceof Entity) {
if (((Projectile) damager).getShooter() instanceof Player) {
killAction.playerKiller = new PlayerSection((Player) ((Projectile) damager).getShooter());
} else {
killAction.entityKiller = new EntitySection((Entity) ((Projectile) damager).getShooter());
}
} else {
killAction.entityKiller = new EntitySection(damager);
}
} else {
killAction.entityKiller = new EntitySection(damager);
}
} else {
killAction.otherKiller = cause.getCause();
}
this.logAction(killAction);
}
Reference<DeathKill> reference = this.reference(killAction);
LivingEntity killed = event.getEntity();
if (killed instanceof Player) {
DeathPlayer action = this.newAction(DeathPlayer.class, killed.getWorld());
if (action != null) {
action.killer = reference;
action.setPlayer((Player) killed);
this.logAction(action);
}
if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
Reference<DeathPlayer> deathRef = this.reference(action);
for (ItemStack itemStack : event.getDrops()) {
PlayerDeathDrop dropAction = newAction(PlayerDeathDrop.class);
dropAction.item = itemStack;
dropAction.death = deathRef;
this.logAction(dropAction);
}
}
return;
}
Class<? extends EntityDeathAction> actionType;
if (killed instanceof Wither || killed instanceof EnderDragon) {
actionType = DeathBoss.class;
} else if (killed instanceof Animals) {
if (killed instanceof Tameable && ((Tameable) killed).isTamed()) {
actionType = DeathPet.class;
} else {
actionType = DeathAnimal.class;
}
} else if (killed instanceof Villager) {
actionType = DeathNpc.class;
} else if (killed instanceof Monster) {
actionType = DeathMonster.class;
} else {
actionType = DeathOther.class;
}
EntityDeathAction action = this.newAction(actionType, killed.getWorld());
if (action != null) {
action.setKilled(killed);
action.setLocation(killed.getLocation());
action.killer = reference;
this.logAction(action);
}
Reference<EntityDeathAction> deathRef = this.reference(action);
if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
for (ItemStack itemStack : event.getDrops()) {
DeathDrop dropAction = newAction(DeathDrop.class);
dropAction.item = itemStack;
dropAction.death = deathRef;
this.logAction(dropAction);
}
}
}
use of org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection in project modules-extra by CubeEngine.
the class DeathPet method setKilled.
@Override
public void setKilled(Entity entity) {
super.setKilled(entity);
Tamer owner = ((Tameable) entity).getOwner();
if (owner instanceof Player) {
this.owner = new PlayerSection((Player) owner);
}
}
Aggregations