Search in sources :

Example 21 with Creature

use of org.bukkit.entity.Creature in project MagicPlugin by elBukkit.

the class EntityData method modifyPreSpawn.

private boolean modifyPreSpawn(MageController controller, Entity entity) {
    if (entity == null || entity.getType() != type)
        return false;
    boolean isPlayer = (entity instanceof Player);
    if (extraData != null) {
        extraData.apply(entity);
    }
    CompatibilityUtils.setSilent(entity, isSilent);
    entity.setFireTicks(fireTicks);
    if (entity instanceof Ageable) {
        Ageable ageable = (Ageable) entity;
        if (isBaby) {
            ageable.setBaby();
        } else {
            ageable.setAdult();
        }
    }
    if (entity instanceof Tameable) {
        ((Tameable) entity).setTamed(isTamed);
    }
    if (entity instanceof Colorable && dyeColor != null) {
        Colorable colorable = (Colorable) entity;
        colorable.setColor(dyeColor);
    }
    if (tags != null && !tags.isEmpty()) {
        Set<String> entityTags = CompatibilityUtils.getTags(entity);
        entityTags.addAll(tags);
    }
    if (entity instanceof Creature) {
        Creature creature = (Creature) entity;
        creature.setCanPickupItems(canPickupItems);
    }
    if (entity instanceof Painting) {
        Painting painting = (Painting) entity;
        if (art != null) {
            painting.setArt(art, true);
        }
        if (facing != null) {
            painting.setFacingDirection(facing, true);
        }
    } else if (entity instanceof ItemFrame) {
        ItemFrame itemFrame = (ItemFrame) entity;
        itemFrame.setItem(item);
        if (facing != null) {
            itemFrame.setFacingDirection(facing, true);
        }
    } else if (entity instanceof Item) {
        Item droppedItem = (Item) entity;
        droppedItem.setItemStack(item);
    } else if (entity instanceof Wolf && dyeColor != null) {
        Wolf wolf = (Wolf) entity;
        wolf.setCollarColor(dyeColor);
    } else if (entity instanceof Ocelot && ocelotType != null) {
        Ocelot ocelot = (Ocelot) entity;
        ocelot.setCatType(ocelotType);
    } else if (entity instanceof Rabbit && rabbitType != null) {
        Rabbit rabbit = (Rabbit) entity;
        rabbit.setRabbitType(rabbitType);
    } else if (entity instanceof ExperienceOrb && xp != null) {
        ((ExperienceOrb) entity).setExperience(xp);
    }
    if (entity instanceof LivingEntity) {
        LivingEntity li = (LivingEntity) entity;
        if (hasPotionEffects) {
            Collection<PotionEffect> currentEffects = li.getActivePotionEffects();
            for (PotionEffect effect : currentEffects) {
                li.removePotionEffect(effect.getType());
            }
            if (potionEffects != null) {
                for (PotionEffect effect : potionEffects) {
                    li.addPotionEffect(effect);
                }
            }
        }
        try {
            if (!isPlayer) {
                applyAttributes(li);
                copyEquipmentTo(li);
                if (maxHealth != null) {
                    li.setMaxHealth(maxHealth);
                }
            }
            if (health != null) {
                li.setHealth(Math.min(health, li.getMaxHealth()));
            }
            if (airLevel != null) {
                li.setRemainingAir(Math.min(airLevel, li.getRemainingAir()));
            }
            if (!hasAI) {
                li.setAI(hasAI);
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }
    if (!isPlayer && name != null && name.length() > 0) {
        entity.setCustomName(name);
    }
    boolean needsMage = controller != null && mageData != null;
    if (needsMage) {
        Mage apiMage = controller.getMage(entity);
        if (apiMage instanceof com.elmakers.mine.bukkit.magic.Mage) {
            ((com.elmakers.mine.bukkit.magic.Mage) apiMage).setEntityData(this);
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) Tameable(org.bukkit.entity.Tameable) Creature(org.bukkit.entity.Creature) PotionEffect(org.bukkit.potion.PotionEffect) Rabbit(org.bukkit.entity.Rabbit) ExperienceOrb(org.bukkit.entity.ExperienceOrb) ItemFrame(org.bukkit.entity.ItemFrame) Ageable(org.bukkit.entity.Ageable) Painting(org.bukkit.entity.Painting) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) Ocelot(org.bukkit.entity.Ocelot) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Colorable(org.bukkit.material.Colorable) Wolf(org.bukkit.entity.Wolf)

Aggregations

Creature (org.bukkit.entity.Creature)21 LivingEntity (org.bukkit.entity.LivingEntity)16 Entity (org.bukkit.entity.Entity)15 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)10 Player (org.bukkit.entity.Player)10 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)9 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)6 Timestamp (java.sql.Timestamp)5 ArrayList (java.util.ArrayList)5 CraftCreature (org.bukkit.craftbukkit.v1_12_R1.entity.CraftCreature)4 Location (org.bukkit.Location)3 World (org.bukkit.World)3 Biome (org.bukkit.block.Biome)3 Block (org.bukkit.block.Block)3 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)3 EventHandler (org.bukkit.event.EventHandler)3 ItemStack (org.bukkit.inventory.ItemStack)3 HashMultiset (com.google.common.collect.HashMultiset)2 Multiset (com.google.common.collect.Multiset)2 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2