Search in sources :

Example 1 with Sittable

use of org.bukkit.entity.Sittable in project Prism-Bukkit by prism.

the class EntitySerializer method serialize.

/**
 * Serialize entity.
 * @param entity Entity.
 */
public final void serialize(Entity entity) {
    entityName = entity.getType().name().toLowerCase();
    // Get custom name
    customName = entity.getCustomName();
    // Get animal age
    if (entity instanceof Ageable) {
        isAdult = ((Ageable) entity).isAdult();
    }
    // Owner
    if (entity instanceof Tameable) {
        final Tameable mob = (Tameable) entity;
        if (mob.getOwner() != null) {
            tamingOwner = mob.getOwner().getUniqueId().toString();
        } else if (mob.isTamed()) {
            tamingOwner = "-none-";
        }
    }
    // Sitting
    if (entity instanceof Sittable) {
        sitting = ((Sittable) entity).isSitting();
    }
    EntityDamageEvent damageEvent = entity.getLastDamageCause();
    // Saves us the null check
    if (damageEvent instanceof EntityDamageByEntityEvent && !damageEvent.isCancelled() && damageEvent.getDamage() > ((LivingEntity) entity).getHealth()) {
        EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) damageEvent;
        if (e.getDamager() instanceof Projectile) {
            customDesc = EntityUtils.getCustomProjectileDescription((Projectile) e.getDamager());
        }
    }
    serializer(entity);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Sittable(org.bukkit.entity.Sittable) Tameable(org.bukkit.entity.Tameable) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Ageable(org.bukkit.entity.Ageable) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Projectile(org.bukkit.entity.Projectile)

Aggregations

Ageable (org.bukkit.entity.Ageable)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Projectile (org.bukkit.entity.Projectile)1 Sittable (org.bukkit.entity.Sittable)1 Tameable (org.bukkit.entity.Tameable)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)1