Search in sources :

Example 36 with MaterialAndData

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

the class CycleBlockAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Block block = context.getTargetBlock();
    if (!context.hasBuildPermission(block)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    MaterialAndData targetMaterial = new MaterialAndData(block);
    MaterialAndData newMaterial = materials.get(targetMaterial);
    if (newMaterial == null) {
        return SpellResult.NO_TARGET;
    }
    context.registerForUndo(block);
    newMaterial.modify(block);
    return SpellResult.CAST;
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block)

Example 37 with MaterialAndData

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

the class CycleBlockAction method initialize.

@Override
public void initialize(Spell spell, ConfigurationSection parameters) {
    super.initialize(spell, parameters);
    @SuppressWarnings("unchecked") List<List<String>> allMaterials = (List<List<String>>) parameters.getList("materials");
    this.materials.clear();
    if (allMaterials == null) {
        spell.getController().getLogger().warning("CycleBlock action missing materials list");
    } else {
        for (List<String> list : allMaterials) {
            List<MaterialAndData> materialList = new ArrayList<>();
            for (String material : list) {
                MaterialAndData entry = new MaterialAndData(material);
                if (entry.isValid()) {
                    materialList.add(entry);
                }
            }
            for (int i = 0; i < materialList.size(); i++) {
                materials.put(materialList.get(i), materialList.get((i + 1) % materialList.size()));
            }
        }
    }
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 38 with MaterialAndData

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

the class FlowerAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Block block = context.getTargetBlock();
    if (block == null) {
        return SpellResult.NO_TARGET;
    }
    if (block.getType() != Material.GRASS) {
        return SpellResult.NO_TARGET;
    }
    block = block.getRelative(BlockFace.UP);
    if (block.getType() != Material.AIR) {
        return SpellResult.NO_TARGET;
    }
    MaterialAndData material = null;
    Random random = context.getRandom();
    boolean tall = flowers.size() == 0 || (tallFlowers.size() > 0 && random.nextBoolean());
    if (tall) {
        material = tallFlowers.get(random.nextInt(tallFlowers.size()));
    } else {
        if (flowers.size() > 0) {
            material = flowers.get(random.nextInt(flowers.size()));
        }
    }
    if (material == null) {
        return SpellResult.FAIL;
    }
    context.registerForUndo(block);
    material.modify(block);
    if (tall) {
        block = block.getRelative(BlockFace.UP);
        context.registerForUndo(block);
        material = new MaterialAndData(material.getMaterial(), (short) (material.getData() | 8));
        material.modify(block);
    }
    return SpellResult.CAST;
}
Also used : Random(java.util.Random) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block)

Example 39 with MaterialAndData

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

the class EffectLibManager method play.

@Nullable
public Effect play(ConfigurationSection configuration, EffectPlayer player, DynamicLocation origin, DynamicLocation target, Map<String, String> parameterMap) {
    if (parameterMap == null) {
        parameterMap = new HashMap<>();
    }
    Entity originEntity = origin == null ? null : origin.getEntity();
    if (originEntity != null && originEntity instanceof Player) {
        parameterMap.put("$name", ((Player) originEntity).getName());
    } else if (originEntity != null && originEntity instanceof LivingEntity) {
        parameterMap.put("$name", ((LivingEntity) originEntity).getCustomName());
    } else {
        parameterMap.put("$name", "Unknown");
    }
    Entity targetEntity = target == null ? null : target.getEntity();
    if (targetEntity != null && targetEntity instanceof Player) {
        parameterMap.put("$target", ((Player) targetEntity).getName());
    } else if (originEntity != null && targetEntity instanceof LivingEntity) {
        parameterMap.put("$target", ((LivingEntity) targetEntity).getCustomName());
    } else {
        parameterMap.put("$target", "Unknown");
    }
    Effect effect = null;
    String effectClass = configuration.getString("class");
    ParticleEffect particleEffect = player.overrideParticle(null);
    String effectOverride = player.getParticleOverrideName();
    if (effectOverride != null && effectOverride.isEmpty())
        effectOverride = null;
    String colorOverrideName = player.getColorOverrideName();
    if (colorOverrideName != null && colorOverrideName.isEmpty())
        colorOverrideName = null;
    ConfigurationSection parameters = configuration;
    Color colorOverride = player.getColor1();
    if ((colorOverrideName != null && colorOverride != null) || (effectOverride != null && particleEffect != null)) {
        parameters = new MemoryConfiguration();
        Collection<String> keys = configuration.getKeys(false);
        for (String key : keys) {
            parameters.set(key, configuration.get(key));
        }
        if (effectOverride != null && particleEffect != null) {
            parameters.set(effectOverride, particleEffect.name());
        }
        if (colorOverride != null && colorOverrideName != null) {
            String hexColor = Integer.toHexString(colorOverride.asRGB());
            parameters.set(colorOverrideName, hexColor);
        }
    }
    try {
        effect = effectManager.start(effectClass, parameters, origin, target, parameterMap);
        if (!parameters.contains("material")) {
            MaterialAndData mat = player.getWorkingMaterial();
            if (mat != null) {
                effect.material = mat.getMaterial();
                effect.materialData = mat.getBlockData();
            }
        }
    } catch (Throwable ex) {
        Bukkit.getLogger().warning("Error playing effects of class: " + effectClass);
        ex.printStackTrace();
    }
    return effect;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Color(org.bukkit.Color) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) LivingEntity(org.bukkit.entity.LivingEntity) ParticleEffect(de.slikey.effectlib.util.ParticleEffect) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Effect(de.slikey.effectlib.Effect) ParticleEffect(de.slikey.effectlib.util.ParticleEffect) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nullable(javax.annotation.Nullable)

Example 40 with MaterialAndData

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

the class BlockRecurse method recurse.

protected void recurse(Block block, ActionContext recurseAction, CastContext context, BlockFace nextFace, int rDepth) {
    if (nextFace != null) {
        block = block.getRelative(nextFace);
    }
    if (replaceable != null && !replaceable.contains(new MaterialAndData(block))) {
        return;
    }
    UndoList undoList = context.getUndoList();
    if (undoList != null) {
        if (undoList.contains(block)) {
            return;
        }
        undoList.add(block);
    }
    context.setTargetLocation(block.getLocation());
    if (recurseAction.perform(context) != SpellResult.CAST) {
        return;
    }
    if (rDepth < maxRecursion) {
        for (BlockFace face : BlockData.FACES) {
            if (nextFace == null || nextFace != BlockData.getReverseFace(face)) {
                recurse(block, recurseAction, context, face, rDepth + 1);
            }
        }
    }
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) BlockFace(org.bukkit.block.BlockFace) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData)

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