diff --git a/src/main/java/me/braydon/mc/controller/ServerController.java b/src/main/java/me/braydon/mc/controller/ServerController.java index 5b02efa..bf2ce24 100644 --- a/src/main/java/me/braydon/mc/controller/ServerController.java +++ b/src/main/java/me/braydon/mc/controller/ServerController.java @@ -66,7 +66,6 @@ public final class ServerController { * * @param platform the platform of the server * @param hostname the hostname of the server - * @param port the port of the server, null for default * @return the server * @throws BadRequestException if the hostname, platform, or port is invalid * @throws ResourceNotFoundException if the server isn't found @@ -75,10 +74,9 @@ public final class ServerController { @ResponseBody public ResponseEntity getServer( @Parameter(description = "The platform of the server", example = "java") @PathVariable @NonNull String platform, - @Parameter(description = "The hostname of the server", example = "hypixel.net") @PathVariable @NonNull String hostname, - @Parameter(description = "The port of the server", example = "25565") @RequestParam(required = false) String port + @Parameter(description = "The hostname of the server", example = "hypixel.net") @PathVariable @NonNull String hostname ) throws BadRequestException, ResourceNotFoundException { - return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname, port)); + return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname)); } /** @@ -103,18 +101,16 @@ public final class ServerController { * server by its platform and hostname. * * @param hostname the hostname of the server - * @param port the port of the server, null for default * @return the server icon */ @GetMapping(value = "/icon/{hostname}", produces = MediaType.IMAGE_PNG_VALUE) @ResponseBody public ResponseEntity getServerFavicon( - @Parameter(description = "The hostname of the server", example = "hypixel.net") @PathVariable @NonNull String hostname, - @Parameter(description = "The port of the server", example = "25565") @RequestParam(required = false) String port + @Parameter(description = "The hostname of the server", example = "hypixel.net") @PathVariable @NonNull String hostname ) { return ResponseEntity.ok() .contentType(MediaType.IMAGE_PNG) .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=%s.png".formatted(hostname)) - .body(mojangService.getServerFavicon(hostname, port)); + .body(mojangService.getServerFavicon(hostname)); } } \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/service/MojangService.java b/src/main/java/me/braydon/mc/service/MojangService.java index c1d589a..bd7ce1e 100644 --- a/src/main/java/me/braydon/mc/service/MojangService.java +++ b/src/main/java/me/braydon/mc/service/MojangService.java @@ -271,14 +271,13 @@ public final class MojangService { *

* * @param hostname the hostname of the server - * @param port the port of the server, null for default * @return the server favicon * @see #DEFAULT_SERVER_ICON for the default server icon */ - public byte[] getServerFavicon(@NonNull String hostname, String port) { + public byte[] getServerFavicon(@NonNull String hostname) { String icon = null; // The server base64 icon try { - JavaMinecraftServer.Favicon favicon = ((JavaMinecraftServer) getMinecraftServer(MinecraftServer.Platform.JAVA.name(), hostname, port).getValue()).getFavicon(); + JavaMinecraftServer.Favicon favicon = ((JavaMinecraftServer) getMinecraftServer(MinecraftServer.Platform.JAVA.name(), hostname).getValue()).getFavicon(); if (favicon != null) { // Use the server's favicon icon = favicon.getBase64(); icon = icon.substring(icon.indexOf(",") + 1); // Remove the data type from the server icon @@ -345,13 +344,12 @@ public final class MojangService { * * @param platformName the name of the platform * @param hostname the hostname of the server - * @param portString the port of the server, null for default * @return the resolved Minecraft server * @throws BadRequestException if the hostname, platform, or port is invalid * @throws ResourceNotFoundException if the server isn't found */ @NonNull - public CachedMinecraftServer getMinecraftServer(@NonNull String platformName, @NonNull String hostname, String portString) + public CachedMinecraftServer getMinecraftServer(@NonNull String platformName, @NonNull String hostname) throws BadRequestException, ResourceNotFoundException { MinecraftServer.Platform platform = EnumUtils.getEnumConstant(MinecraftServer.Platform.class, platformName.toUpperCase()); if (platform == null) { // Invalid platform @@ -360,7 +358,11 @@ public final class MojangService { String lookupHostname = hostname; // The hostname used to lookup the server int port = platform.getDefaultPort(); // Port to ping - if (portString != null) { + String portString = null; + if (hostname.contains(":")) { // Hostname contains a port + String[] split = hostname.split(":"); + hostname = split[0]; + portString = split[1]; try { // Try and parse the port port = Integer.parseInt(portString); } catch (NumberFormatException ex) { // Invalid port