Search in sources :

Example 1 with PigZombie

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;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Skeleton(org.bukkit.entity.Skeleton) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Example 2 with PigZombie

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;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Example 3 with PigZombie

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;
}
Also used : Bed(org.bukkit.material.Bed) GlowBed(net.glowstone.block.entity.state.GlowBed) Entity(org.bukkit.entity.Entity) BedEntity(net.glowstone.block.entity.BedEntity) BlockEntity(net.glowstone.block.entity.BlockEntity) Biome(org.bukkit.block.Biome) Creature(org.bukkit.entity.Creature) PigZombie(org.bukkit.entity.PigZombie) GlowWorld(net.glowstone.GlowWorld) MaterialData(org.bukkit.material.MaterialData)

Example 4 with PigZombie

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;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) PigZombie(org.bukkit.entity.PigZombie) Block(org.bukkit.block.Block) Skeleton(org.bukkit.entity.Skeleton) Location(org.bukkit.Location)

Example 5 with PigZombie

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;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) PigZombie(org.bukkit.entity.PigZombie) Skeleton(org.bukkit.entity.Skeleton) Location(org.bukkit.Location)

Aggregations

PigZombie (org.bukkit.entity.PigZombie)6 Entity (org.bukkit.entity.Entity)5 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)4 Location (org.bukkit.Location)4 Ageable (org.bukkit.entity.Ageable)4 LivingEntity (org.bukkit.entity.LivingEntity)4 Player (org.bukkit.entity.Player)4 Slime (org.bukkit.entity.Slime)4 Zombie (org.bukkit.entity.Zombie)4 Skeleton (org.bukkit.entity.Skeleton)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)2 Target (com.elmakers.mine.bukkit.utility.Target)2 GlowWorld (net.glowstone.GlowWorld)1 BedEntity (net.glowstone.block.entity.BedEntity)1 BlockEntity (net.glowstone.block.entity.BlockEntity)1 GlowBed (net.glowstone.block.entity.state.GlowBed)1 Biome (org.bukkit.block.Biome)1 Block (org.bukkit.block.Block)1 Creature (org.bukkit.entity.Creature)1 Bed (org.bukkit.material.Bed)1