Search in sources :

Example 1 with Colorable

use of org.bukkit.material.Colorable 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

Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 Ageable (org.bukkit.entity.Ageable)1 Creature (org.bukkit.entity.Creature)1 ExperienceOrb (org.bukkit.entity.ExperienceOrb)1 Item (org.bukkit.entity.Item)1 ItemFrame (org.bukkit.entity.ItemFrame)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Ocelot (org.bukkit.entity.Ocelot)1 Painting (org.bukkit.entity.Painting)1 Player (org.bukkit.entity.Player)1 Rabbit (org.bukkit.entity.Rabbit)1 Tameable (org.bukkit.entity.Tameable)1 Wolf (org.bukkit.entity.Wolf)1 Colorable (org.bukkit.material.Colorable)1 PotionEffect (org.bukkit.potion.PotionEffect)1