Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/com/nisovin/magicspells/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ public SpellCastEvent preCast(@NotNull SpellData data) {
if (castEvent.haveReagentsChanged()) {
boolean hasReagents = hasReagents(data.caster(), castEvent.getReagents());
if (!hasReagents && state != SpellCastState.MISSING_REAGENTS) {
castEvent.setSpellCastState(SpellCastState.MISSING_REAGENTS);
castEvent.setSpellCastState(state = SpellCastState.MISSING_REAGENTS);
debug(2, " Spell cast state changed: " + state);
} else if (hasReagents && state == SpellCastState.MISSING_REAGENTS) {
castEvent.setSpellCastState(state = SpellCastState.NORMAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public SpellCastEvent(Spell spell, LivingEntity caster, SpellCastState state, fl
reagentsChanged = false;
}

@Override
public LivingEntity getCaster() {
return spellData.caster();
}

/**
* Gets the current spell cast state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public SpellCastedEvent(SpellCastEvent castEvent, CastResult result) {
this(castEvent.getSpell(), castEvent.getSpellCastState(), result.action(), result.data(), castEvent.getCooldown(), castEvent.getReagents());
}

@Override
public LivingEntity getCaster() {
return spellData.caster();
}

/**
* Gets the current spell cast state.
* @return the spell cast state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,59 @@

import com.nisovin.magicspells.Spell;
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.util.SpellData;
import com.nisovin.magicspells.handlers.DebugHandler;

public class SpellPreImpactEvent extends SpellEvent implements Cancellable {

private LivingEntity target;
private float power;
private Spell deliverySpell;
private final Spell deliverySpell;

private SpellData spellData;

private boolean redirect;
private boolean cancelled;

@Deprecated
public SpellPreImpactEvent(Spell spellPayload, Spell deliverySpell, LivingEntity caster, LivingEntity target, float power) {
super(spellPayload, caster);
this.target = target;
this.power = power;
this(spellPayload, deliverySpell, new SpellData(caster, target, power));
}

public SpellPreImpactEvent(Spell spellPayload, Spell deliverySpell, SpellData spellData) {
super(spellPayload, spellData.caster());
this.deliverySpell = deliverySpell;
redirect = false;
cancelled = false;
this.spellData = spellData;
if (DebugHandler.isSpellPreImpactEventCheckEnabled()) MagicSpells.plugin.getLogger().info(toString());
}


@Override
public LivingEntity getCaster() {
return spellData.caster();
}

public LivingEntity getTarget() {
return target;
return spellData.target();
}

public boolean getRedirected() {
return redirect;
}

public void setRedirected(boolean redirect) {
this.redirect = redirect;
}

public float getPower() {
return power;
return spellData.power();
}

public void setPower(float power) {
this.power = power;
spellData = spellData.power(power);
}


public SpellData getSpellData() {
return spellData;
}

public Spell getDeliverySpell() {
return deliverySpell;
}
Expand All @@ -60,14 +73,14 @@ public boolean isCancelled() {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}

@Override
public String toString() {
String casterLabel = "Caster: " + (caster == null ? "null" : caster.toString());
String targetLabel = "Target: " + (target == null ? "null" : target.toString());
String spellLabel = "SpellPayload: " + (spell == null ? "null" : spell.toString());
String payloadSpellLabel = "Delivery Spell: " + (deliverySpell == null ? "null" : deliverySpell.toString());
String casterLabel = "Caster: " + caster;
String targetLabel = "Target: " + spellData.target();
String spellLabel = "SpellPayload: " + (spell == null ? "null" : spell.getInternalName());
String payloadSpellLabel = "Delivery Spell: " + (deliverySpell == null ? "null" : deliverySpell.getInternalName());
return Arrays.deepToString(new String[]{ casterLabel, targetLabel, spellLabel, payloadSpellLabel });
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public SpellTargetEvent(Spell spell, LivingEntity caster, LivingEntity target, f
this.spellData = new SpellData(caster, target, power, null);
}

@Override
public LivingEntity getCaster() {
return spellData.caster();
}

/**
* Gets the living entity that is being targeted by the spell.
* @return the targeted living entity
Expand Down Expand Up @@ -91,6 +96,14 @@ public SpellData getSpellData() {
return spellData;
}

/**
* Sets the spell's {@link SpellData} to the provided value.
* @param data the new data
*/
public void setSpellData(SpellData data) {
spellData = data;
}

@Override
public boolean isCancelled() {
return cancelled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public SpellTargetLocationEvent(Spell spell, LivingEntity caster, Location targe
spellData = new SpellData(caster, target, power, null);
}

@Override
public LivingEntity getCaster() {
return spellData.caster();
}

/**
* Gets the location that is being targeted by the spell.
* @return the targeted living entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void run() {
if (!targetEvent.callEvent()) continue;

SpellData subData = targetEvent.getSpellData();
target = subData.target();

int fireTicks;
if (!data.constantFireTicks) {
Expand All @@ -161,7 +162,7 @@ public void run() {
addUseAndChargeCost(caster);

playSpellEffects(EffectPosition.TARGET, target, subData);
playSpellEffectsTrail(caster.getLocation(), entity.getLocation(), subData);
playSpellEffectsTrail(subData.caster().getLocation(), target.getLocation(), subData);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
// NO API CHANGES - NEEDS TOTAL REWORK
public class ReflectSpell extends BuffSpell {

private final Map<UUID, ReflectData> reflectors;
private final Set<String> shieldBreakerNames;
private final Set<String> delayedReflectionSpells;
private final Map<UUID, ReflectData> reflectors = new HashMap<>();
private final Set<String> shieldBreakerNames = new HashSet<>();
private final Set<String> delayedReflectionSpells = new HashSet<>();

private final ConfigData<Float> reflectedSpellPowerMultiplier;

Expand All @@ -31,10 +31,6 @@ public class ReflectSpell extends BuffSpell {
public ReflectSpell(MagicConfig config, String spellName) {
super(config, spellName);

reflectors = new HashMap<>();
shieldBreakerNames = new HashSet<>();
delayedReflectionSpells = new HashSet<>();

shieldBreakerNames.addAll(getConfigStringList("shield-breakers", new ArrayList<>()));
delayedReflectionSpells.addAll(getConfigStringList("delayed-reflection-spells", new ArrayList<>()));

Expand Down Expand Up @@ -93,17 +89,15 @@ public void onSpellTarget(SpellTargetEvent event) {
if (!target.isValid()) return;
if (!isActive(target)) return;

if (shieldBreakerNames != null && shieldBreakerNames.contains(event.getSpell().getInternalName())) {
if (shieldBreakerNames.contains(event.getSpell().getInternalName())) {
turnOff(target);
return;
}
if (delayedReflectionSpells != null && delayedReflectionSpells.contains(event.getSpell().getInternalName())) {
// Let the delayed reflection spells target the reflector so the animations run
// It will get reflected later
return;
}

event.setTarget(event.getCaster());
// Let the delayed reflection spells target the reflector so the reflection is handled on impact instead.
if (delayedReflectionSpells.contains(event.getSpell().getInternalName())) return;

event.setSpellData(event.getSpellData().invert());
ReflectData data = reflectors.get(target.getUniqueId());

addUseAndChargeCost(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.nisovin.magicspells.events.SpellTargetEvent;
import com.nisovin.magicspells.zones.NoMagicZoneManager;
import com.nisovin.magicspells.spells.TargetedEntitySpell;
import com.nisovin.magicspells.events.SpellPreImpactEvent;
import com.nisovin.magicspells.spelleffects.EffectPosition;
import com.nisovin.magicspells.spells.TargetedLocationSpell;
import com.nisovin.magicspells.spells.TargetedEntityFromLocationSpell;
Expand Down Expand Up @@ -268,27 +269,38 @@ public CastResult castAtEntityFromLocation(SpellData data) {
//check entities in the beam range
for (LivingEntity e : loc.getNearbyLivingEntities(hitRadius, verticalHitRadius)) {
if (!e.isValid() || immune.contains(e)) continue;
if (!validTargetList.canTarget(data.caster(), e)) continue;
if (!validTargetList.canTarget(locData.caster(), e)) continue;

SpellTargetEvent event = new SpellTargetEvent(this, locData, e);
if (!event.callEvent()) continue;

SpellData subData = event.getSpellData();
LivingEntity entity = event.getTarget();

if (hitSpell != null) hitSpell.subcast(subData.noLocation());
if (entityLocationSpell != null) entityLocationSpell.subcast(subData.noTarget());
if (hitSpell != null) {
SpellPreImpactEvent preImpact = new SpellPreImpactEvent(hitSpell.getSpell(), BeamSpell.this, subData);
if (preImpact.callEvent()) {
subData = preImpact.getSpellData();

if (preImpact.getRedirected()) {
step.multiply(-1);
locData = subData.caster(entity);
continue mainLoop;
} else hitSpell.subcast(subData.noLocation());
}
}

playSpellEffects(EffectPosition.TARGET, entity, subData);
playSpellEffectsTrail(data.caster().getLocation(), entity.getLocation(), subData);
immune.add(e);
playSpellEffectsTrail(subData.caster().getLocation(), entity.getLocation(), subData);
immune.add(entity);
if (stopOnHitEntity) break mainLoop;
}
}

//end of the beam
if (!zoneManager.willFizzle(loc, this) && d >= maxDistance) {
playSpellEffects(EffectPosition.DELAYED, loc, data.location(loc));
playSpellEffects(EffectPosition.DELAYED, loc, locData.location(loc));
if (endSpell != null) endSpell.subcast(locData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.bukkit.entity.ArmorStand;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.LivingEntity;
import org.bukkit.persistence.PersistentDataType;

Expand All @@ -28,6 +27,7 @@
import com.nisovin.magicspells.util.magicitems.MagicItem;
import com.nisovin.magicspells.util.magicitems.MagicItems;
import com.nisovin.magicspells.spells.TargetedEntitySpell;
import com.nisovin.magicspells.events.SpellPreImpactEvent;
import com.nisovin.magicspells.spelleffects.EffectPosition;
import com.nisovin.magicspells.spells.TargetedLocationSpell;
import com.nisovin.magicspells.spells.TargetedEntityFromLocationSpell;
Expand Down Expand Up @@ -298,7 +298,7 @@ public CastResult castAtEntityFromLocation(SpellData data) {
stand.getPersistentDataContainer().set(MS_BLOCK_BEAM, PersistentDataType.BOOLEAN, true);

if (hpFix) {
stand.getAttribute(Attribute.MAX_HEALTH).setBaseValue(health);
Util.setMaxHealth(stand, health);
stand.setHealth(health);
}

Expand All @@ -310,18 +310,29 @@ public CastResult castAtEntityFromLocation(SpellData data) {
//check entities in the beam range
for (LivingEntity e : loc.getNearbyLivingEntities(hitRadius, verticalHitRadius)) {
if (!e.isValid() || immune.contains(e)) continue;
if (!validTargetList.canTarget(data.caster(), e)) continue;
if (!validTargetList.canTarget(locData.caster(), e)) continue;

SpellTargetEvent event = new SpellTargetEvent(this, locData, e);
if (!event.callEvent()) continue;

SpellData subData = event.getSpellData();
LivingEntity subTarget = event.getTarget();

if (hitSpell != null) hitSpell.subcast(subData.noLocation());
if (hitSpell != null) {
SpellPreImpactEvent preImpact = new SpellPreImpactEvent(hitSpell.getSpell(), BlockBeamSpell.this, subData);
if (preImpact.callEvent()) {
subData = preImpact.getSpellData();

if (preImpact.getRedirected()) {
step.multiply(-1);
locData = subData.caster(e);
continue mainLoop;
} else hitSpell.subcast(subData.noLocation());
}
}

playSpellEffects(EffectPosition.TARGET, subTarget, subData);
playSpellEffectsTrail(data.caster().getLocation(), subTarget.getLocation(), subData);
playSpellEffectsTrail(subData.caster().getLocation(), subTarget.getLocation(), subData);
immune.add(e);

if (stopOnHitEntity) break mainLoop;
Expand All @@ -330,7 +341,7 @@ public CastResult castAtEntityFromLocation(SpellData data) {

//end of the beam
if (!zoneManager.willFizzle(loc, this) && d >= maxDistance) {
playSpellEffects(EffectPosition.DELAYED, loc, data.location(loc));
playSpellEffects(EffectPosition.DELAYED, loc, locData.location(loc));
if (endSpell != null) endSpell.subcast(locData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public CastResult cast(SpellData data) {
else target.setVelocity(velocity);

playSpellEffects(EffectPosition.TARGET, target, subData);
playSpellEffectsTrail(data.caster().getLocation(), target.getLocation(), subData);
playSpellEffectsTrail(subData.caster().getLocation(), target.getLocation(), subData);
}

playSpellEffects(EffectPosition.CASTER, data.caster(), data);
Expand Down
Loading
Loading