geforkt von Mirrors/Velocity
Shorten connection errors to a more reasonable length. Fixes #58
Dieser Commit ist enthalten in:
Ursprung
9363ee34ec
Commit
d6fb3a210e
@ -51,6 +51,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.CompletionException;
|
||||||
|
|
||||||
public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||||
private static final PlainComponentSerializer PASS_THRU_TRANSLATE = new PlainComponentSerializer((c) -> "", TranslatableComponent::key);
|
private static final PlainComponentSerializer PASS_THRU_TRANSLATE = new PlainComponentSerializer((c) -> "", TranslatableComponent::key);
|
||||||
@ -258,13 +259,18 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleConnectionException(RegisteredServer server, Throwable throwable) {
|
public void handleConnectionException(RegisteredServer server, Throwable throwable) {
|
||||||
String error = ThrowableUtils.briefDescription(throwable);
|
Throwable wrapped = throwable;
|
||||||
|
if (throwable instanceof CompletionException) {
|
||||||
|
wrapped = throwable.getCause();
|
||||||
|
}
|
||||||
|
|
||||||
|
String error = ThrowableUtils.briefDescription(wrapped);
|
||||||
String userMessage;
|
String userMessage;
|
||||||
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
|
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
|
||||||
userMessage = "Exception in server " + server.getServerInfo().getName();
|
userMessage = "Exception in server " + server.getServerInfo().getName();
|
||||||
} else {
|
} else {
|
||||||
logger.error("{}: unable to connect to server {}", this, server.getServerInfo().getName(), throwable);
|
logger.error("{}: unable to connect to server {}", this, server.getServerInfo().getName(), wrapped);
|
||||||
userMessage = "Exception connecting to server " + server.getServerInfo().getName();
|
userMessage = "Can't connect to server " + server.getServerInfo().getName();
|
||||||
}
|
}
|
||||||
handleConnectionException(server, null, TextComponent.builder()
|
handleConnectionException(server, null, TextComponent.builder()
|
||||||
.content(userMessage + ": ")
|
.content(userMessage + ": ")
|
||||||
@ -286,7 +292,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
} else {
|
} else {
|
||||||
logger.error("{}: disconnected while connecting to {}: {}", this, server.getServerInfo().getName(), plainTextReason);
|
logger.error("{}: disconnected while connecting to {}: {}", this, server.getServerInfo().getName(), plainTextReason);
|
||||||
handleConnectionException(server, disconnectReason, TextComponent.builder()
|
handleConnectionException(server, disconnectReason, TextComponent.builder()
|
||||||
.content("Unable to connect to " + server.getServerInfo().getName() + ": ")
|
.content("Can't connect to server " + server.getServerInfo().getName() + ": ")
|
||||||
.color(TextColor.RED)
|
.color(TextColor.RED)
|
||||||
.append(disconnectReason)
|
.append(disconnectReason)
|
||||||
.build());
|
.build());
|
||||||
|
@ -4,6 +4,6 @@ public enum ThrowableUtils {
|
|||||||
;
|
;
|
||||||
|
|
||||||
public static String briefDescription(Throwable throwable) {
|
public static String briefDescription(Throwable throwable) {
|
||||||
return throwable.getClass().getName() + ": " + throwable.getMessage();
|
return throwable.getClass().getSimpleName() + ": " + throwable.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren