From e187646de2816092e5b1e0d9924cf67d0ae0c91a Mon Sep 17 00:00:00 2001 From: TechnicJelle <22576047+TechnicJelle@users.noreply.github.com> Date: Thu, 8 Jun 2023 23:00:49 +0200 Subject: [PATCH] Add port-in-use check to CLI --- .../bluecolored/bluemap/cli/BlueMapCLI.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java b/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java index 8ff7292f..55dc7909 100644 --- a/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java +++ b/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java @@ -54,7 +54,9 @@ import java.io.File; import java.io.IOException; +import java.net.BindException; import java.net.InetSocketAddress; +import java.net.UnknownHostException; import java.nio.file.Path; import java.util.*; import java.util.concurrent.TimeUnit; @@ -204,12 +206,24 @@ public void startWebserver(BlueMapService blueMap, boolean verbose) throws IOExc HttpRequestHandler handler = new BlueMapResponseModifier(routingRequestHandler); if (verbose) handler = new LoggingRequestHandler(handler); - HttpServer webServer = new HttpServer(handler); - webServer.bind(new InetSocketAddress( - config.resolveIp(), - config.getPort() - )); - webServer.start(); + try { + HttpServer webServer = new HttpServer(handler); + webServer.bind(new InetSocketAddress( + config.resolveIp(), + config.getPort() + )); + webServer.start(); + } catch (UnknownHostException ex) { + throw new ConfigurationException("BlueMap failed to resolve the ip in your webserver-config.\n" + + "Check if that is correctly configured.", ex); + } catch (BindException ex) { + throw new ConfigurationException("BlueMap failed to bind to the configured address.\n" + + "This usually happens when the configured port (" + config.getPort() + ") is already in use by some other program.", ex); + } catch (IOException ex) { + throw new ConfigurationException("BlueMap failed to initialize the webserver.\n" + + "Check your webserver-config if everything is configured correctly.\n" + + "(Make sure you DON'T use the same port for bluemap that you also use for your minecraft server)", ex); + } } @Override