13
0
geforkt von Mirrors/Velocity

Map command nodes being serialized by their identities

Fixes #429
Dieser Commit ist enthalten in:
Andrew Steinborn 2021-02-16 01:14:22 -05:00
Ursprung 2a8a982538
Commit b94303d2be
2 geänderte Dateien mit 28 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,9 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertyRegistry;
import com.velocitypowered.proxy.util.collect.IdentityHashStrategy;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenCustomHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import java.util.ArrayDeque;
@ -96,7 +98,8 @@ public class AvailableCommands implements MinecraftPacket {
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
// Assign all the children an index.
Deque<CommandNode<CommandSource>> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode));
Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenHashMap<>();
Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenCustomHashMap<>(
IdentityHashStrategy.instance());
while (!childrenQueue.isEmpty()) {
CommandNode<CommandSource> child = childrenQueue.poll();
if (!idMappings.containsKey(child)) {

Datei anzeigen

@ -0,0 +1,24 @@
package com.velocitypowered.proxy.util.collect;
import it.unimi.dsi.fastutil.Hash.Strategy;
public final class IdentityHashStrategy<T> implements Strategy<T> {
@SuppressWarnings("rawtypes")
private static final IdentityHashStrategy INSTANCE = new IdentityHashStrategy();
public static <T> Strategy<T> instance() {
//noinspection unchecked
return INSTANCE;
}
@Override
public int hashCode(T o) {
return System.identityHashCode(o);
}
@Override
public boolean equals(T a, T b) {
return a == b;
}
}