mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-24 01:37:35 +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;
|
package me.filoghost.holographicdisplays.core.tracking;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Consumer;
|
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;
|
private final Collection<T> viewers;
|
||||||
|
|
||||||
public DelegateViewers(Collection<T> viewers) {
|
public ImmutableViewers(Collection<T> viewers) {
|
||||||
this.viewers = viewers;
|
this.viewers = new ArrayList<>(viewers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -22,7 +22,6 @@ import java.util.concurrent.ConcurrentMap;
|
|||||||
public abstract class LineTracker<T extends Viewer> {
|
public abstract class LineTracker<T extends Viewer> {
|
||||||
|
|
||||||
private final ConcurrentMap<Player, T> viewers;
|
private final ConcurrentMap<Player, T> viewers;
|
||||||
private final Viewers<T> iterableViewers;
|
|
||||||
|
|
||||||
private String positionWorldName;
|
private String positionWorldName;
|
||||||
protected PositionCoordinates positionCoordinates;
|
protected PositionCoordinates positionCoordinates;
|
||||||
@ -33,7 +32,6 @@ public abstract class LineTracker<T extends Viewer> {
|
|||||||
|
|
||||||
protected LineTracker() {
|
protected LineTracker() {
|
||||||
this.viewers = new ConcurrentHashMap<>();
|
this.viewers = new ConcurrentHashMap<>();
|
||||||
this.iterableViewers = new DelegateViewers<>(viewers.values());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract BaseHologramLine getLine();
|
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
|
// Then, send the changes (if any) to already tracked players
|
||||||
if (sendChangesPackets && hasViewers()) {
|
if (sendChangesPackets && hasViewers()) {
|
||||||
sendChangesPackets(iterableViewers);
|
sendChangesPackets(new ImmutableViewers<>(viewers.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, add/remove viewers sending them the full spawn/destroy packets
|
// Finally, add/remove viewers sending them the full spawn/destroy packets
|
||||||
@ -223,7 +221,7 @@ public abstract class LineTracker<T extends Viewer> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendDestroyPackets(iterableViewers);
|
sendDestroyPackets(new ImmutableViewers<>(viewers.values()));
|
||||||
viewers.clear();
|
viewers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user