forked from GeyserMC/Geyser
Fix exception when removing all entities
This commit is contained in:
parent
cc0b3293bf
commit
8efeb3fe25
2 changed files with 10 additions and 14 deletions
|
@ -25,10 +25,7 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network.session.cache;
|
package org.geysermc.connector.network.session.cache;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2LongMap;
|
import it.unimi.dsi.fastutil.longs.*;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.entity.PlayerEntity;
|
import org.geysermc.connector.entity.PlayerEntity;
|
||||||
|
@ -45,9 +42,9 @@ public class EntityCache {
|
||||||
private GeyserSession session;
|
private GeyserSession session;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Long2ObjectMap<Entity> entities = new Long2ObjectOpenHashMap<>();
|
private Long2ObjectMap<Entity> entities = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>());
|
||||||
private Long2LongMap entityIdTranslations = new Long2LongOpenHashMap();
|
private Long2LongMap entityIdTranslations = Long2LongMaps.synchronize(new Long2LongOpenHashMap());
|
||||||
private Map<UUID, PlayerEntity> playerEntities = new HashMap<>();
|
private Map<UUID, PlayerEntity> playerEntities = Collections.synchronizedMap(new HashMap<>());
|
||||||
private Map<UUID, Long> bossbars = new HashMap<>();
|
private Map<UUID, Long> bossbars = new HashMap<>();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
|
@ -6,6 +6,9 @@ import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.TranslatorsInit;
|
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DimensionUtils {
|
public class DimensionUtils {
|
||||||
public static void switchDimension(GeyserSession session, int javaDimension, boolean fake) {
|
public static void switchDimension(GeyserSession session, int javaDimension, boolean fake) {
|
||||||
int bedrockDimension = javaToBedrock(javaDimension);
|
int bedrockDimension = javaToBedrock(javaDimension);
|
||||||
|
@ -15,13 +18,9 @@ public class DimensionUtils {
|
||||||
|
|
||||||
Vector3i pos = Vector3i.from(0, 32767, 0);
|
Vector3i pos = Vector3i.from(0, 32767, 0);
|
||||||
|
|
||||||
//FIXME: chance of exception while iterating
|
List<Entity> entities = new ArrayList<>(session.getEntityCache().getEntities().values());
|
||||||
try {
|
for (Entity entity : entities) {
|
||||||
for (Entity entity : session.getEntityCache().getEntities().values()) {
|
session.getEntityCache().removeEntity(entity, false);
|
||||||
session.getEntityCache().removeEntity(entity, false);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket();
|
ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket();
|
||||||
|
|
Loading…
Reference in a new issue