use of com.laytonsmith.abstraction.blocks.MCBlockProjectileSource in project CommandHelper by EngineHub.
the class EntityEvents method parseEntityDamageEvent.
public static Map<String, Construct> parseEntityDamageEvent(MCEntityDamageEvent event, Map<String, Construct> map) {
if (event != null) {
MCEntity victim = event.getEntity();
map.put("type", new CString(victim.getType().name(), Target.UNKNOWN));
map.put("id", new CString(victim.getUniqueId().toString(), Target.UNKNOWN));
map.put("cause", new CString(event.getCause().name(), Target.UNKNOWN));
map.put("amount", new CDouble(event.getDamage(), Target.UNKNOWN));
map.put("finalamount", new CDouble(event.getFinalDamage(), Target.UNKNOWN));
map.put("world", new CString(event.getEntity().getWorld().getName(), Target.UNKNOWN));
map.put("location", ObjectGenerator.GetGenerator().location(event.getEntity().getLocation()));
if (event instanceof MCEntityDamageByEntityEvent) {
MCEntity damager = ((MCEntityDamageByEntityEvent) event).getDamager();
if (damager instanceof MCPlayer) {
map.put("damager", new CString(((MCPlayer) damager).getName(), Target.UNKNOWN));
} else {
map.put("damager", new CString(damager.getUniqueId().toString(), Target.UNKNOWN));
}
if (damager instanceof MCProjectile) {
MCProjectileSource shooter = ((MCProjectile) damager).getShooter();
if (shooter instanceof MCPlayer) {
map.put("shooter", new CString(((MCPlayer) shooter).getName(), Target.UNKNOWN));
} else if (shooter instanceof MCEntity) {
map.put("shooter", new CString(((MCEntity) shooter).getUniqueId().toString(), Target.UNKNOWN));
} else if (shooter instanceof MCBlockProjectileSource) {
map.put("shooter", ObjectGenerator.GetGenerator().location(((MCBlockProjectileSource) shooter).getBlock().getLocation()));
}
}
}
}
return map;
}
Aggregations