mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-19 15:27:45 +01:00
Fix viewers mutating after submitting async packet sending
This commit is contained in:
parent
9dcf6035fe
commit
6f343c5fc0
@ -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<T extends Viewer> implements Viewers<T> {
|
||||
public class ImmutableViewers<T extends Viewer> implements Viewers<T> {
|
||||
|
||||
private final Collection<T> viewers;
|
||||
|
||||
public DelegateViewers(Collection<T> viewers) {
|
||||
this.viewers = viewers;
|
||||
public ImmutableViewers(Collection<T> viewers) {
|
||||
this.viewers = new ArrayList<>(viewers);
|
||||
}
|
||||
|
||||
@Override
|
@ -22,7 +22,6 @@ import java.util.concurrent.ConcurrentMap;
|
||||
public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
private final ConcurrentMap<Player, T> viewers;
|
||||
private final Viewers<T> iterableViewers;
|
||||
|
||||
private String positionWorldName;
|
||||
protected PositionCoordinates positionCoordinates;
|
||||
@ -33,7 +32,6 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
protected LineTracker() {
|
||||
this.viewers = new ConcurrentHashMap<>();
|
||||
this.iterableViewers = new DelegateViewers<>(viewers.values());
|
||||
}
|
||||
|
||||
protected abstract BaseHologramLine getLine();
|
||||
@ -67,7 +65,7 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
// 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<T extends Viewer> {
|
||||
return;
|
||||
}
|
||||
|
||||
sendDestroyPackets(iterableViewers);
|
||||
sendDestroyPackets(new ImmutableViewers<>(viewers.values()));
|
||||
viewers.clear();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user