Search in sources :

Example 16 with MaterialAndData

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

the class EffectPlayer method getWorkingMaterial.

@SuppressWarnings("deprecation")
protected MaterialAndData getWorkingMaterial() {
    Location target = getTarget();
    if (sampleTarget && target != null) {
        return new MaterialAndData(target.getBlock().getType(), target.getBlock().getData());
    }
    if (material1 != null)
        return material1;
    MaterialAndData result = material;
    Location origin = getOrigin();
    if (result == null && target != null) {
        result = new MaterialAndData(target.getBlock().getType(), target.getBlock().getData());
    } else if (result == null && origin != null) {
        result = new MaterialAndData(origin.getBlock().getType(), origin.getBlock().getData());
    } else if (result == null) {
        result = new MaterialAndData(Material.AIR);
    }
    return result;
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Location(org.bukkit.Location) SourceLocation(com.elmakers.mine.bukkit.magic.SourceLocation) DynamicLocation(de.slikey.effectlib.util.DynamicLocation)

Example 17 with MaterialAndData

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

the class RaiseSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Block targetBlock = getTargetBlock();
    if (targetBlock == null) {
        return SpellResult.NO_TARGET;
    }
    if (!isDestructible(targetBlock)) {
        return SpellResult.NO_TARGET;
    }
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    BlockFace direction = BlockFace.UP;
    int distance = parameters.getInt("distance", 5);
    Block highestBlock = targetBlock;
    while (distance > 0) {
        highestBlock = highestBlock.getRelative(direction);
        if (highestBlock.getType() != Material.AIR) {
            return SpellResult.NO_TARGET;
        }
        distance--;
    }
    if (!hasBuildPermission(highestBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    MaterialAndData blockState = new MaterialAndData(targetBlock);
    registerForUndo(targetBlock);
    registerForUndo(highestBlock);
    targetBlock.setType(Material.AIR);
    blockState.modify(highestBlock);
    currentCast.registerBreakable(highestBlock, 1);
    registerForUndo();
    return SpellResult.CAST;
}
Also used : BlockFace(org.bukkit.block.BlockFace) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block)

Example 18 with MaterialAndData

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

the class LevitateSpell method getEffectMaterial.

@Override
public com.elmakers.mine.bukkit.api.block.MaterialAndData getEffectMaterial() {
    Block block = mage.getEntity().getLocation().getBlock();
    block = block.getRelative(BlockFace.DOWN);
    return new MaterialAndData(block);
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block)

Example 19 with MaterialAndData

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

the class Messages method describeItem.

@Override
public String describeItem(ItemStack item) {
    String displayName = null;
    if (item.hasItemMeta()) {
        ItemMeta meta = item.getItemMeta();
        displayName = meta.getDisplayName();
        if ((displayName == null || displayName.isEmpty()) && meta instanceof BookMeta) {
            BookMeta book = (BookMeta) meta;
            displayName = book.getTitle();
        }
    }
    if (displayName == null || displayName.isEmpty()) {
        MaterialAndData material = new MaterialAndData(item);
        displayName = material.getName();
    }
    return displayName;
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 20 with MaterialAndData

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

the class AbsorbAction method perform.

@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
    Block target = context.getTargetBlock();
    Mage mage = context.getMage();
    Wand wand = context.getWand();
    if (wand == null) {
        return SpellResult.FAIL;
    }
    MageController controller = context.getController();
    Material material = target.getType();
    byte data = target.getData();
    MaterialSet buildingMaterials = controller.getBuildingMaterialSet();
    MaterialSet restrictedMaterials = mage.getRestrictedMaterialSet();
    if (material == null || material == Material.AIR) {
        return SpellResult.NO_TARGET;
    }
    if (!mage.getCommandSender().hasPermission("Magic.bypass_restricted") && (!buildingMaterials.testBlock(target) || restrictedMaterials.testBlock(target))) {
        return SpellResult.NO_TARGET;
    }
    // Add to the wand
    MaterialAndData mat = new MaterialAndData(material, data);
    if (!wand.addBrush(mat.getKey())) {
        // Still try and activate it
        wand.setActiveBrush(mat.getKey());
        return SpellResult.NO_TARGET;
    }
    // And activate it
    wand.setActiveBrush(mat.getKey());
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) Block(org.bukkit.block.Block) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Material(org.bukkit.Material)

Aggregations

MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)47 Block (org.bukkit.block.Block)20 ItemStack (org.bukkit.inventory.ItemStack)11 ArrayList (java.util.ArrayList)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)10 Material (org.bukkit.Material)8 Nullable (javax.annotation.Nullable)7 ItemMeta (org.bukkit.inventory.meta.ItemMeta)7 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 Target (com.elmakers.mine.bukkit.utility.Target)5 Player (org.bukkit.entity.Player)5 MageController (com.elmakers.mine.bukkit.api.magic.MageController)4 Wand (com.elmakers.mine.bukkit.api.wand.Wand)4 List (java.util.List)4 ItemData (com.elmakers.mine.bukkit.api.item.ItemData)3 MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)3 IOException (java.io.IOException)3 Location (org.bukkit.Location)3 CurrencyItem (com.elmakers.mine.bukkit.api.block.CurrencyItem)2 ParseException (java.text.ParseException)2