From f9583a7652c04e42b6b6a43268750d4a31a256b6 Mon Sep 17 00:00:00 2001 From: Janmm14 Date: Sat, 26 Jun 2021 10:05:27 +1000 Subject: [PATCH] #3129: Replace ConnectTimeoutException with a more user-friendly string. --- .../java/net/md_5/bungee/UserConnection.java | 16 ++++++++++++++-- proxy/src/main/resources/messages.properties | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 5a69db65..5713c127 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -8,6 +8,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; +import io.netty.channel.ConnectTimeoutException; import io.netty.util.internal.PlatformDependent; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -351,10 +352,10 @@ public final class UserConnection implements ProxiedPlayer connect( def, null, true, ServerConnectEvent.Reason.LOBBY_FALLBACK ); } else if ( dimensionChange ) { - disconnect( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) ); + disconnect( bungee.getTranslation( "fallback_kick", connectionFailMessage( future.cause() ) ) ); } else { - sendMessage( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) ); + sendMessage( bungee.getTranslation( "fallback_kick", connectionFailMessage( future.cause() ) ) ); } } } @@ -373,6 +374,17 @@ public final class UserConnection implements ProxiedPlayer b.connect().addListener( listener ); } + private String connectionFailMessage(Throwable cause) + { + if ( cause instanceof ConnectTimeoutException ) + { + return bungee.getTranslation( "timeout" ); + } else + { + return cause.getClass().getName(); + } + } + @Override public void disconnect(String reason) { diff --git a/proxy/src/main/resources/messages.properties b/proxy/src/main/resources/messages.properties index 2a79e62b..e114cdcf 100644 --- a/proxy/src/main/resources/messages.properties +++ b/proxy/src/main/resources/messages.properties @@ -7,6 +7,7 @@ connect_kick=\u00a7cKicked whilst connecting to {0}: {1} current_server=\u00a76You are currently connected to {0}. fallback_kick=\u00a7cCould not connect to a default or fallback server, please try again later: {0} fallback_lobby=\u00a7cCould not connect to target server, you have been moved to a fallback server. +timeout=Server not reachable (timeout). Offline? Incorrectly configured address/port/firewall? lost_connection=[Proxy] Lost connection to server. mojang_fail=Error occurred while contacting login servers, are they down? no_permission=\u00a7cYou do not have permission to execute this command!