Skip to content
Merged
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
29 changes: 10 additions & 19 deletions core/src/main/java/com/nisovin/magicspells/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -2007,29 +2007,20 @@ protected Map<SpellEffect, DelayableEntity<Entity>> playSpellEntityEffects(Effec
return values;
}

@Deprecated
/**
* @deprecated {@code armorstand} spell effect now extends {@code entity} effect and is spawned in with {@link Spell#playSpellEntityEffects(EffectPosition, Location, SpellData)}.
*/
@Deprecated(forRemoval = true)
protected Set<ArmorStand> playSpellArmorStandEffects(EffectPosition pos, Location location) {
Set<DelayableEntity<ArmorStand>> values = playSpellArmorStandEffects(pos, location, SpellData.NULL);
if (values == null) return null;

Set<ArmorStand> set = new HashSet<>();
values.forEach(stand -> stand.ifPresent(set::add));

return set;
return null;
}

/**
* @deprecated {@code armorstand} spell effect now extends {@code entity} effect and is spawned in with {@link Spell#playSpellEntityEffects(EffectPosition, Location, SpellData)}.
*/
@Deprecated(forRemoval = true)
protected Set<DelayableEntity<ArmorStand>> playSpellArmorStandEffects(EffectPosition pos, Location location, SpellData data) {
if (effects == null) return null;
List<SpellEffect> effectsList = effects.get(pos);
if (effectsList == null) return null;
Set<DelayableEntity<ArmorStand>> armorStands = new HashSet<>();
for (SpellEffect effect : effectsList) {
if (!(effect instanceof ArmorStandEffect)) continue;
DelayableEntity<ArmorStand> stand = effect.playArmorStandEffect(location, data);
if (stand == null) continue;
armorStands.add(stand);
}
return armorStands;
return null;
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,23 +345,20 @@ public final DelayableEntity<Entity> playEntityEffect(final Location location, S
return new DelayableEntity<>(loc -> playEntityEffectLocationReal(loc, finalData), location, delay.get(finalData));
}

@Nullable
@Deprecated
/**
* @deprecated {@code armorstand} spell effect now extends {@code entity} effect and is spawned in with {@link SpellEffect#playEntityEffect(Location, SpellData)}.
*/
@Deprecated(forRemoval = true)
public final ArmorStand playArmorStandEffect(final Location location) {
DelayableEntity<ArmorStand> armorStand = playArmorStandEffect(location, SpellData.NULL);
return armorStand == null ? null : armorStand.now();
return null;
}

@Nullable
/**
* @deprecated {@code armorstand} spell effect now extends {@code entity} effect and is spawned in with {@link SpellEffect#playEntityEffect(Location, SpellData)}.
*/
@Deprecated(forRemoval = true)
public final DelayableEntity<ArmorStand> playArmorStandEffect(final Location location, SpellData data) {
double chance = this.chance.get(data);
if (chance > 0 && chance < 1 && random.nextDouble() > chance) return null;

ModifierResult result = checkModifiers(data, location);
if (!result.check()) return null;

SpellData finalData = result.data();
return new DelayableEntity<>(loc -> playArmorStandEffectLocationReal(loc, finalData), location, delay.get(finalData));
return null;
}

private Runnable playEffectLocationReal(Location location, SpellData data) {
Expand All @@ -385,13 +382,6 @@ private Entity playEntityEffectLocationReal(Location location, SpellData data) {
return playEntityEffectLocation(loc, data);
}

private ArmorStand playArmorStandEffectLocationReal(Location location, SpellData data) {
if (location == null) return playArmorStandEffectLocation(null, data);
Location loc = location.clone();
applyOffsets(loc, data);
return playArmorStandEffectLocation(loc, data);
}

@Deprecated
protected Runnable playEffectLocation(Location location) {
//expect to be overridden
Expand Down Expand Up @@ -425,17 +415,6 @@ protected Entity playEntityEffectLocation(Location location, SpellData data) {
return playEntityEffectLocation(location);
}

@Deprecated
protected ArmorStand playArmorStandEffectLocation(Location location) {
//expect to be overridden
return null;
}

protected ArmorStand playArmorStandEffectLocation(Location location, SpellData data) {
//expect to be overridden
return playArmorStandEffectLocation(location);
}

@Deprecated
public void playTrackingLinePatterns(Location origin, Location target, Entity originEntity, Entity targetEntity) {
// no op, effects should override this with their own behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import com.nisovin.magicspells.util.SpellData;
import com.nisovin.magicspells.util.EntityData;
import com.nisovin.magicspells.util.config.ConfigData;
import com.nisovin.magicspells.spelleffects.SpellEffect;
import com.nisovin.magicspells.util.magicitems.MagicItem;
import com.nisovin.magicspells.util.magicitems.MagicItems;
import com.nisovin.magicspells.util.config.ConfigDataUtil;

@Name("armorstand")
public class ArmorStandEffect extends SpellEffect {
public class ArmorStandEffect extends EntityEffect {

public static final String ENTITY_TAG = "MS_ARMOR_STAND";

Expand All @@ -38,6 +37,8 @@ protected void loadFromConfig(ConfigurationSection config) {

entityData = new EntityData(section);

duration = ConfigDataUtil.getInteger(section, "duration", 0);

gravity = ConfigDataUtil.getBoolean(section, "gravity", false);
disableSlots = ConfigDataUtil.getBoolean(section, "disable-slots", true);

Expand All @@ -52,7 +53,7 @@ protected void loadFromConfig(ConfigurationSection config) {
}

@Override
protected ArmorStand playArmorStandEffectLocation(Location location, SpellData data) {
protected Entity playEntityEffectLocation(Location location, SpellData data) {
return entityData.spawn(location, data, ArmorStand.class, stand -> {
stand.setSilent(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class EntityEffect extends SpellEffect {

private EntityData entityData;

private ConfigData<Integer> duration;
protected ConfigData<Integer> duration;

private ConfigData<Boolean> gravity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.bukkit.Material;
import org.bukkit.util.Vector;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.FluidCollisionMode;

import com.nisovin.magicspells.util.*;
Expand Down Expand Up @@ -391,10 +390,6 @@ public Map<SpellEffect, DelayableEntity<Entity>> playEntityEffectsProjectile(Eff
return playSpellEntityEffects(position, location, data);
}

public Set<DelayableEntity<ArmorStand>> playArmorStandEffectsProjectile(EffectPosition position, Location location, SpellData data) {
return playSpellArmorStandEffects(position, location, data);
}

private void setupTracker(ParticleProjectileTracker tracker, SpellData data) {
tracker.setSpell(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ public Map<SpellEffect, DelayableEntity<Entity>> playEntityEffectsProjectile(Eff
return playSpellEntityEffects(position, location, data);
}

public Set<DelayableEntity<ArmorStand>> playArmorStandEffectsProjectile(EffectPosition position, Location location, SpellData data) {
return playSpellArmorStandEffects(position, location, data);
}

public static Set<ProjectileTracker> getProjectileTrackers() {
return trackerSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.bukkit.Location;
import org.bukkit.util.Vector;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.LivingEntity;

import de.slikey.effectlib.Effect;
Expand Down Expand Up @@ -202,7 +201,6 @@ private class MissileTracker implements Runnable {

private final Set<EffectlibSpellEffect> effectSet;
private final Map<SpellEffect, DelayableEntity<Entity>> entityMap;
private final Set<DelayableEntity<ArmorStand>> armorStandSet;

private final BoundingBox hitBox;
private final long startTime;
Expand Down Expand Up @@ -294,7 +292,6 @@ private MissileTracker(SpellData data) {

effectSet = playSpellEffectLibEffects(EffectPosition.PROJECTILE, currentLocation, data);
entityMap = playSpellEntityEffects(EffectPosition.PROJECTILE, currentLocation, data);
armorStandSet = playSpellArmorStandEffects(EffectPosition.PROJECTILE, currentLocation, data);

if (data.hasCaster()) playSpellEffects(EffectPosition.CASTER, data.caster(), data);

Expand Down Expand Up @@ -355,7 +352,7 @@ public void run() {
if (!force.isZero()) currentVelocity.add(force.normalize());
currentVelocity.normalize().multiply(velocityPerTick);

if (armorStandSet != null || entityMap != null) {
if (entityMap != null) {
// Changing the effect location
Vector dir = currentLocation.getDirection().normalize();
Vector offset = new Vector(-dir.getZ(), 0.0, dir.getX()).normalize();
Expand All @@ -365,17 +362,9 @@ public void run() {
effectLoc.setY(effectLoc.getY() + effectOffset.getY());
effectLoc = Util.makeFinite(effectLoc);

if (armorStandSet != null) {
for (DelayableEntity<ArmorStand> armorStand : armorStandSet) {
armorStand.teleport(effectLoc);
}
}

if (entityMap != null) {
for (var entry : entityMap.entrySet()) {
entry.getValue().teleport(entry.getKey().applyOffsets(effectLoc.clone(), data));
}
}
for (var entry : entityMap.entrySet()) {
entry.getValue().teleport(entry.getKey().applyOffsets(effectLoc.clone(), data));
}
}

if (stopOnHitGround && !currentLocation.getBlock().isPassable()) {
Expand Down Expand Up @@ -475,10 +464,6 @@ public void stop(boolean removeTracker) {
}
effectSet.clear();
}
if (armorStandSet != null) {
armorStandSet.forEach(DelayableEntity::remove);
armorStandSet.clear();
}
if (entityMap != null) {
entityMap.values().forEach(DelayableEntity::remove);
entityMap.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.util.Vector;
import org.bukkit.entity.Entity;
import org.bukkit.util.BoundingBox;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.LivingEntity;

import de.slikey.effectlib.Effect;
Expand Down Expand Up @@ -217,10 +216,9 @@ private class OrbitTracker implements Runnable {
private final Vector perpendicular;

private final Object2IntMap<UUID> immune;
private final Set<DelayableEntity<ArmorStand>> armorStandSet;
private final Predicate<Location> transparent;
private final Map<SpellEffect, DelayableEntity<Entity>> entityMap;
private final Set<EffectlibSpellEffect> effectSet;
private final Map<SpellEffect, DelayableEntity<Entity>> entityMap;

private final boolean followYaw;
private final boolean followPitch;
Expand Down Expand Up @@ -318,7 +316,6 @@ private OrbitTracker(SpellData data) {

entityMap = playSpellEntityEffects(EffectPosition.PROJECTILE, center, data);
effectSet = playSpellEffectLibEffects(EffectPosition.PROJECTILE, center, data);
armorStandSet = playSpellArmorStandEffects(EffectPosition.PROJECTILE, center, data);

if (data.hasTarget()) playSpellEffects(data.caster(), data.target(), data);
else playSpellEffects(data.caster(), center, data);
Expand Down Expand Up @@ -367,12 +364,6 @@ public void run() {
}
}

if (armorStandSet != null) {
for (DelayableEntity<ArmorStand> armorStand : armorStandSet) {
armorStand.teleport(currentLocation);
}
}

if (entityMap != null) {
for (var entry : entityMap.entrySet()) {
entry.getValue().teleport(entry.getKey().applyOffsets(currentLocation.clone(), data));
Expand Down Expand Up @@ -513,11 +504,6 @@ private void stop(boolean removeTracker) {
effectSet.clear();
}

if (armorStandSet != null) {
armorStandSet.forEach(DelayableEntity::remove);
armorStandSet.clear();
}

if (entityMap != null) {
entityMap.values().forEach(DelayableEntity::remove);
entityMap.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.ApiStatus;

import io.papermc.paper.math.Rotations;

import java.util.function.Function;
import java.util.function.Consumer;
import java.util.concurrent.CompletableFuture;
Expand All @@ -12,6 +14,7 @@

import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ArmorStand;

import com.nisovin.magicspells.MagicSpells;

Expand Down Expand Up @@ -71,8 +74,16 @@ public void accept(@NotNull Consumer<E> consumer) {
*/
public void teleport(@NotNull Location location) {
E entity = now();
if (entity == null) spawnLocation = location;
else entity.teleportAsync(location);

if (entity == null) {
spawnLocation = location;
return;
}

entity.teleportAsync(location);

if (!(entity instanceof ArmorStand stand)) return;
stand.setHeadRotations(Rotations.ZERO.withX(entity.getPitch()));
}

/**
Expand Down Expand Up @@ -107,7 +118,7 @@ public DelayableEntity(@NotNull Function<Location, E> function, @NotNull Locatio
else taskId = MagicSpells.scheduleDelayedTask(spawnEntity, delay);

int id = taskId;
future.whenComplete((result, throwable) -> {
future.whenComplete((_, throwable) -> {
if (future.isCancelled() && id != -1) MagicSpells.cancelTask(id);
if (throwable == null) return;
MagicSpells.handleException(new Exception("Delayed entity failed to spawn", throwable));
Expand Down
Loading
Loading