Skip to content
Merged
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 @@ -68,19 +68,17 @@ public void turnOffBuff(LivingEntity entity) {
protected void turnOff() {
super.turnOff();

if (manager == null) return;
manager.stop();
manager = null;
if (manager != null) manager.stop();
}

@Override
protected @NotNull Collection<UUID> getActiveEntities() {
return manager.entities.keySet();
return manager != null ? manager.getActiveEntities(this) : Collections.emptyList();
}

private static class InvisibilityManager implements Listener {

private final Object2ObjectArrayMap<UUID, InvisibilityData> entities = new Object2ObjectArrayMap<>();
private final Map<UUID, InvisibilityData> entities = new Object2ObjectArrayMap<>();

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

public Collection<UUID> getActiveEntities(InvisibilitySpell spell) {
return entities.entrySet().stream()
.filter(entry -> entry.getValue().spells.containsKey(spell.internalName))
.map(Map.Entry::getKey)
.toList();
}

public void turnOffBuff(InvisibilitySpell spell, LivingEntity entity) {
UUID uuid = entity.getUniqueId();
InvisibilityData data = entities.get(uuid);
Expand All @@ -136,7 +141,10 @@ public void turnOffBuff(InvisibilitySpell spell, LivingEntity entity) {
}

public void stop() {
entities.clear();
// Only stop if all other InvisibilitySpell instances with active casts have been turned off.
if (!entities.isEmpty()) return;

InvisibilitySpell.manager = null;
HandlerList.unregisterAll(this);
}

Expand Down