Search in sources :

Example 31 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class BaseSpell method finalizeCast.

protected boolean finalizeCast(ConfigurationSection parameters) {
    SpellResult result = null;
    // Global parameters
    controller.disablePhysics(parameters.getInt("disable_physics", 0));
    if (!mage.isSuperPowered()) {
        if (backfireChance > 0 && random.nextDouble() < backfireChance) {
            backfire();
        } else if (fizzleChance > 0 && random.nextDouble() < fizzleChance) {
            result = SpellResult.FIZZLE;
        }
    }
    if (result == null) {
        result = onCast(parameters);
    }
    if (backfired) {
        result = SpellResult.BACKFIRE;
    }
    if (result == SpellResult.CAST) {
        LivingEntity sourceEntity = mage.getLivingEntity();
        Entity targetEntity = getTargetEntity();
        if (sourceEntity == targetEntity) {
            result = SpellResult.CAST_SELF;
        }
    }
    processResult(result, parameters);
    boolean success = result.isSuccess();
    boolean free = result.isFree(castOnNoTarget);
    if (!free) {
        if (costs != null && !mage.isCostFree()) {
            UndoList undoList = currentCast.getUndoList();
            for (CastingCost cost : costs) {
                if (undoList != null && cost.isItem() && currentCast != null) {
                    undoList.setConsumed(true);
                }
                cost.use(this);
            }
        }
        updateCooldown();
    }
    if (success && toggle != ToggleType.NONE) {
        activate();
    }
    sendCastMessage(result, " (" + success + ")");
    return success;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) CastingCost(com.elmakers.mine.bukkit.api.spell.CastingCost) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Example 32 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class BlockController method onBlockFromTo.

@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
    Block targetBlock = event.getToBlock();
    Block sourceBlock = event.getBlock();
    UndoList undoList = controller.getPendingUndo(sourceBlock.getLocation());
    if (undoList != null) {
        undoList.add(targetBlock);
    } else {
        undoList = controller.getPendingUndo(targetBlock.getLocation());
        if (undoList != null) {
            undoList.add(targetBlock);
        }
    }
    if (undoList != null && undoList.isScheduled()) {
        // Avoid dropping broken items!
        MaterialSet doubles = com.elmakers.mine.bukkit.block.UndoList.attachablesDouble;
        if (doubles.testBlock(targetBlock)) {
            Block upBlock = targetBlock.getRelative(BlockFace.UP);
            while (doubles.testBlock(upBlock)) {
                undoList.add(upBlock);
                DeprecatedUtils.setTypeIdAndData(upBlock, Material.AIR.ordinal(), (byte) 0, false);
                upBlock = upBlock.getRelative(BlockFace.UP);
            }
            Block downBlock = targetBlock.getRelative(BlockFace.DOWN);
            while (doubles.testBlock(downBlock)) {
                undoList.add(downBlock);
                DeprecatedUtils.setTypeIdAndData(downBlock, Material.AIR.ordinal(), (byte) 0, false);
                downBlock = downBlock.getRelative(BlockFace.DOWN);
            }
        }
        DeprecatedUtils.setTypeIdAndData(targetBlock, Material.AIR.ordinal(), (byte) 0, false);
        event.setCancelled(true);
    }
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) EventHandler(org.bukkit.event.EventHandler)

Example 33 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class BlockController method onPistonExtend.

@EventHandler
public void onPistonExtend(BlockPistonExtendEvent event) {
    Block piston = event.getBlock();
    Block block = piston.getRelative(event.getDirection());
    UndoList undoList = controller.getPendingUndo(block.getLocation());
    if (undoList != null) {
        undoList.add(block);
        undoList.add(piston);
    }
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) EventHandler(org.bukkit.event.EventHandler)

Example 34 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class BlockController method onEntityChangeBlockEvent.

@EventHandler
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof FallingBlock) {
        if (event.getTo() == Material.AIR) {
            // Block is falling, register it
            controller.registerFallingBlock(entity, event.getBlock());
        } else {
            // Block is landing, convert it
            UndoList blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
            if (blockList != null) {
                com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
                if (context != null && !context.hasBuildPermission(entity.getLocation().getBlock())) {
                    event.setCancelled(true);
                } else {
                    Block block = event.getBlock();
                    blockList.convert(entity, block);
                    if (!blockList.getApplyPhysics()) {
                        FallingBlock falling = (FallingBlock) entity;
                        DeprecatedUtils.setTypeIdAndData(block, DeprecatedUtils.getId(falling.getMaterial()), DeprecatedUtils.getBlockData(falling), false);
                        event.setCancelled(true);
                    }
                }
            }
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) EventHandler(org.bukkit.event.EventHandler)

Example 35 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class EntityController method onEntityDamageByEntity.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Projectile || entity instanceof TNTPrimed)
        return;
    Entity damager = event.getDamager();
    /*
        if (damager instanceof Projectile) {
            Projectile projectile = (Projectile)damager;
            ProjectileSource source = projectile.getShooter();
            if (source instanceof LivingEntity) {
                damager = (Entity)source;
            }
        }
        if (entity instanceof Creature && damager instanceof LivingEntity) {
            Creature creature = (Creature)entity;
            creature.setTarget((LivingEntity)damager);
        }
        */
    UndoList undoList = controller.getEntityUndo(damager);
    if (undoList != null) {
        // Prevent dropping items from frames,
        if (event.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK || undoList.isScheduled()) {
            undoList.damage(entity);
            if (!entity.isValid()) {
                event.setCancelled(true);
            }
        } else {
            undoList.modify(entity);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) TNTPrimed(org.bukkit.entity.TNTPrimed) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

UndoList (com.elmakers.mine.bukkit.api.block.UndoList)36 EventHandler (org.bukkit.event.EventHandler)15 Entity (org.bukkit.entity.Entity)14 Block (org.bukkit.block.Block)13 Location (org.bukkit.Location)10 FallingBlock (org.bukkit.entity.FallingBlock)10 Mage (com.elmakers.mine.bukkit.api.magic.Mage)8 LivingEntity (org.bukkit.entity.LivingEntity)6 Player (org.bukkit.entity.Player)6 ItemStack (org.bukkit.inventory.ItemStack)6 Ageable (org.bukkit.entity.Ageable)4 PigZombie (org.bukkit.entity.PigZombie)4 Slime (org.bukkit.entity.Slime)4 Zombie (org.bukkit.entity.Zombie)4 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)3 Target (com.elmakers.mine.bukkit.utility.Target)3 Nullable (javax.annotation.Nullable)3 BlockFace (org.bukkit.block.BlockFace)3 Skeleton (org.bukkit.entity.Skeleton)3