use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class AlterSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (target.hasEntity()) {
SpellResult result = alterEntity(target.getEntity());
if (result != SpellResult.NO_TARGET) {
return result;
}
}
Block targetBlock = target.getBlock();
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
int recurseDistance = parameters.getInt("depth", DEFAULT_RECURSE_DISTANCE);
recurseDistance = (int) (mage.getRadiusMultiplier() * recurseDistance);
List<Integer> adjustableMaterials = parseIntegers(DEFAULT_ADJUSTABLES);
List<Integer> maxData = parseIntegers(DEFAULT_ADJUST_MAX);
List<Integer> minData = parseIntegers(DEFAULT_ADJUST_MIN);
if (adjustableMaterials.size() != maxData.size() || maxData.size() != minData.size()) {
controller.getLogger().warning("Spells:Alter: Mis-match in adjustable material lists!");
}
if (!adjustableMaterials.contains(targetBlock.getTypeId())) {
return SpellResult.FAIL;
}
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (mage.isIndestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
if (!isDestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
int originalData = targetBlock.getData();
int materialIndex = adjustableMaterials.indexOf(targetBlock.getTypeId());
int minValue = minData.get(materialIndex);
int maxValue = maxData.get(materialIndex);
int dataSize = maxValue - minValue + 1;
byte data = (byte) ((((originalData - minValue) + 1) % dataSize) + minValue);
boolean recursive = recurseDistance > 0;
adjust(targetBlock, data, recursive, recurseDistance, 0);
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class CommandSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
List<String> commands = null;
if (parameters.contains("command")) {
String command = parameters.getString("command");
if (command != null && command.length() > 0) {
commands = new ArrayList<>();
commands.add(command);
}
} else {
commands = parameters.getStringList("commands");
}
if (commands == null || commands.size() == 0) {
return SpellResult.FAIL;
}
boolean asConsole = parameters.getBoolean("console", false);
CommandSender sender = asConsole ? Bukkit.getConsoleSender() : mage.getCommandSender();
if (sender == null) {
return SpellResult.FAIL;
}
boolean opPlayer = parameters.getBoolean("op", false);
boolean isOp = sender.isOp();
if (opPlayer && !isOp) {
sender.setOp(true);
}
Location location = getLocation();
Target target = null;
Location targetLocation = null;
if (getTargetType() != TargetType.NONE) {
target = getTarget();
targetLocation = target.getLocation();
if (targetLocation == null) {
return SpellResult.NO_TARGET;
}
}
for (String command : commands) {
command = command.replace("@_", " ").replace("@spell", getName()).replace("@pd", mage.getDisplayName()).replace("@p", mage.getName()).replace("@uuid", mage.getId()).replace("@world", location.getWorld().getName()).replace("@x", Double.toString(location.getX())).replace("@y", Double.toString(location.getY())).replace("@z", Double.toString(location.getZ()));
if (targetLocation != null) {
command = command.replace("@tworld", targetLocation.getWorld().getName()).replace("@tx", Double.toString(targetLocation.getX())).replace("@ty", Double.toString(targetLocation.getY())).replace("@tz", Double.toString(targetLocation.getZ()));
Entity targetEntity = target.getEntity();
if (targetEntity != null) {
if (controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
command = command.replace("@td", targetMage.getDisplayName()).replace("@t", targetMage.getName()).replace("@tuuid", targetMage.getId());
} else {
command = command.replace("@td", controller.getEntityDisplayName(targetEntity)).replace("@t", controller.getEntityName(targetEntity)).replace("@tuuid", targetEntity.getUniqueId().toString());
}
} else {
return SpellResult.NO_TARGET;
}
}
if (command.contains("@a")) {
double radius = parameters.getDouble("radius", 0);
double radiusSquared = radius * radius;
Player exclude = mage.getPlayer();
if (parameters.getBoolean("exclude_player", true)) {
exclude = null;
}
Collection<? extends Player> players = controller.getPlugin().getServer().getOnlinePlayers();
Location source = targetLocation == null ? getLocation() : targetLocation;
for (Player player : players) {
if (exclude != null && exclude.equals(player))
continue;
if (radiusSquared != 0) {
Location playerLocation = player.getLocation();
if (playerLocation.getWorld().equals(source.getWorld())) {
continue;
}
if (playerLocation.distanceSquared(source) > radiusSquared) {
continue;
}
}
String playerCommand = command;
playerCommand = playerCommand.replace("@a", player.getName());
controller.getPlugin().getServer().dispatchCommand(sender, playerCommand);
}
} else {
controller.getPlugin().getServer().dispatchCommand(sender, command);
}
}
if (opPlayer && !isOp) {
sender.setOp(false);
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class CommitSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
// You should really use /magic commit for this at this point.
String typeString = parameters.getString("type", "");
if (typeString.equalsIgnoreCase("all")) {
return controller.commitAll() ? SpellResult.CAST : SpellResult.FAIL;
}
Target target = getTarget();
Entity targetEntity = target.getEntity();
if (targetEntity instanceof Player) {
Mage mage = controller.getMage((Player) targetEntity);
return mage.commit() ? SpellResult.CAST : SpellResult.FAIL;
}
return mage.commit() ? SpellResult.CAST : SpellResult.FAIL;
}
use of com.elmakers.mine.bukkit.utility.Target 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;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class DoorSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (!target.hasTarget()) {
return SpellResult.NO_TARGET;
}
Block targetBlock = target.getBlock();
byte data = targetBlock.getData();
if ((data & 0x8) != 0) {
targetBlock = targetBlock.getRelative(BlockFace.DOWN);
data = targetBlock.getData();
}
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!isDestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
registerForUndo(targetBlock);
String type = parameters.getString("type", "open");
if (type.equalsIgnoreCase("open")) {
targetBlock.setData((byte) (data | 0x4));
} else if (type.equalsIgnoreCase("close")) {
targetBlock.setData((byte) (data & ~0x4));
} else if (type.equalsIgnoreCase("toggle")) {
targetBlock.setData((byte) (data ^ 0x4));
} else {
return SpellResult.FAIL;
}
registerForUndo();
return SpellResult.CAST;
}
Aggregations