use of com.elmakers.mine.bukkit.utility.Target 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.utility.Target in project MagicPlugin by elBukkit.
the class PotionEffectSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (!target.hasTarget()) {
return SpellResult.NO_TARGET;
}
List<LivingEntity> targetEntities = new ArrayList<>();
Entity targetedEntity = target.getEntity();
if (target.hasEntity() && targetedEntity instanceof LivingEntity) {
targetEntities.add((LivingEntity) targetedEntity);
}
int radius = parameters.getInt("radius", 0);
radius = (int) (mage.getRadiusMultiplier() * radius);
if (radius > 0) {
List<Entity> entities = CompatibilityUtils.getNearbyEntities(target.getLocation(), radius, radius, radius);
for (Entity entity : entities) {
if (entity instanceof LivingEntity && entity != targetedEntity && entity != mage.getEntity()) {
targetEntities.add((LivingEntity) entity);
}
}
}
if (targetEntities.size() == 0) {
return SpellResult.NO_TARGET;
}
int fallProtection = parameters.getInt("fall_protection", 0);
Integer duration = null;
if (parameters.contains("duration")) {
duration = parameters.getInt("duration");
}
Collection<PotionEffect> effects = getPotionEffects(parameters, duration);
for (LivingEntity targetEntity : targetEntities) {
Mage targetMage = controller.isMage(targetEntity) ? controller.getMage(targetEntity) : null;
if (targetMage != null && fallProtection > 0) {
targetMage.enableFallProtection(fallProtection);
}
if (targetEntity != mage.getEntity()) {
// Check for superprotected mages
if (targetMage != null) {
// Check for protected players
if (isSuperProtected(targetMage)) {
continue;
}
if (parameters.getBoolean("deactivate_target_mage")) {
targetMage.deactivateAllSpells(true, false);
}
}
}
if (targetEntity instanceof Player && parameters.getBoolean("feed", false)) {
Player p = (Player) targetEntity;
p.setExhaustion(0);
p.setFoodLevel(20);
}
if (parameters.getBoolean("cure", false)) {
Collection<PotionEffect> currentEffects = targetEntity.getActivePotionEffects();
for (PotionEffect effect : currentEffects) {
if (negativeEffects.contains(effect.getType())) {
targetEntity.removePotionEffect(effect.getType());
}
}
}
if (parameters.contains("heal")) {
registerModified(targetEntity);
double health = targetEntity.getHealth() + parameters.getDouble("heal");
targetEntity.setHealth(Math.min(health, targetEntity.getMaxHealth()));
} else if (parameters.contains("heal_percentage")) {
registerModified(targetEntity);
double health = targetEntity.getHealth() + targetEntity.getMaxHealth() * parameters.getDouble("heal_percentage");
targetEntity.setHealth(Math.min(health, targetEntity.getMaxHealth()));
} else if (parameters.contains("damage")) {
registerModified(targetEntity);
CompatibilityUtils.magicDamage(targetEntity, parameters.getDouble("damage") * mage.getDamageMultiplier(), mage.getEntity());
} else {
registerPotionEffects(targetEntity);
}
if (parameters.contains("fire")) {
registerModified(targetEntity);
targetEntity.setFireTicks(parameters.getInt("fire"));
}
CompatibilityUtils.applyPotionEffects(targetEntity, effects);
if (parameters.contains("remove_effects")) {
List<String> removeKeys = parameters.getStringList("remove_effects");
for (String removeKey : removeKeys) {
PotionEffectType removeType = PotionEffectType.getByName(removeKey);
targetEntity.removePotionEffect(removeType);
}
}
}
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class LightningSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (target == null || !target.isValid()) {
return SpellResult.NO_TARGET;
}
Block targetBlock = target.getBlock();
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
CoverAction cover = new CoverAction();
cover.addAction(new LightningAction());
ActionHandler handler = new ActionHandler();
handler.loadAction(cover);
handler.initialize(this, parameters);
registerForUndo();
return handler.start(getCurrentCast(), parameters);
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class MusicSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (!target.hasTarget()) {
return SpellResult.NO_TARGET;
}
Location location = target.getLocation();
location.getWorld().playEffect(location, Effect.RECORD_PLAY, RECORDS[random.nextInt(RECORDS.length)].getId());
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class ForceSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
effectColor = mage.getEffectColor();
if (effectColor == null) {
effectColor = Color.fromRGB(Integer.parseInt(parameters.getString("effect_color", "FF0000"), 16));
}
if (targetEntity != null) {
Location location = getLocation();
World targetWorld = targetEntity.getWorld();
if (!targetEntity.isValid() || targetEntity.isDead()) {
releaseTarget();
} else if (targetWorld == null || location == null || !targetWorld.getName().equals(location.getWorld().getName())) {
releaseTarget();
} else if (location.distanceSquared(targetEntity.getLocation()) > getMaxRangeSquared()) {
releaseTarget();
}
// Check for protected Mages
if (targetEntity != null && controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
// Check for protected players (admins, generally...)
if (isSuperProtected(targetMage)) {
releaseTarget();
}
}
}
if (targetEntity == null) {
Target target = getTarget();
if (!target.hasEntity() || !(target.getEntity() instanceof LivingEntity)) {
return SpellResult.NO_TARGET;
}
releaseTarget();
LivingEntity checkTarget = (LivingEntity) target.getEntity();
// Check for protected Mages
if (checkTarget != null && controller.isMage(checkTarget)) {
Mage targetMage = controller.getMage(checkTarget);
// Check for protected players
if (isSuperProtected(targetMage)) {
return SpellResult.NO_TARGET;
}
}
selectTarget(checkTarget);
activate();
return SpellResult.TARGET_SELECTED;
}
double multiplier = parameters.getDouble("size", 1);
int magnitude = parameters.getInt("entity_force", DEFAULT_MAGNITUDE);
forceEntity(targetEntity, multiplier, magnitude);
return SpellResult.CAST;
}
Aggregations