mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 02:57:37 +01:00
Update VIEWABLE_STORAGE_MAP as compute
is no longer required
This commit is contained in:
parent
2608071ee4
commit
0ca5e2ade6
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.utils;
|
package net.minestom.server.utils;
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
@ -31,7 +32,6 @@ import java.nio.BufferUnderflowException;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
@ -54,7 +54,7 @@ public final class PacketUtils {
|
|||||||
public static final boolean VIEWABLE_PACKET = getBoolean("minestom.viewable-packet", true);
|
public static final boolean VIEWABLE_PACKET = getBoolean("minestom.viewable-packet", true);
|
||||||
|
|
||||||
// Viewable packets
|
// Viewable packets
|
||||||
private static final ConcurrentMap<Viewable, ViewableStorage> VIEWABLE_STORAGE_MAP = ConcurrentMap.class.cast(Caffeine.newBuilder().weakKeys().build().asMap());
|
private static final Cache<Viewable, ViewableStorage> VIEWABLE_STORAGE_MAP = Caffeine.newBuilder().weakKeys().build();
|
||||||
|
|
||||||
private PacketUtils() {
|
private PacketUtils() {
|
||||||
}
|
}
|
||||||
@ -139,11 +139,8 @@ public final class PacketUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player exception = entity instanceof Player ? (Player) entity : null;
|
final Player exception = entity instanceof Player ? (Player) entity : null;
|
||||||
VIEWABLE_STORAGE_MAP.compute(viewable, (v, storage) -> {
|
ViewableStorage storage = VIEWABLE_STORAGE_MAP.get(viewable, (unused) -> new ViewableStorage());
|
||||||
if (storage == null) storage = new ViewableStorage();
|
storage.append(viewable, serverPacket, exception);
|
||||||
storage.append(v, serverPacket, exception);
|
|
||||||
return storage;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Experimental
|
@ApiStatus.Experimental
|
||||||
@ -154,7 +151,7 @@ public final class PacketUtils {
|
|||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public static void flush() {
|
public static void flush() {
|
||||||
if (VIEWABLE_PACKET) {
|
if (VIEWABLE_PACKET) {
|
||||||
VIEWABLE_STORAGE_MAP.entrySet().parallelStream().forEach(entry ->
|
VIEWABLE_STORAGE_MAP.asMap().entrySet().parallelStream().forEach(entry ->
|
||||||
entry.getValue().process(entry.getKey()));
|
entry.getValue().process(entry.getKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user