From cbfaa867a9be43f58a5ddac488d2dcf2d3a9d523 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 17 Apr 2024 20:51:48 +0100 Subject: [PATCH] fix bedrock invalid server pinging --- src/main/java/xyz/mcutils/backend/common/WebRequest.java | 1 + .../pinger/impl/BedrockMinecraftServerPinger.java | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/common/WebRequest.java b/src/main/java/xyz/mcutils/backend/common/WebRequest.java index c87b9d5..9fc3680 100644 --- a/src/main/java/xyz/mcutils/backend/common/WebRequest.java +++ b/src/main/java/xyz/mcutils/backend/common/WebRequest.java @@ -1,5 +1,6 @@ package xyz.mcutils.backend.common; +import com.google.gson.JsonObject; import lombok.experimental.UtilityClass; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; diff --git a/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java b/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java index 6073681..7afbe0d 100644 --- a/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java +++ b/src/main/java/xyz/mcutils/backend/service/pinger/impl/BedrockMinecraftServerPinger.java @@ -10,10 +10,7 @@ import xyz.mcutils.backend.model.server.BedrockMinecraftServer; import xyz.mcutils.backend.service.pinger.MinecraftServerPinger; import java.io.IOException; -import java.net.DatagramSocket; -import java.net.InetSocketAddress; -import java.net.SocketTimeoutException; -import java.net.UnknownHostException; +import java.net.*; /** * The {@link MinecraftServerPinger} for pinging @@ -56,11 +53,13 @@ public final class BedrockMinecraftServerPinger implements MinecraftServerPinger throw new ResourceNotFoundException("Server didn't respond to ping"); } return BedrockMinecraftServer.create(hostname, ip, port, records, response); // Return the server - } catch (IOException ex) { + } catch (IOException ex ) { if (ex instanceof UnknownHostException) { throw new BadRequestException("Unknown hostname: %s".formatted(hostname)); } else if (ex instanceof SocketTimeoutException) { throw new ResourceNotFoundException(ex); + } else if (ex instanceof SocketException) { + throw new BadRequestException("An error occurred pinging %s:%s".formatted(hostname, port)); } log.error("An error occurred pinging %s:%s:".formatted(hostname, port), ex); }