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
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRemoveEvent;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;

import com.nisovin.magicspells.Perm;
import com.nisovin.magicspells.Spell;
import com.nisovin.magicspells.util.Util;
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.util.EntityData;
import com.nisovin.magicspells.events.SpellTargetEvent;
import com.nisovin.magicspells.zones.NoMagicZoneManager;
import com.nisovin.magicspells.spelleffects.effecttypes.*;
Expand Down Expand Up @@ -59,6 +64,26 @@ public void onEntityDamage(EntityDamageEvent event) {
event.setCancelled(true);
}

@EventHandler
public void onEntityRemove(EntityRemoveEvent event) {
Util.forEachPassenger(event.getEntity(), passenger -> {
PersistentDataContainer container = passenger.getPersistentDataContainer();
if (!container.has(EntityData.MS_PASSENGER)) return;

if (passenger.isPersistent()) {
container.remove(EntityData.MS_PASSENGER);
return;
}

passenger.remove();
});
}

@EventHandler
public void onEntityDismount(EntityDismountEvent event) {
event.getEntity().getPersistentDataContainer().remove(EntityData.MS_PASSENGER);
}

private boolean isMSEntity(Entity entity) {
return entity.getScoreboardTags().contains(ArmorStandEffect.ENTITY_TAG) || entity.getScoreboardTags().contains(EntityEffect.ENTITY_TAG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.configuration.ConfigurationSection;

import com.nisovin.magicspells.util.Name;
import com.nisovin.magicspells.util.Util;
import com.nisovin.magicspells.util.SpellData;
import com.nisovin.magicspells.util.EntityData;
import com.nisovin.magicspells.util.config.ConfigData;
Expand All @@ -23,6 +24,7 @@ public class ArmorStandEffect extends SpellEffect {
private EntityData entityData;

private ConfigData<Boolean> gravity;
private ConfigData<Boolean> disableSlots;

private ItemStack headItem;
private ItemStack offhandItem;
Expand All @@ -36,6 +38,7 @@ protected void loadFromConfig(ConfigurationSection config) {
entityData = new EntityData(section);

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

MagicItem item = MagicItems.getMagicItemFromString(section.getString("head"));
if (item != null) headItem = item.getItemStack();
Expand All @@ -54,11 +57,15 @@ protected ArmorStand playArmorStandEffectLocation(Location location, SpellData d
stand.addScoreboardTag(ENTITY_TAG);

stand.setGravity(gravity.get(data));
if (disableSlots.get(data)) stand.setDisabledSlots(EquipmentSlot.values());

stand.setItem(EquipmentSlot.HEAD, headItem);
stand.setItem(EquipmentSlot.HAND, mainhandItem);
stand.setItem(EquipmentSlot.OFF_HAND, offhandItem);
}, stand -> stand.setPersistent(false));
}, stand -> {
stand.setPersistent(false);
Util.forEachPassenger(stand, e -> e.setPersistent(false));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.configuration.ConfigurationSection;

import com.nisovin.magicspells.util.Name;
import com.nisovin.magicspells.util.Util;
import com.nisovin.magicspells.MagicSpells;
import com.nisovin.magicspells.util.SpellData;
import com.nisovin.magicspells.util.EntityData;
Expand Down Expand Up @@ -45,7 +46,10 @@ 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));
}, entity -> {
entity.setPersistent(false);
Util.forEachPassenger(entity, e -> e.setPersistent(false));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ public boolean castBuff(SpellData data) {
if (baby.get(data)) ageable.setBaby();
else ageable.setAdult();
});
else minion = entityData.spawn(loc, data, mobClass, mob -> prepareMob(mob, target, data), null);
else minion = entityData.spawn(loc, data, mobClass, mob -> prepareMob(mob, target, data), mob -> {
mob.setPersistent(false);
Util.forEachPassenger(mob, e -> e.setPersistent(false));
});

if (spawnSpell != null) {
SpellData castData = data.builder().caster(target).target(minion).location(minion.getLocation()).recipient(null).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.nisovin.magicspells.spells.targeted;

import org.bukkit.entity.LivingEntity;

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.spells.TargetedSpell;
import com.nisovin.magicspells.spells.TargetedEntitySpell;

public class ApplyEntityDataSpell extends TargetedSpell implements TargetedEntitySpell {

private final EntityData entityData;

public ApplyEntityDataSpell(MagicConfig config, String spellName) {
super(config, spellName);

entityData = new EntityData(getConfigSection("entity"), true);
}

@Override
public CastResult cast(SpellData data) {
TargetInfo<LivingEntity> info = getTargetedEntity(data);
if (info.noTarget()) return noTarget(info);

return castAtEntity(info.spellData());
}

@Override
public CastResult castAtEntity(SpellData data) {
entityData.apply(data.target(), data);

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.nisovin.magicspells.spells.targeted;

import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;

import com.nisovin.magicspells.util.*;
import com.nisovin.magicspells.spells.TargetedSpell;
import com.nisovin.magicspells.spells.TargetedEntitySpell;

public class EntityRemoveSpell extends TargetedSpell implements TargetedEntitySpell {

public EntityRemoveSpell(MagicConfig config, String spellName) {
super(config, spellName);
}

@Override
public CastResult cast(SpellData data) {
TargetInfo<LivingEntity> info = getTargetedEntity(data);
if (info.noTarget()) return noTarget(info);

return castAtEntity(info.spellData());
}

@Override
public CastResult castAtEntity(SpellData data) {
if (data.target() instanceof Player) return noTarget(data);

data.target().remove();

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,11 @@ private CastResult spawnMob(Location source, SpellData data) {
}

SpellData finalData = data;
Entity entity = entityData.spawn(loc, data,
mob -> prepMob(mob, finalData),
mob -> mob.setPersistent(!removeMob)
);
Entity entity = entityData.spawn(loc, data, mob -> prepMob(mob, finalData), mob -> {
if (!removeMob) return;
mob.setPersistent(false);
Util.forEachPassenger(mob, e -> e.setPersistent(false));
});
if (entity == null) return noTarget(data);

UUID uuid = entity.getUniqueId();
Expand Down
Loading