Search in sources :

Example 46 with MaterialAndData

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

the class DisintegrateSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    int playerDamage = parameters.getInt("player_damage", DEFAULT_PLAYER_DAMAGE);
    int entityDamage = parameters.getInt("entity_damage", DEFAULT_ENTITY_DAMAGE);
    if (target.hasEntity()) {
        Entity targetEntity = target.getEntity();
        if (controller.isElemental(targetEntity)) {
            int elementalDamage = parameters.getInt("elemental_damage", DEFAULT_ENTITY_DAMAGE);
            controller.damageElemental(targetEntity, elementalDamage, 0, mage.getCommandSender());
            return SpellResult.CAST;
        } else {
            registerModified(targetEntity);
            if (targetEntity instanceof Player) {
                Player player = (Player) targetEntity;
                CompatibilityUtils.magicDamage(player, mage.getDamageMultiplier() * playerDamage, mage.getEntity());
            } else if (targetEntity instanceof LivingEntity) {
                LivingEntity li = (LivingEntity) targetEntity;
                CompatibilityUtils.magicDamage(li, mage.getDamageMultiplier() * entityDamage, mage.getEntity());
            } else {
                targetEntity.remove();
            }
            registerForUndo();
            return SpellResult.CAST;
        }
    }
    if (!target.hasTarget()) {
        return SpellResult.NO_TARGET;
    }
    Block targetBlock = target.getBlock();
    if (!hasBreakPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!isDestructible(targetBlock)) {
        return SpellResult.NO_TARGET;
    }
    registerForUndo(targetBlock);
    // This makes $target messaging work properly, otherwise
    // it always displays air or water
    MaterialAndData targetMaterial = new MaterialAndData(targetBlock);
    getCurrentCast().setTargetName(targetMaterial.getName());
    if (isUnderwater()) {
        targetBlock.setType(Material.STATIONARY_WATER);
    } else {
        targetBlock.setType(Material.AIR);
    }
    registerForUndo();
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Player(org.bukkit.entity.Player) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block)

Example 47 with MaterialAndData

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

the class FlingSpell 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)

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