Skip to content
Open

Fixes #1095

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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nisovin.magicspells.spelleffects.effecttypes;

import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.EquipmentSlot;
Expand Down Expand Up @@ -54,7 +55,6 @@ protected void loadFromConfig(ConfigurationSection config) {
protected ArmorStand playArmorStandEffectLocation(Location location, SpellData data) {
return entityData.spawn(location, data, ArmorStand.class, stand -> {
stand.setSilent(true);
stand.addScoreboardTag(ENTITY_TAG);

stand.setGravity(gravity.get(data));
if (disableSlots.get(data)) stand.setDisabledSlots(EquipmentSlot.values());
Expand All @@ -63,9 +63,14 @@ protected ArmorStand playArmorStandEffectLocation(Location location, SpellData d
stand.setItem(EquipmentSlot.HAND, mainhandItem);
stand.setItem(EquipmentSlot.OFF_HAND, offhandItem);
}, stand -> {
stand.setPersistent(false);
Util.forEachPassenger(stand, e -> e.setPersistent(false));
postSpawn(stand);
Util.forEachPassenger(stand, this::postSpawn);
});
}

private void postSpawn(Entity entity) {
entity.setPersistent(false);
entity.addScoreboardTag(ENTITY_TAG);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ protected void loadFromConfig(ConfigurationSection config) {
@Override
protected Entity playEntityEffectLocation(Location location, SpellData data) {
return entityData.spawn(location, data, entity -> {
entity.addScoreboardTag(ENTITY_TAG);
entity.setGravity(gravity.get(data));
}, entity -> {
entity.setPersistent(false);
Util.forEachPassenger(entity, e -> e.setPersistent(false));
postSpawn(entity);
Util.forEachPassenger(entity, this::postSpawn);
});
}

private void postSpawn(Entity entity) {
entity.setPersistent(false);
entity.addScoreboardTag(ENTITY_TAG);
}

@Override
public Runnable playEffectLocation(Location location, SpellData data) {
Entity entity = playEntityEffectLocation(location, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.nisovin.magicspells.util.config.ConfigData;
import com.nisovin.magicspells.spelleffects.SpellEffect;
import com.nisovin.magicspells.castmodifiers.ModifierSet;
import com.nisovin.magicspells.util.config.ConfigDataUtil;
import com.nisovin.magicspells.spelleffects.EffectPosition;
import com.nisovin.magicspells.spells.TargetedLocationSpell;
import com.nisovin.magicspells.util.trackers.ProjectileTracker;
Expand Down Expand Up @@ -70,6 +69,7 @@ public class ProjectileSpell extends InstantSpell implements TargetedLocationSpe
private final ConfigData<Component> projectileName;

private final ConfigData<Color> arrowColor;
private final ConfigData<Color> potionColor;

private Subspell hitSpell;
private Subspell tickSpell;
Expand Down Expand Up @@ -122,7 +122,8 @@ public ProjectileSpell(MagicConfig config, String spellName) {

projectileName = getConfigDataComponent("projectile-name", null);

arrowColor = ConfigDataUtil.getColor(config.getMainConfig(), internalKey + "arrow-color", null);
arrowColor = getConfigDataColor("arrow-color", null);
potionColor = getConfigDataColor("potion-color", null);

projectileModifiersStrings = getConfigStringList("projectile-modifiers", null);
}
Expand Down Expand Up @@ -221,6 +222,7 @@ private void setupTracker(ProjectileTracker tracker, SpellData data) {
tracker.setProjectileName(projectileName.get(data));

tracker.setArrowColor(arrowColor.get(data));
tracker.setPotionColor(potionColor.get(data));

tracker.setHitSpell(hitSpell);
tracker.setTickSpell(tickSpell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.nisovin.magicspells.castmodifiers.ModifierSet;
import com.nisovin.magicspells.events.SpellPreImpactEvent;
import com.nisovin.magicspells.spells.TargetedEntitySpell;
import com.nisovin.magicspells.util.config.ConfigDataUtil;
import com.nisovin.magicspells.spelleffects.EffectPosition;
import com.nisovin.magicspells.util.projectile.ProjectileManager;
import com.nisovin.magicspells.util.projectile.ProjectileManagers;
Expand Down Expand Up @@ -63,6 +62,7 @@ public class HomingProjectileSpell extends TargetedSpell implements TargetedEnti
private final ConfigData<Component> projectileName;

private final ConfigData<Color> arrowColor;
private final ConfigData<Color> potionColor;

private final String hitSpellName;
private final String airSpellName;
Expand All @@ -86,7 +86,8 @@ public HomingProjectileSpell(MagicConfig config, String spellName) {

projectileType = getConfigDataString("projectile-type", "arrow");

arrowColor = ConfigDataUtil.getColor(config.getMainConfig(), internalKey + "arrow-color", null);
arrowColor = getConfigDataColor("arrow-color", null);
potionColor = getConfigDataColor("potion-color", null);

relativeOffset = getConfigDataVector("relative-offset", new Vector(0.5, 0.5, 0));
targetRelativeOffset = getConfigDataVector("target-relative-offset", new Vector(0, 0.5, 0));
Expand Down Expand Up @@ -279,7 +280,7 @@ private HomingProjectileMonitor(SpellData data) {
if (proj instanceof WitherSkull witherSkull) witherSkull.setCharged(charged.get(finalData));
if (proj instanceof Explosive explosive) explosive.setIsIncendiary(incendiary.get(finalData));
if (proj instanceof ProjectileManagerThrownPotion potion) {
((ThrownPotion) proj).setItem(potion.getItem());
((ThrownPotion) proj).setItem(potion.getPotion(potionColor.get(finalData)));
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.nisovin.magicspells.spells.targeted;

import java.util.Map;
import java.util.UUID;
import java.util.List;
import java.util.HashMap;

import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.*;
import org.bukkit.util.Vector;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.Particle.DustOptions;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.Particle.DustTransition;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;

import org.jetbrains.annotations.NotNull;

Expand All @@ -23,12 +26,17 @@
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.spells.TargetedSpell;
import com.nisovin.magicspells.util.config.ConfigData;
import com.nisovin.magicspells.events.SpellTargetEvent;
import com.nisovin.magicspells.spells.TargetedEntitySpell;
import com.nisovin.magicspells.util.config.ConfigDataUtil;
import com.nisovin.magicspells.spells.TargetedLocationSpell;

import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent;

public class ParticleCloudSpell extends TargetedSpell implements TargetedLocationSpell, TargetedEntitySpell {

private final Map<UUID, SpellData> clouds = new HashMap<>();

private final ConfigData<Vector> relativeOffset;

private final ConfigData<Component> customName;
Expand Down Expand Up @@ -67,6 +75,8 @@ public class ParticleCloudSpell extends TargetedSpell implements TargetedLocatio
private final ConfigData<Boolean> canTargetEntities;
private final ConfigData<Boolean> canTargetLocation;

private final boolean removeCloud;

private final List<ConfigData<PotionEffect>> potionEffects;

public ParticleCloudSpell(MagicConfig config, String spellName) {
Expand Down Expand Up @@ -129,13 +139,26 @@ public ParticleCloudSpell(MagicConfig config, String spellName) {
radiusOnUse = getConfigDataFloat("radius-on-use", 0F);
radiusPerTick = getConfigDataFloat("radius-per-tick", 0F);

removeCloud = getConfigBoolean("remove-cloud", false);

useGravity = getConfigDataBoolean("use-gravity", false);
canTargetEntities = getConfigDataBoolean("can-target-entities", true);
canTargetLocation = getConfigDataBoolean("can-target-location", true);

potionEffects = Util.getPotionEffects(getConfigList("potion-effects", null), internalName);
}

@Override
protected void turnOff() {
if (removeCloud) {
for (UUID uuid : clouds.keySet()) {
Entity cloud = Bukkit.getEntity(uuid);
if (cloud != null) cloud.remove();
}
}
clouds.clear();
}

@Override
public CastResult cast(SpellData data) {
if (canTargetEntities.get(data)) {
Expand Down Expand Up @@ -203,12 +226,30 @@ private CastResult spawnCloud(SpellData data) {
cloud.customName(customName);
cloud.setCustomNameVisible(true);
}

clouds.put(cloud.getUniqueId(), finalData);
});

playSpellEffects(data);
return new CastResult(PostCastAction.HANDLE_NORMALLY, data);
}

@EventHandler(ignoreCancelled = true)
public void onEffectApply(AreaEffectCloudApplyEvent event) {
SpellData data = clouds.get(event.getEntity().getUniqueId());
if (data == null) return;

event.getAffectedEntities().removeIf(entity -> {
SpellTargetEvent targetEvent = new SpellTargetEvent(this, data.target(entity));
return !targetEvent.callEvent();
});
}

@EventHandler(ignoreCancelled = true)
public void onRemove(EntityRemoveFromWorldEvent event) {
clouds.remove(event.getEntity().getUniqueId());
}

private Object getParticleData(@NotNull Particle particle, @NotNull SpellData data) {
Object nmsData = MagicSpells.getVolatileCodeHandler().getVolatileParticleData(
particle,
Expand Down
17 changes: 9 additions & 8 deletions core/src/main/java/com/nisovin/magicspells/util/EntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class EntityData {

private final Multimap<EntityType, Transformer<?>> options = MultimapBuilder.enumKeys(EntityType.class).arrayListValues().build();
private final List<DelayedEntityData> delayedEntityData = new ArrayList<>();
private final List<EntityData> passengers = new ArrayList<>();

private ConfigData<EntityType> entityType;

Expand Down Expand Up @@ -797,14 +798,7 @@ public EntityData(ConfigurationSection config, boolean forceOptional) {
// Passengers
for (Object object : config.getList("passengers", new ArrayList<>())) {
if (!(object instanceof Map<?, ?> map)) continue;
EntityData passengerData = new EntityData(ConfigReaderUtil.mapToSection(map));

transformers.put(Entity.class, (Entity entity, SpellData data) -> {
passengerData.spawn(entity.getLocation(), data, passenger -> {
entity.addPassenger(passenger);
passenger.getPersistentDataContainer().set(MS_PASSENGER, PersistentDataType.BOOLEAN, true);
});
});
passengers.add(new EntityData(ConfigReaderUtil.mapToSection(map)));
}

// Mob Goals
Expand Down Expand Up @@ -956,6 +950,13 @@ public <T extends Entity> T spawn(@NotNull Location location, @NotNull SpellData
spawnLocation.setPitch(pitch.get(data).apply(spawnLocation.getPitch()));

return spawnLocation.getWorld().spawn(spawnLocation, entityClass, entity -> {
for (EntityData passengerData : passengers) {
passengerData.spawn(entity.getLocation(), data, passenger -> {
entity.addPassenger(passenger);
passenger.getPersistentDataContainer().set(MS_PASSENGER, PersistentDataType.BOOLEAN, true);
});
}

if (preConsumer != null) preConsumer.accept(entity);

apply(entity, data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.nisovin.magicspells.util.managers;

import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.HashMap;
import java.util.*;
import java.util.function.Consumer;

import com.google.common.collect.SetMultimap;
Expand Down Expand Up @@ -83,18 +80,16 @@ public void stop() {
public void accept(ScheduledTask scheduledTask) {
NoMagicZoneManager zoneManager = MagicSpells.getNoMagicZoneManager();

activeBuffs.entries().removeIf(entry -> {
for (Map.Entry<UUID, BuffSpell> entry : new HashSet<>(activeBuffs.entries())) {
UUID uuid = entry.getKey();
LivingEntity entity = Bukkit.getEntity(uuid) instanceof LivingEntity le ? le : lastEntity.get(uuid);

BuffSpell buff = entry.getValue();
if ((entity instanceof Player || entity.isValid()) && !buff.isExpired(entity) && !zoneManager.willFizzle(entity, buff))
return false;
continue;

buff.turnOff(entity, false);
new BuffEndEvent(entity, buff).callEvent();
return true;
});
endBuff(entity, buff);
}
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

public class ProjectileManagerLingeringPotion extends ProjectileManagerThrownPotion {

private static final ItemStack POTION = new ItemStack(Material.LINGERING_POTION);

@NotNull
@Override
public ItemStack getItem() {
return POTION;
protected ItemStack getItem() {
return new ItemStack(Material.LINGERING_POTION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

public class ProjectileManagerSplashPotion extends ProjectileManagerThrownPotion {

private static final ItemStack POTION = new ItemStack(Material.SPLASH_POTION);

@NotNull
@Override
public ItemStack getItem() {
return POTION;
protected ItemStack getItem() {
return new ItemStack(Material.SPLASH_POTION);
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package com.nisovin.magicspells.util.projectile;

import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ProjectileManagerThrownPotion extends ProjectileManager {

private static final ItemStack POTION = new ItemStack(Material.POTION);

@Override
public Class<? extends Projectile> getProjectileClass() {
return ThrownPotion.class;
}

@NotNull
public ItemStack getItem() {
return POTION;
protected ItemStack getItem() {
return new ItemStack(Material.POTION);
}

@NotNull
public final ItemStack getPotion(@Nullable Color color) {
ItemStack potion = getItem();
if (color != null) potion.editMeta(PotionMeta.class, p -> p.setColor(color));
return potion;
}

}
Loading
Loading