use of org.bukkit.entity.Ageable in project Denizen-For-Bukkit by DenizenScript.
the class EntityAge method setAge.
public void setAge(int val) {
if (ageable.isCitizensNPC()) {
NPC ageable_npc = ageable.getDenizenNPC().getCitizen();
ageable_npc.getTrait(Age.class).setAge(val);
} else {
if (ageable.getBukkitEntity().getType() == EntityType.ZOMBIE) {
((Zombie) ageable.getBukkitEntity()).setBaby(val >= 0);
} else {
((Ageable) ageable.getBukkitEntity()).setAge(val);
}
}
}
use of org.bukkit.entity.Ageable in project MagicPlugin by elBukkit.
the class FamiliarSpell method onCast.
@SuppressWarnings("deprecation")
@Override
public SpellResult onCast(ConfigurationSection parameters) {
spawnCount = 0;
Target target = getTarget();
if (!target.hasTarget()) {
return SpellResult.NO_TARGET;
}
Block originalTarget = target.getBlock();
Block targetBlock = originalTarget;
LivingEntity targetEntity = null;
boolean track = parameters.getBoolean("track", true);
boolean loot = parameters.getBoolean("loot", false);
boolean setTarget = parameters.getBoolean("set_target", true);
double spawnRange = parameters.getInt("spawn_range", 0);
String entityName = parameters.getString("name", "");
if (hasFamiliar() && track) {
// Dispel familiars if you target them and cast
boolean isFamiliar = target.hasEntity() && isFamiliar(target.getEntity());
if (isFamiliar) {
checkListener();
releaseFamiliar(target.getEntity());
return SpellResult.DEACTIVATE;
}
releaseFamiliars();
}
if (target.hasEntity()) {
targetBlock = targetBlock.getRelative(BlockFace.SOUTH);
Entity e = target.getEntity();
if (e instanceof LivingEntity) {
targetEntity = (LivingEntity) e;
}
}
targetBlock = targetBlock.getRelative(BlockFace.UP);
Location centerLoc = targetBlock.getLocation();
Location caster = getLocation();
if (spawnRange > 0) {
double distanceSquared = targetBlock.getLocation().distanceSquared(caster);
if (spawnRange * spawnRange < distanceSquared) {
Vector direction = caster.getDirection().normalize().multiply(spawnRange);
centerLoc = caster.clone().add(direction);
for (int i = 0; i < spawnRange; i++) {
Material blockType = centerLoc.getBlock().getType();
if (blockType == Material.AIR || blockType == Material.WATER || blockType != Material.STATIONARY_WATER) {
break;
}
centerLoc = centerLoc.add(0, 1, 0);
}
}
}
EntityType famType = null;
int famCount = parameters.getInt("count", 1);
String famTypeName = parameters.getString("type", null);
if (famTypeName != null && !famTypeName.isEmpty()) {
try {
famType = EntityType.valueOf(famTypeName.toUpperCase());
} catch (Throwable ex) {
sendMessage("Unknown entity type: " + famTypeName);
return SpellResult.FAIL;
}
}
if (originalTarget.getType() == Material.WATER || originalTarget.getType() == Material.STATIONARY_WATER) {
famType = EntityType.SQUID;
}
boolean spawnBaby = parameters.getBoolean("baby", false);
List<LivingEntity> newFamiliars = new ArrayList<>();
for (int i = 0; i < famCount; i++) {
EntityType entityType = famType;
if (entityType == null) {
String randomType = RandomUtils.weightedRandom(entityTypeProbability);
try {
entityType = EntityType.fromName(randomType);
} catch (Throwable ex) {
sendMessage("Unknown entity type: " + randomType);
return SpellResult.FAIL;
}
}
if (parameters.contains("reason")) {
String reasonText = parameters.getString("reason").toUpperCase();
try {
spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
} catch (Exception ex) {
sendMessage("Unknown spawn reason: " + reasonText);
return SpellResult.FAIL;
}
}
final Location targetLoc = centerLoc.clone();
if (famCount > 1) {
targetLoc.setX(targetLoc.getX() + rand.nextInt(2 * famCount) - famCount);
targetLoc.setZ(targetLoc.getZ() + rand.nextInt(2 * famCount) - famCount);
}
targetLoc.setPitch(caster.getPitch());
targetLoc.setYaw(caster.getYaw());
if (entityType != null) {
final LivingEntity entity = spawnFamiliar(targetLoc, entityType, targetBlock.getLocation(), targetEntity, setTarget);
if (entity != null) {
if (entityName != null && !entityName.isEmpty()) {
entity.setCustomName(entityName);
}
if (!loot) {
entity.setMetadata("nodrops", new FixedMetadataValue(mage.getController().getPlugin(), true));
}
if (spawnBaby && entity instanceof Ageable) {
Ageable ageable = (Ageable) entity;
ageable.setBaby();
}
entity.teleport(targetLoc);
newFamiliars.add(entity);
spawnCount++;
registerForUndo(entity);
}
}
}
registerForUndo();
if (track) {
setFamiliars(newFamiliars);
checkListener();
}
return SpellResult.CAST;
}
use of org.bukkit.entity.Ageable in project MagicPlugin by elBukkit.
the class GrowEntityAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
MageController controller = context.getController();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
elementalSize *= 1.2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
context.registerModified(li);
((Ageable) li).setAdult();
} else if (li instanceof Zombie) {
context.registerModified(li);
Zombie zombie = (Zombie) li;
if (!zombie.isBaby()) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
Location targetLocation = li.getLocation();
li.remove();
Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
context.registerForUndo(giant);
if (spawnedList != null) {
spawnedList.add(giant);
}
} else {
((Zombie) li).setBaby(false);
}
} else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
context.registerModified(li);
((PigZombie) li).setBaby(false);
} else if (li instanceof Slime) {
context.registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() + 1);
} else if (li instanceof Skeleton && skeletons && ((Skeleton) li).getSkeletonType() == Skeleton.SkeletonType.NORMAL) {
context.registerModified(li);
Skeleton skeleton = (Skeleton) li;
skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
} else {
return SpellResult.NO_TARGET;
}
return SpellResult.CAST;
}
use of org.bukkit.entity.Ageable in project MagicPlugin by elBukkit.
the class GrowSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (!target.hasEntity()) {
return SpellResult.NO_TARGET;
}
Entity targetEntity = target.getEntity();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
elementalSize *= 1.2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
registerModified(li);
((Ageable) li).setAdult();
} else if (li instanceof Zombie) {
registerModified(li);
Zombie zombie = (Zombie) li;
if (!zombie.isBaby()) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
Location targetLocation = li.getLocation();
li.remove();
Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
registerForUndo(giant);
if (spawnedList != null) {
spawnedList.add(giant);
}
} else {
((Zombie) li).setBaby(false);
}
} else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
registerModified(li);
((PigZombie) li).setBaby(false);
} else if (li instanceof Slime) {
registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() + 1);
} else {
return SpellResult.NO_TARGET;
}
registerForUndo();
return SpellResult.CAST;
}
use of org.bukkit.entity.Ageable in project Citizens2 by CitizensDev.
the class Age method onSpawn.
@Override
public void onSpawn() {
if (npc.getEntity() instanceof Ageable) {
Ageable entity = (Ageable) npc.getEntity();
entity.setAge(age);
entity.setAgeLock(locked);
ageable = entity;
} else if (npc.getEntity() instanceof Zombie) {
((Zombie) npc.getEntity()).setBaby(age < 0);
ageable = null;
} else {
ageable = null;
}
}
Aggregations