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;
}
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()));
}
}
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations