Compare commits
No commits in common. "9e99db3aa307e0eb37d102f682ea52b3af09d378" and "ad51d4d3574521e36fc2eb32af64b3bbcd9b6dfd" have entirely different histories.
9e99db3aa3
...
ad51d4d357
@ -16,29 +16,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
arch: ["ubuntu-latest"]
|
arch: ["ubuntu-latest"]
|
||||||
git-version: ["2.44.0"]
|
git-version: ["2.44.0"]
|
||||||
java-version: ["17"]
|
|
||||||
maven-version: ["3.8.5"]
|
|
||||||
runs-on: ${{ matrix.arch }}
|
runs-on: ${{ matrix.arch }}
|
||||||
|
|
||||||
# Steps to run
|
# Steps to run
|
||||||
steps:
|
steps:
|
||||||
# Checkout the repo
|
# Checkout the repo
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# Setup Java and Maven
|
|
||||||
- name: Set up JDK and Maven
|
|
||||||
uses: s4u/setup-maven-action@v1.12.0
|
|
||||||
with:
|
|
||||||
java-version: ${{ matrix.java-version }}
|
|
||||||
distribution: "zulu"
|
|
||||||
maven-version: ${{ matrix.maven-version }}
|
|
||||||
|
|
||||||
# Run JUnit Tests
|
|
||||||
- name: Run Tests
|
|
||||||
run: mvn --batch-mode test -q
|
|
||||||
|
|
||||||
# Re-checkout to reset the FS before deploying to Dokku
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
|
@ -26,6 +26,7 @@ package me.braydon.mc.controller;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import me.braydon.mc.exception.impl.BadRequestException;
|
import me.braydon.mc.exception.impl.BadRequestException;
|
||||||
|
import me.braydon.mc.exception.impl.InvalidMinecraftServerPlatform;
|
||||||
import me.braydon.mc.exception.impl.ResourceNotFoundException;
|
import me.braydon.mc.exception.impl.ResourceNotFoundException;
|
||||||
import me.braydon.mc.model.MinecraftServer;
|
import me.braydon.mc.model.MinecraftServer;
|
||||||
import me.braydon.mc.model.cache.CachedMinecraftServer;
|
import me.braydon.mc.model.cache.CachedMinecraftServer;
|
||||||
@ -64,13 +65,14 @@ public final class ServerController {
|
|||||||
* @param platform the platform of the server
|
* @param platform the platform of the server
|
||||||
* @param hostname the hostname of the server
|
* @param hostname the hostname of the server
|
||||||
* @return the server
|
* @return the server
|
||||||
* @throws BadRequestException if the hostname or platform is invalid
|
* @throws BadRequestException if the hostname is unknown
|
||||||
|
* @throws InvalidMinecraftServerPlatform if the platform is invalid
|
||||||
* @throws ResourceNotFoundException if the server isn't found
|
* @throws ResourceNotFoundException if the server isn't found
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{platform}/{hostname}")
|
@GetMapping("/{platform}/{hostname}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<CachedMinecraftServer> getServer(@PathVariable @NonNull String platform, @PathVariable @NonNull String hostname)
|
public ResponseEntity<CachedMinecraftServer> getServer(@PathVariable @NonNull String platform, @PathVariable @NonNull String hostname)
|
||||||
throws BadRequestException, ResourceNotFoundException
|
throws BadRequestException, InvalidMinecraftServerPlatform, ResourceNotFoundException
|
||||||
{
|
{
|
||||||
return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname));
|
return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Braydon (Rainnny).
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package me.braydon.mc.exception.impl;
|
||||||
|
|
||||||
|
import me.braydon.mc.model.MinecraftServer;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This exception is raised when a {@link MinecraftServer}
|
||||||
|
* lookup is made for an invalid {@link MinecraftServer.Platform}.
|
||||||
|
*
|
||||||
|
* @author Braydon
|
||||||
|
*/
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
public final class InvalidMinecraftServerPlatform extends RuntimeException {
|
||||||
|
public InvalidMinecraftServerPlatform() {
|
||||||
|
super("Invalid Minecraft server platform");
|
||||||
|
}
|
||||||
|
}
|
@ -35,6 +35,7 @@ import me.braydon.mc.common.*;
|
|||||||
import me.braydon.mc.common.web.JsonWebException;
|
import me.braydon.mc.common.web.JsonWebException;
|
||||||
import me.braydon.mc.common.web.JsonWebRequest;
|
import me.braydon.mc.common.web.JsonWebRequest;
|
||||||
import me.braydon.mc.exception.impl.BadRequestException;
|
import me.braydon.mc.exception.impl.BadRequestException;
|
||||||
|
import me.braydon.mc.exception.impl.InvalidMinecraftServerPlatform;
|
||||||
import me.braydon.mc.exception.impl.MojangRateLimitException;
|
import me.braydon.mc.exception.impl.MojangRateLimitException;
|
||||||
import me.braydon.mc.exception.impl.ResourceNotFoundException;
|
import me.braydon.mc.exception.impl.ResourceNotFoundException;
|
||||||
import me.braydon.mc.model.*;
|
import me.braydon.mc.model.*;
|
||||||
@ -282,7 +283,7 @@ public final class MojangService {
|
|||||||
icon = favicon.getBase64();
|
icon = favicon.getBase64();
|
||||||
icon = icon.substring(icon.indexOf(",") + 1); // Remove the data type from the server icon
|
icon = icon.substring(icon.indexOf(",") + 1); // Remove the data type from the server icon
|
||||||
}
|
}
|
||||||
} catch (BadRequestException | ResourceNotFoundException ignored) {
|
} catch (BadRequestException | InvalidMinecraftServerPlatform | ResourceNotFoundException ignored) {
|
||||||
// Safely ignore these, we will use the default server icon
|
// Safely ignore these, we will use the default server icon
|
||||||
}
|
}
|
||||||
if (icon == null) { // Use the default server icon
|
if (icon == null) { // Use the default server icon
|
||||||
@ -345,15 +346,16 @@ public final class MojangService {
|
|||||||
* @param platformName the name of the platform
|
* @param platformName the name of the platform
|
||||||
* @param hostname the hostname of the server
|
* @param hostname the hostname of the server
|
||||||
* @return the resolved Minecraft server
|
* @return the resolved Minecraft server
|
||||||
* @throws BadRequestException if the hostname or platform is invalid
|
* @throws BadRequestException if the hostname is unknown
|
||||||
|
* @throws InvalidMinecraftServerPlatform if the platform is invalid
|
||||||
* @throws ResourceNotFoundException if the server isn't found
|
* @throws ResourceNotFoundException if the server isn't found
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public CachedMinecraftServer getMinecraftServer(@NonNull String platformName, @NonNull String hostname)
|
public CachedMinecraftServer getMinecraftServer(@NonNull String platformName, @NonNull String hostname)
|
||||||
throws BadRequestException, ResourceNotFoundException {
|
throws BadRequestException, InvalidMinecraftServerPlatform, ResourceNotFoundException {
|
||||||
MinecraftServer.Platform platform = EnumUtils.getEnumConstant(MinecraftServer.Platform.class, platformName.toUpperCase());
|
MinecraftServer.Platform platform = EnumUtils.getEnumConstant(MinecraftServer.Platform.class, platformName.toUpperCase());
|
||||||
if (platform == null) { // Invalid platform
|
if (platform == null) { // Invalid platform
|
||||||
throw new BadRequestException("Invalid platform: %s".formatted(platformName));
|
throw new InvalidMinecraftServerPlatform();
|
||||||
}
|
}
|
||||||
String lookupHostname = hostname; // The hostname used to lookup the server
|
String lookupHostname = hostname; // The hostname used to lookup the server
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user