use of com.elmakers.mine.bukkit.batch.ShapeBatch 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