Search in sources :

Example 1 with UndoList

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

the class BlockController method onBlockIgnite.

@EventHandler
public void onBlockIgnite(BlockIgniteEvent event) {
    BlockIgniteEvent.IgniteCause cause = event.getCause();
    if (cause == BlockIgniteEvent.IgniteCause.ENDER_CRYSTAL || cause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) {
        return;
    }
    Entity entity = event.getIgnitingEntity();
    UndoList entityList = controller.getEntityUndo(entity);
    if (entityList != null) {
        entityList.add(event.getBlock());
        return;
    }
    Block ignitingBlock = event.getIgnitingBlock();
    Block targetBlock = event.getBlock();
    if (ignitingBlock != null) {
        UndoList undoList = controller.getPendingUndo(ignitingBlock.getLocation());
        if (undoList != null) {
            undoList.add(event.getBlock());
            return;
        }
    }
    UndoList undoList = controller.getPendingUndo(targetBlock.getLocation());
    if (undoList != null) {
        undoList.add(targetBlock);
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with UndoList

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

the class BlockController method onBlockBreak.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    Block block = event.getBlock();
    Player player = event.getPlayer();
    if (creativeBreakFrequency > 0 && player.getGameMode() == GameMode.CREATIVE) {
        com.elmakers.mine.bukkit.magic.Mage mage = controller.getMage(event.getPlayer());
        if (mage.checkLastClick(creativeBreakFrequency)) {
            event.setCancelled(true);
            return;
        }
    }
    if (controller.areLocksProtected() && controller.isContainer(block) && !event.getPlayer().hasPermission("Magic.bypass")) {
        String lockKey = CompatibilityUtils.getLock(block);
        if (lockKey != null && !lockKey.isEmpty()) {
            Inventory inventory = player.getInventory();
            Mage mage = controller.getRegisteredMage(event.getPlayer());
            if (mage != null) {
                inventory = mage.getInventory();
            }
            if (!InventoryUtils.hasItem(inventory, lockKey)) {
                String message = controller.getMessages().get("general.locked_chest");
                if (mage != null) {
                    mage.sendMessage(message);
                } else {
                    player.sendMessage(message);
                }
                event.setCancelled(true);
                return;
            }
        }
    }
    com.elmakers.mine.bukkit.api.block.BlockData modifiedBlock = com.elmakers.mine.bukkit.block.UndoList.getBlockData(block.getLocation());
    if (modifiedBlock != null) {
        UndoList undoList = modifiedBlock.getUndoList();
        if (undoList != null) {
            if (!undoList.isConsumed()) {
                event.setCancelled(true);
                block.setType(Material.AIR);
            }
            com.elmakers.mine.bukkit.block.UndoList.commit(modifiedBlock);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 3 with UndoList

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

the class BlockController method onBlockFade.

@EventHandler
public void onBlockFade(BlockFadeEvent event) {
    Block block = event.getBlock();
    UndoList undoList = controller.getPendingUndo(block.getLocation());
    if (undoList != null) {
        undoList.add(block);
    }
}
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 4 with UndoList

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

the class BlockController method onBlockBurn.

@EventHandler
public void onBlockBurn(BlockBurnEvent event) {
    Block targetBlock = event.getBlock();
    UndoList undoList = controller.getPendingUndo(targetBlock.getLocation());
    if (undoList == null) {
        // 6) Fire B rolls back, leaving burning blocks that continue to spread.
        for (BlockFace face : blockBurnDirections) {
            Block sourceBlock = targetBlock.getRelative(face);
            if (sourceBlock.getType() != Material.FIRE)
                continue;
            undoList = controller.getPendingUndo(sourceBlock.getLocation());
            if (undoList != null) {
                break;
            }
        }
    }
    if (undoList != null) {
        undoList.add(targetBlock);
    }
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) EventHandler(org.bukkit.event.EventHandler)

Example 5 with UndoList

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

the class EntityController method onEntityCombust.

@EventHandler
public void onEntityCombust(EntityCombustEvent event) {
    Entity entity = event.getEntity();
    com.elmakers.mine.bukkit.magic.Mage mage = controller.getRegisteredMage(entity);
    if (mage != null) {
        mage.onCombust(event);
    }
    if (!event.isCancelled()) {
        UndoList undoList = controller.getPendingUndo(entity.getLocation());
        if (undoList != null) {
            undoList.modify(entity);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) 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