Search in sources :

Example 11 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.

the class BlockSpell method addDestructible.

protected void addDestructible(MaterialAndData material) {
    MaterialSet current = getDestructible();
    destructible = MaterialSets.union(current, material);
}
Also used : MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet)

Example 12 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet 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 13 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.

the class DropSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Block target = getTargetBlock();
    if (target == null) {
        return SpellResult.NO_TARGET;
    }
    MaterialSet dropMaterials = controller.getMaterialSetManager().fromConfigEmpty(parameters.getString("drop"));
    if (!dropMaterials.testBlock(target)) {
        return SpellResult.NO_TARGET;
    }
    if (!hasBreakPermission(target)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    Collection<ItemStack> drops = new ArrayList<>();
    int maxRecursion = parameters.getInt("recursion_depth", DEFAULT_MAX_RECURSION);
    dropCount = parameters.getInt("drop_count", -1);
    falling = parameters.getBoolean("falling", true);
    diagonals = parameters.getBoolean("diagonals", true);
    drop(target, dropMaterials, drops, maxRecursion);
    for (ItemStack drop : drops) {
        target.getWorld().dropItemNaturally(target.getLocation(), drop);
    }
    // Make this undoable.. even though it means you can exploit it for ore with Rewind. Meh!
    registerForUndo();
    return SpellResult.CAST;
}
Also used : MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)13 Block (org.bukkit.block.Block)6 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 FallingBlock (org.bukkit.entity.FallingBlock)2 EventHandler (org.bukkit.event.EventHandler)2 ItemStack (org.bukkit.inventory.ItemStack)2 Test (org.junit.Test)2 BlockData (com.elmakers.mine.bukkit.api.block.BlockData)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 MaterialSetManager (com.elmakers.mine.bukkit.api.magic.MaterialSetManager)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 Wand (com.elmakers.mine.bukkit.wand.Wand)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Material (org.bukkit.Material)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1