Search in sources :

Example 1 with MCBlockProjectileSource

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;
}
Also used : MCBlockProjectileSource(com.laytonsmith.abstraction.blocks.MCBlockProjectileSource) MCEntityDamageByEntityEvent(com.laytonsmith.abstraction.events.MCEntityDamageByEntityEvent) MCEntity(com.laytonsmith.abstraction.MCEntity) MCPlayer(com.laytonsmith.abstraction.MCPlayer) CDouble(com.laytonsmith.core.constructs.CDouble) CString(com.laytonsmith.core.constructs.CString) MCProjectile(com.laytonsmith.abstraction.MCProjectile) MCProjectileSource(com.laytonsmith.abstraction.MCProjectileSource)

Aggregations

MCEntity (com.laytonsmith.abstraction.MCEntity)1 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 MCProjectile (com.laytonsmith.abstraction.MCProjectile)1 MCProjectileSource (com.laytonsmith.abstraction.MCProjectileSource)1 MCBlockProjectileSource (com.laytonsmith.abstraction.blocks.MCBlockProjectileSource)1 MCEntityDamageByEntityEvent (com.laytonsmith.abstraction.events.MCEntityDamageByEntityEvent)1 CDouble (com.laytonsmith.core.constructs.CDouble)1 CString (com.laytonsmith.core.constructs.CString)1