Search in sources :

Example 1 with BlockData

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

the class EntityController method onItemSpawn.

@EventHandler(priority = EventPriority.LOWEST)
public void onItemSpawn(ItemSpawnEvent event) {
    if (disableItemSpawn || com.elmakers.mine.bukkit.block.BlockData.undoing) {
        event.setCancelled(true);
        return;
    }
    Item itemEntity = event.getEntity();
    ItemStack spawnedItem = itemEntity.getItemStack();
    Block block = itemEntity.getLocation().getBlock();
    BlockData undoData = com.elmakers.mine.bukkit.block.UndoList.getBlockData(block.getLocation());
    boolean isBreaking = block.getType() != Material.AIR;
    if (!isBreaking) {
        MaterialSet doubleAttachables = controller.getMaterialSetManager().getMaterialSetEmpty("attachable_double");
        isBreaking = doubleAttachables.testItem(spawnedItem);
    }
    if (undoData != null && isBreaking) {
        // So we can catch this as a one-time event, for blocks we have recorded.
        if (undoData.getMaterial() != Material.AIR) {
            UndoList undoList = undoData.getUndoList();
            if (undoList != null) {
                undoList.add(block);
            } else {
                controller.getLogger().warning("Block broken into item under undo at " + block + ", but no undo list was assigned");
            }
            event.setCancelled(true);
            return;
        }
        // If this was a block we built magically, don't drop items if the item being dropped
        // matches the block type. This is messy, but avoid players losing all their items
        // when suffocating inside a Blob
        Collection<ItemStack> drops = block.getDrops();
        if (drops != null) {
            for (ItemStack drop : drops) {
                if (drop.getType() == spawnedItem.getType()) {
                    com.elmakers.mine.bukkit.block.UndoList.commit(undoData);
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
    if (Wand.isSkill(spawnedItem)) {
        event.setCancelled(true);
        return;
    }
    if (Wand.isWand(spawnedItem)) {
        boolean invulnerable = controller.getWandProperty(spawnedItem, "invulnerable", false);
        if (invulnerable) {
            CompatibilityUtils.setInvulnerable(event.getEntity());
        }
        boolean trackWand = controller.getWandProperty(spawnedItem, "track", false);
        if (trackWand) {
            Wand wand = controller.getWand(spawnedItem);
            controller.addLostWand(wand, event.getEntity().getLocation());
        }
    } else {
        // registerEntityForUndo(event.getEntity());
        if (ageDroppedItems > 0) {
            int ticks = ageDroppedItems * 20 / 1000;
            Item item = event.getEntity();
            CompatibilityUtils.ageItem(item, ticks);
        }
    }
}
Also used : Item(org.bukkit.entity.Item) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) Block(org.bukkit.block.Block) Wand(com.elmakers.mine.bukkit.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) BlockData(com.elmakers.mine.bukkit.api.block.BlockData) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BlockData

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

the class PhysicsHandler method allowPhysics.

protected boolean allowPhysics(Block block) {
    if (timeout == 0) {
        controller.unregisterPhysicsHandler(this);
        return true;
    }
    long now = System.currentTimeMillis();
    if (now > timeout) {
        controller.unregisterPhysicsHandler(this);
        timeout = 0;
        return true;
    }
    BlockData registered = UndoList.getBlockData(block.getLocation());
    if (registered == null) {
        return true;
    }
    com.elmakers.mine.bukkit.api.block.UndoList registeredList = registered.getUndoList();
    if (registeredList != null && !registeredList.getApplyPhysics()) {
        timeout = Math.min(now + timeoutBuffer, timeout);
        return false;
    }
    return true;
}
Also used : BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Example 3 with BlockData

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

the class UndoList method add.

@Override
public boolean add(BlockData blockData) {
    if (bypass)
        return true;
    if (!super.add(blockData)) {
        return false;
    }
    modifiedTime = System.currentTimeMillis();
    if (watching != null) {
        BlockData attachedBlock = watching.remove(blockData.getId());
        if (attachedBlock != null) {
            removeFromWatched(attachedBlock);
        }
    }
    register(blockData);
    blockData.setUndoList(this);
    if (loading)
        return true;
    addAttachable(blockData, BlockFace.NORTH, attachablesWall);
    addAttachable(blockData, BlockFace.SOUTH, attachablesWall);
    addAttachable(blockData, BlockFace.EAST, attachablesWall);
    addAttachable(blockData, BlockFace.WEST, attachablesWall);
    addAttachable(blockData, BlockFace.UP, attachables);
    addAttachable(blockData, BlockFace.DOWN, attachables);
    return true;
}
Also used : BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Example 4 with BlockData

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

the class UndoList method remove.

@Override
public boolean remove(Object o) {
    if (o instanceof BlockData) {
        BlockData block = (BlockData) o;
        removeFromModified(block);
    }
    return super.remove(o);
}
Also used : BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Example 5 with BlockData

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

the class UndoList method register.

public static BlockData register(Block block) {
    BlockData blockData = new com.elmakers.mine.bukkit.block.BlockData(block);
    registry.registerModified(blockData);
    return blockData;
}
Also used : BlockData(com.elmakers.mine.bukkit.api.block.BlockData)

Aggregations

BlockData (com.elmakers.mine.bukkit.api.block.BlockData)22 Block (org.bukkit.block.Block)6 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 Location (org.bukkit.Location)2 FallingBlock (org.bukkit.entity.FallingBlock)2 ItemStack (org.bukkit.inventory.ItemStack)2 CastContext (com.elmakers.mine.bukkit.api.action.CastContext)1 Batch (com.elmakers.mine.bukkit.api.batch.Batch)1 BlockList (com.elmakers.mine.bukkit.api.block.BlockList)1 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)1 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 UndoQueue (com.elmakers.mine.bukkit.api.block.UndoQueue)1 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 MagicAPI (com.elmakers.mine.bukkit.api.magic.MagicAPI)1 MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)1 LostWand (com.elmakers.mine.bukkit.api.wand.LostWand)1 UndoList (com.elmakers.mine.bukkit.block.UndoList)1 MagicController (com.elmakers.mine.bukkit.magic.MagicController)1