use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class PillarSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Block attachBlock = getTargetBlock();
if (attachBlock == null) {
return SpellResult.NO_TARGET;
}
BlockFace direction = BlockFace.UP;
String typeString = parameters.getString("type", "");
if (typeString.equals("down")) {
direction = BlockFace.DOWN;
}
Block targetBlock = attachBlock.getRelative(direction);
int distance = 0;
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
while (isTargetable(targetBlock) && distance <= MAX_SEARCH_DISTANCE) {
distance++;
attachBlock = targetBlock;
targetBlock = attachBlock.getRelative(direction);
}
if (isTargetable(targetBlock)) {
return SpellResult.NO_TARGET;
}
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
MaterialBrush buildWith = getBrush();
Block pillar = targetBlock;
buildWith.setTarget(attachBlock.getLocation(), pillar.getLocation());
buildWith.update(mage, pillar.getLocation());
registerForUndo(pillar);
buildWith.modify(pillar);
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class PlaceSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target attachToBlock = getTarget();
if (!attachToBlock.isValid())
return SpellResult.NO_TARGET;
Block placeBlock = getPreviousBlock();
if (placeBlock == null)
return SpellResult.NO_TARGET;
if (!hasBuildPermission(placeBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
MaterialBrush buildWith = getBrush();
buildWith.setTarget(attachToBlock.getLocation(), placeBlock.getLocation());
buildWith.update(mage, placeBlock.getLocation());
registerForUndo(placeBlock);
buildWith.modify(placeBlock);
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class TossSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Location location = getLocation();
if (!hasBuildPermission(location.getBlock())) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
location.setY(location.getY() - 1);
MaterialBrush buildWith = getBrush();
buildWith.setTarget(location);
Material material = buildWith.getMaterial();
byte data = buildWith.getBlockData();
int tossCount = 1;
tossCount = parameters.getInt("count", tossCount);
tossCount = (int) (mage.getRadiusMultiplier() * tossCount);
float speed = 0.6f;
speed = (float) parameters.getDouble("speed", speed);
Vector direction = getDirection();
direction.normalize().multiply(speed);
Vector up = new Vector(0, 1, 0);
Vector perp = new Vector();
perp.copy(direction);
perp.crossProduct(up);
for (int i = 0; i < tossCount; i++) {
FallingBlock block = null;
location = getEyeLocation();
location.setX(location.getX() + perp.getX() * (Math.random() * tossCount / 4 - tossCount / 8));
location.setY(location.getY());
location.setZ(location.getZ() + perp.getZ() * (Math.random() * tossCount / 4 - tossCount / 8));
block = getWorld().spawnFallingBlock(location, material, data);
if (block == null) {
registerForUndo();
return SpellResult.FAIL;
}
registerForUndo(block);
block.setDropItem(false);
SafetyUtils.setVelocity(block, direction);
}
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class BreakBlockAction method perform.
@Override
public SpellResult perform(CastContext context) {
Block block = context.getTargetBlock();
if (block.getType() == Material.AIR || !context.isDestructible(block)) {
return SpellResult.NO_TARGET;
}
context.registerForUndo(block);
double scaledAmount = durabilityAmount;
if (maxDistanceSquared > 0) {
double distanceSquared = context.getTargetCenterLocation().distanceSquared(block.getLocation());
if (distanceSquared > maxDistanceSquared) {
return SpellResult.NO_TARGET;
}
if (distanceSquared > 0) {
scaledAmount = scaledAmount * (1 - distanceSquared / maxDistanceSquared);
}
}
double breakAmount = 1;
double durability = CompatibilityUtils.getDurability(block.getType());
if (durability > 0) {
double breakPercentage = scaledAmount / durability;
breakAmount = context.registerBreaking(block, breakPercentage);
}
if (breakAmount > 1) {
if (context.hasBreakPermission(block)) {
CompatibilityUtils.clearBreaking(block);
BlockState blockState = block.getState();
if (blockState != null && (blockState instanceof InventoryHolder || blockState.getType() == Material.FLOWER_POT)) {
NMSUtils.clearItems(blockState.getLocation());
}
MaterialBrush brush = context.getBrush();
if (brush == null) {
brush = new com.elmakers.mine.bukkit.block.MaterialBrush(context.getMage(), Material.AIR, (byte) 0);
context.setBrush(brush);
} else {
brush.setMaterial(Material.AIR);
}
super.perform(context);
context.unregisterBreaking(block);
context.playEffects("break");
}
} else {
CompatibilityUtils.setBreaking(block, breakAmount);
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.block.MaterialBrush in project MagicPlugin by elBukkit.
the class ShapeSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target t = getTarget();
Block target = t.getBlock();
if (target == null) {
return SpellResult.NO_TARGET;
}
int radius = parameters.getInt("radius", DEFAULT_RADIUS);
radius = parameters.getInt("r", radius);
Location orientTo = null;
if (getTargetType() == TargetType.SELECT) {
if (targetLocation2 != null) {
this.targetBlock = targetLocation2.getBlock();
}
if (targetBlock == null) {
targetBlock = target;
activate();
return SpellResult.TARGET_SELECTED;
} else {
radius = (int) targetBlock.getLocation().distance(target.getLocation());
orientTo = target.getLocation();
target = targetBlock;
}
}
int maxDimension = parameters.getInt("max_dimension", DEFAULT_MAX_DIMENSION);
maxDimension = parameters.getInt("md", maxDimension);
maxDimension = (int) (mage.getConstructionMultiplier() * maxDimension);
int diameter = radius * 2;
if (diameter > maxDimension) {
return SpellResult.FAIL;
}
if (!hasBuildPermission(target)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
MaterialBrush buildWith = getBrush();
buildWith.setTarget(target.getLocation());
ConstructionType conType = DEFAULT_CONSTRUCTION_TYPE;
String typeString = parameters.getString("type", "");
ConstructionType testType = ConstructionType.parseString(typeString, ConstructionType.UNKNOWN);
if (testType != ConstructionType.UNKNOWN) {
conType = testType;
}
int thickness = parameters.getInt("thickness", 1);
ShapeBatch batch = new ShapeBatch(this, target.getLocation(), conType, radius, thickness, orientTo);
if (parameters.contains("orient_dimension_max")) {
batch.setOrientDimensionMax(parameters.getInt("orient_dimension_max"));
} else if (parameters.contains("odmax")) {
batch.setOrientDimensionMax(parameters.getInt("odmax"));
}
if (parameters.contains("orient_dimension_min")) {
batch.setOrientDimensionMin(parameters.getInt("orient_dimension_min"));
} else if (parameters.contains("odmin")) {
batch.setOrientDimensionMin(parameters.getInt("odmin"));
}
boolean success = mage.addBatch(batch);
deactivate();
return success ? SpellResult.CAST : SpellResult.FAIL;
}
Aggregations