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;
}
Aggregations