Skip to content

Commit 2a81915

Browse files
Fix turning off
1 parent 8797c03 commit 2a81915

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

core/src/main/java/com/nisovin/magicspells/spells/buff/InvisibilitySpell.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,17 @@ public void turnOffBuff(LivingEntity entity) {
6868
protected void turnOff() {
6969
super.turnOff();
7070

71-
if (manager == null) return;
72-
manager.stop();
73-
manager = null;
71+
if (manager != null) manager.stop();
7472
}
7573

7674
@Override
7775
protected @NotNull Collection<UUID> getActiveEntities() {
78-
return manager.entities.keySet();
76+
return manager != null ? manager.getActiveEntities(this) : Collections.emptyList();
7977
}
8078

8179
private static class InvisibilityManager implements Listener {
8280

83-
private final Object2ObjectArrayMap<UUID, InvisibilityData> entities = new Object2ObjectArrayMap<>();
81+
private final Map<UUID, InvisibilityData> entities = new Object2ObjectArrayMap<>();
8482

8583
public InvisibilityManager() {
8684
MagicSpells.registerEvents(this);
@@ -111,6 +109,13 @@ public boolean isActive(InvisibilitySpell spell, LivingEntity entity) {
111109
return data != null && data.spells.containsKey(spell.internalName);
112110
}
113111

112+
public Collection<UUID> getActiveEntities(InvisibilitySpell spell) {
113+
return entities.entrySet().stream()
114+
.filter(entry -> entry.getValue().spells.containsKey(spell.internalName))
115+
.map(Map.Entry::getKey)
116+
.toList();
117+
}
118+
114119
public void turnOffBuff(InvisibilitySpell spell, LivingEntity entity) {
115120
UUID uuid = entity.getUniqueId();
116121
InvisibilityData data = entities.get(uuid);
@@ -136,7 +141,10 @@ public void turnOffBuff(InvisibilitySpell spell, LivingEntity entity) {
136141
}
137142

138143
public void stop() {
139-
entities.clear();
144+
// Only stop if all other InvisibilitySpell instances with active casts have been turned off.
145+
if (!entities.isEmpty()) return;
146+
147+
InvisibilitySpell.manager = null;
140148
HandlerList.unregisterAll(this);
141149
}
142150

0 commit comments

Comments
 (0)