Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down Expand Up @@ -95,7 +96,7 @@ public void processLegacy(LegacyPlayerListItemPacket packet) {
entry.setLatencyInternal(item.getLatency());
}
} else {
UUID uuid = UUID.randomUUID(); // Use a fake uuid to preserve function of custom entries
UUID uuid = generateInsecureRandomUuid(); // Use a fake uuid to preserve function of custom entries
nameMapping.put(item.getName(), uuid);
entries.put(uuid, (KeyedVelocityTabListEntry) TabListEntry.builder()
.tabList(this)
Expand Down Expand Up @@ -153,4 +154,17 @@ public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayN
int gameMode, @Nullable ChatSession chatSession, boolean listed, int listOrder, boolean showHat) {
return new VelocityTabListEntryLegacy(this, profile, displayName, latency, gameMode);
Comment thread
Beaness marked this conversation as resolved.
}

/**
* Generates a random UUID v4 using {@link ThreadLocalRandom}. The result is a structurally valid
* UUID v4 but is not cryptographically secure
*
* @return a new random {@link UUID}
*/
private static UUID generateInsecureRandomUuid() {
ThreadLocalRandom random = ThreadLocalRandom.current();
long msb = (random.nextLong() & 0xffffffffffff0fffL) | 0x0000000000004000L; // version 4
long lsb = (random.nextLong() & 0x3fffffffffffffffL) | 0x8000000000000000L; // IETF variant
Comment thread
Beaness marked this conversation as resolved.
return new UUID(msb, lsb);
}
}