use of org.bukkit.entity.PigZombie 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.PigZombie 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.PigZombie in project Glowstone by GlowstoneMC.
the class BlockBed method blockInteract.
@Override
public boolean blockInteract(final GlowPlayer player, GlowBlock block, final BlockFace face, final Vector clickedLoc) {
GlowWorld world = player.getWorld();
MaterialData data = block.getState().getData();
if (!(data instanceof Bed)) {
warnMaterialData(Bed.class, data);
return false;
}
block = getHead(block);
// Disallow sleeping in nether and end biomes
Biome biome = block.getBiome();
if (EXPLOSIVE_IN_BIOMES.contains(biome)) {
// Set off an explosion at the bed slightly stronger than TNT
world.createExplosion(block.getLocation(), 5F, true);
return true;
}
// Sleeping is only possible during the night or a thunderstorm
// Tick values for day/night time taken from the minecraft wiki
final long time = world.getTime();
if ((time < 12541 || time > 23458) && !world.isThundering()) {
GlowstoneMessages.Bed.DAY.send(player);
return true;
}
if (isOccupied(block)) {
GlowstoneMessages.Bed.OCCUPIED.send(player);
return true;
}
if (!isWithinDistance(player, block, 3, 2, 3)) {
// Distance between player and bed is too great, fail silently
return true;
}
// (Don't use getEntitiesByType etc., because they copy the entire list of entities)
for (Entity e : world.getEntityManager()) {
if (e instanceof Creature && (e.getType() != EntityType.ZOMBIFIED_PIGLIN || ((PigZombie) e).isAngry()) && isWithinDistance(e, block.getRelative(BlockFace.DOWN), 8, 5, 8)) {
GlowstoneMessages.Bed.MOB.send(player);
return true;
}
}
player.enterBed(block);
return true;
}
use of org.bukkit.entity.PigZombie in project MagicPlugin by elBukkit.
the class ShrinkSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
String giveName = parameters.getString("name");
if (giveName != null) {
String itemName = giveName + "'s Head";
Player player = Bukkit.getPlayer(giveName);
if (player != null) {
dropPlayerHead(getLocation(), player, itemName);
} else {
dropPlayerHead(getLocation(), giveName, itemName);
}
return SpellResult.CAST;
}
Target target = getTarget();
if (target.hasEntity()) {
Entity targetEntity = target.getEntity();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
if (elementalSize < 0.1) {
int elementalDamage = parameters.getInt("elemental_damage", DEFAULT_ENTITY_DAMAGE);
controller.damageElemental(targetEntity, elementalDamage, 0, mage.getCommandSender());
} else {
elementalSize /= 2;
controller.setElementalScale(targetEntity, elementalSize);
}
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
// Register for undo in advance to catch entity death.
registerForUndo();
int damage = parameters.getInt("entity_damage", DEFAULT_ENTITY_DAMAGE);
LivingEntity li = (LivingEntity) targetEntity;
boolean alreadyDead = li.isDead() || li.getHealth() <= 0;
String ownerName = null;
String itemName = null;
byte data = 3;
if (li instanceof Player) {
damage = parameters.getInt("player_damage", DEFAULT_PLAYER_DAMAGE);
ownerName = ((Player) li).getName();
} else {
itemName = li.getType().getName() + " Head";
switch(li.getType()) {
case CREEPER:
data = 4;
break;
case ZOMBIE:
data = 2;
break;
case SKELETON:
Skeleton skeleton = (Skeleton) li;
data = (byte) (skeleton.getSkeletonType() == SkeletonType.NORMAL ? 0 : 1);
break;
default:
ownerName = getMobSkin(li.getType());
}
}
if (itemName == null && ownerName != null) {
itemName = ownerName + "'s Head";
}
Location targetLocation = targetEntity.getLocation();
if (li instanceof Player) {
CompatibilityUtils.magicDamage(li, damage, mage.getEntity());
if (li.isDead() && !alreadyDead) {
dropPlayerHead(targetEntity.getLocation(), (Player) li, itemName);
}
} else if (li.getType() == EntityType.GIANT) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
registerModified(li);
li.remove();
Entity zombie = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.ZOMBIE);
if (zombie instanceof Zombie) {
((Zombie) zombie).setBaby(false);
}
registerForUndo(zombie);
if (spawnedList != null) {
spawnedList.add(zombie);
}
} else if (li instanceof Ageable && ((Ageable) li).isAdult() && !(li instanceof Player)) {
registerModified(li);
((Ageable) li).setBaby();
} else if (li instanceof Zombie && !((Zombie) li).isBaby()) {
registerModified(li);
((Zombie) li).setBaby(true);
} else if (li instanceof PigZombie && !((PigZombie) li).isBaby()) {
registerModified(li);
((PigZombie) li).setBaby(true);
} else if (li instanceof Slime && ((Slime) li).getSize() > 1) {
registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() - 1);
} else {
CompatibilityUtils.magicDamage(li, damage, mage.getEntity());
if ((ownerName != null || data != 3) && (li.isDead() || li.getHealth() == 0) && !alreadyDead) {
dropHead(targetEntity.getLocation(), ownerName, itemName, data);
}
}
} else {
Block targetBlock = target.getBlock();
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
String blockSkin = getBlockSkin(targetBlock.getType());
if (blockSkin == null)
return SpellResult.NO_TARGET;
if (!hasBreakPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (mage.isIndestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
registerForUndo(targetBlock);
registerForUndo();
dropHead(targetBlock.getLocation(), blockSkin, targetBlock.getType().name(), (byte) 3);
targetBlock.setType(Material.AIR);
}
return SpellResult.CAST;
}
use of org.bukkit.entity.PigZombie in project MagicPlugin by elBukkit.
the class ShrinkEntityAction 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);
if (elementalSize < 0.1) {
return super.perform(context);
}
elementalSize /= 2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
boolean alreadyDead = li.isDead() || li.getHealth() <= 0;
String ownerName = null;
String itemName = null;
byte data = 3;
if (li instanceof Player) {
ownerName = ((Player) li).getName();
} else {
itemName = DeprecatedUtils.getName(li.getType()) + " Head";
switch(li.getType()) {
case CREEPER:
data = 4;
break;
case ZOMBIE:
data = 2;
break;
case SKELETON:
Skeleton skeleton = (Skeleton) li;
data = (byte) (skeleton.getSkeletonType() == SkeletonType.NORMAL ? 0 : 1);
break;
default:
ownerName = controller.getMobSkin(li.getType());
}
}
if (itemName == null && ownerName != null) {
itemName = ownerName + "'s Head";
}
Location targetLocation = targetEntity.getLocation();
if (li instanceof Player) {
super.perform(context);
if (li.isDead() && !alreadyDead) {
dropPlayerHead(targetEntity.getLocation(), (Player) li, itemName);
}
} else if (li.getType() == EntityType.GIANT) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
context.registerModified(li);
li.remove();
Entity zombie = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.ZOMBIE);
if (zombie instanceof Zombie) {
((Zombie) zombie).setBaby(false);
}
context.registerForUndo(zombie);
if (spawnedList != null) {
spawnedList.add(zombie);
}
} else if (li instanceof Ageable && ((Ageable) li).isAdult() && !(li instanceof Player)) {
context.registerModified(li);
((Ageable) li).setBaby();
} else if (li instanceof Zombie && !((Zombie) li).isBaby()) {
context.registerModified(li);
((Zombie) li).setBaby(true);
} else if (li instanceof PigZombie && !((PigZombie) li).isBaby()) {
context.registerModified(li);
((PigZombie) li).setBaby(true);
} else if (li instanceof Slime && ((Slime) li).getSize() > 1) {
context.registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() - 1);
} else if (li instanceof Skeleton && skeletons && ((Skeleton) li).getSkeletonType() == SkeletonType.WITHER) {
context.registerModified(li);
Skeleton skeleton = (Skeleton) li;
skeleton.setSkeletonType(SkeletonType.NORMAL);
} else {
super.perform(context);
if ((ownerName != null || data != 3) && (li.isDead() || li.getHealth() == 0) && !alreadyDead) {
dropHead(targetEntity.getLocation(), ownerName, itemName, data);
}
}
return SpellResult.CAST;
}
Aggregations