From 6f343c5fc0c7e5da634a6e4565cc9c4bce62e7dc Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 9 Mar 2024 23:43:21 +0100 Subject: [PATCH] Fix viewers mutating after submitting async packet sending --- .../{DelegateViewers.java => ImmutableViewers.java} | 7 ++++--- .../holographicdisplays/core/tracking/LineTracker.java | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) rename core/src/main/java/me/filoghost/holographicdisplays/core/tracking/{DelegateViewers.java => ImmutableViewers.java} (65%) diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/DelegateViewers.java b/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/ImmutableViewers.java similarity index 65% rename from core/src/main/java/me/filoghost/holographicdisplays/core/tracking/DelegateViewers.java rename to core/src/main/java/me/filoghost/holographicdisplays/core/tracking/ImmutableViewers.java index b240a7ad..4de646f5 100644 --- a/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/DelegateViewers.java +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/ImmutableViewers.java @@ -5,15 +5,16 @@ */ package me.filoghost.holographicdisplays.core.tracking; +import java.util.ArrayList; import java.util.Collection; import java.util.function.Consumer; -public class DelegateViewers implements Viewers { +public class ImmutableViewers implements Viewers { private final Collection viewers; - public DelegateViewers(Collection viewers) { - this.viewers = viewers; + public ImmutableViewers(Collection viewers) { + this.viewers = new ArrayList<>(viewers); } @Override diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/LineTracker.java b/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/LineTracker.java index 5ac3e470..4928dad4 100644 --- a/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/LineTracker.java +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/tracking/LineTracker.java @@ -22,7 +22,6 @@ import java.util.concurrent.ConcurrentMap; public abstract class LineTracker { private final ConcurrentMap viewers; - private final Viewers iterableViewers; private String positionWorldName; protected PositionCoordinates positionCoordinates; @@ -33,7 +32,6 @@ public abstract class LineTracker { protected LineTracker() { this.viewers = new ConcurrentHashMap<>(); - this.iterableViewers = new DelegateViewers<>(viewers.values()); } protected abstract BaseHologramLine getLine(); @@ -67,7 +65,7 @@ public abstract class LineTracker { // Then, send the changes (if any) to already tracked players if (sendChangesPackets && hasViewers()) { - sendChangesPackets(iterableViewers); + sendChangesPackets(new ImmutableViewers<>(viewers.values())); } // Finally, add/remove viewers sending them the full spawn/destroy packets @@ -223,7 +221,7 @@ public abstract class LineTracker { return; } - sendDestroyPackets(iterableViewers); + sendDestroyPackets(new ImmutableViewers<>(viewers.values())); viewers.clear(); }