Better server ping concurrency

Addresses #2289
This commit is contained in:
Dan Mulloy 2023-04-03 22:55:32 -04:00
parent b51812655a
commit c7753a9d5b
No known key found for this signature in database
GPG Key ID: F379C293F178751F
1 changed files with 22 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package com.comphenix.protocol.wrappers.ping;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Semaphore;
import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.reflect.EquivalentConverter;
@ -29,13 +30,18 @@ public final class ServerPingRecord implements ServerPingImpl {
private static EquivalentConverter<List<WrappedGameProfile>> PROFILE_LIST_CONVERTER;
private static boolean initialized = false;
private static final Object lock = new Object();
private static void initialize() {
if (initialized) {
return;
}
initialized = true;
synchronized (lock) {
// may have been initialized while waiting for the lock
if (initialized) {
return;
}
try {
SERVER_PING = MinecraftReflection.getServerPingClass();
@ -52,7 +58,10 @@ public final class ServerPingRecord implements ServerPingImpl {
DEFAULT_DESCRIPTION = WrappedChatComponent.fromLegacyText("A Minecraft Server");
} catch (Exception ex) {
ex.printStackTrace(); // TODO
throw new RuntimeException("Failed to initialize Server Ping", ex);
} finally {
initialized = true;
}
}
}