Skip to content

Commit

Permalink
Buff effect position fix!
Browse files Browse the repository at this point in the history
Fixed a bug which existed even in nisovin's version of MagicSpells, it caused all effects with buff position in buff spells to increase each time you have used that buff spell.
  • Loading branch information
Chronoken authored and TheComputerGeek2 committed Mar 13, 2018
1 parent b58f4e2 commit 59dc2a7
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions src/com/nisovin/magicspells/spelleffects/SpellEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,10 @@ public final Runnable playEffect(final Location location) {

private Runnable playEffectLocationReal(Location location) {
if (location == null) return playEffectLocation(null);
if (heightOffset != 0 || forwardOffset != 0) {
Location loc = location.clone();
if (heightOffset != 0) loc.setY(loc.getY() + heightOffset);
if (forwardOffset != 0) loc.add(loc.getDirection().setY(0).normalize().multiply(forwardOffset));
return playEffectLocation(loc);
}
return playEffectLocation(location.clone());
Location loc = location.clone();
if (heightOffset != 0) loc.setY(loc.getY() + heightOffset);
if (forwardOffset != 0) loc.add(loc.getDirection().setY(0).normalize().multiply(forwardOffset));
return playEffectLocation(loc);
}

protected Runnable playEffectLocation(Location location) {
Expand Down Expand Up @@ -194,14 +191,7 @@ public Runnable playEffect(Location location1, Location location2) {
}

public void playEffectWhileActiveOnEntity(final Entity entity, final SpellEffectActiveChecker checker) {
taskId = MagicSpells.scheduleRepeatingTask(new Runnable() {

@Override
public void run() {
if (checker.isActive(entity)) playEffect(entity);
}

}, 0, effectInterval);
new EffectTracker(entity, checker);
}

public OrbitTracker playEffectWhileActiveOrbit(final Entity entity, final SpellEffectActiveChecker checker) {
Expand All @@ -214,7 +204,38 @@ public interface SpellEffectActiveChecker {
boolean isActive(Entity entity);

}


class EffectTracker implements Runnable {

Entity entity;
SpellEffectActiveChecker checker;
int effectTrackerTaskId;

public EffectTracker(Entity entity, SpellEffectActiveChecker checker) {
this.entity = entity;
this.checker = checker;
this.effectTrackerTaskId = MagicSpells.scheduleRepeatingTask(this, 0, effectInterval);
}

@Override
public void run() {
// check for valid and alive caster
if (!entity.isValid() || !checker.isActive(entity)) {
stop();
return;
}

playEffect(entity);

}

public void stop() {
MagicSpells.cancelTask(effectTrackerTaskId);
entity = null;
}

}

class OrbitTracker implements Runnable {

Entity entity;
Expand Down Expand Up @@ -296,15 +317,13 @@ public void stop() {
*/
public static SpellEffect createNewEffectByName(String name) {
Class<? extends SpellEffect> clazz = effects.get(name.toLowerCase());
if (clazz != null) {
try {
return clazz.newInstance();
} catch (Exception e) {
DebugHandler.debugGeneral(e);
return null;
}
if (clazz == null) return null;
try {
return clazz.newInstance();
} catch (Exception e) {
DebugHandler.debugGeneral(e);
return null;
}
return null;
}

public void playTrackingLinePatterns(Location origin, Location target, Entity originEntity, Entity targetEntity) {
Expand Down

0 comments on commit 59dc2a7

Please sign in to comment.