add location to the server response
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 57s
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 57s
This commit is contained in:
@ -32,8 +32,8 @@ public final class BedrockMinecraftServer extends MinecraftServer {
|
||||
|
||||
private BedrockMinecraftServer(@NonNull String id, @NonNull String hostname, String ip, int port, @NonNull DNSRecord[] records,
|
||||
@NonNull Edition edition, @NonNull Version version, @NonNull Players players, @NonNull MOTD motd,
|
||||
@NonNull GameMode gamemode) {
|
||||
super(hostname, ip, port, records, motd, players);
|
||||
@NonNull GameMode gamemode, GeoLocation location) {
|
||||
super(hostname, ip, port, records, motd, players, location);
|
||||
this.id = id;
|
||||
this.edition = edition;
|
||||
this.version = version;
|
||||
@ -53,7 +53,7 @@ public final class BedrockMinecraftServer extends MinecraftServer {
|
||||
* @return the Bedrock Minecraft server
|
||||
*/
|
||||
@NonNull
|
||||
public static BedrockMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, @NonNull String token) {
|
||||
public static BedrockMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, GeoLocation location, @NonNull String token) {
|
||||
String[] split = token.split(";"); // Split the token
|
||||
Edition edition = Edition.valueOf(split[0]);
|
||||
Version version = new Version(Integer.parseInt(split[2]), split[3]);
|
||||
@ -70,7 +70,8 @@ public final class BedrockMinecraftServer extends MinecraftServer {
|
||||
version,
|
||||
players,
|
||||
motd,
|
||||
gameMode
|
||||
gameMode,
|
||||
location
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -65,10 +65,10 @@ public final class JavaMinecraftServer extends MinecraftServer {
|
||||
*/
|
||||
private boolean mojangBlocked;
|
||||
|
||||
public JavaMinecraftServer(String hostname, String ip, int port, MOTD motd, Players players, DNSRecord[] records,
|
||||
@NonNull Version version, Favicon favicon, ForgeModInfo modInfo, ForgeData forgeData,
|
||||
boolean preventsChatReports, boolean enforcesSecureChat, boolean previewsChat) {
|
||||
super(hostname, ip, port, records, motd, players);
|
||||
public JavaMinecraftServer(String hostname, String ip, int port, MOTD motd, Players players, GeoLocation location,
|
||||
DNSRecord[] records, @NonNull Version version, Favicon favicon, ForgeModInfo modInfo,
|
||||
ForgeData forgeData, boolean preventsChatReports, boolean enforcesSecureChat, boolean previewsChat) {
|
||||
super(hostname, ip, port, records, motd, players, location);
|
||||
this.version = version;
|
||||
this.favicon = favicon;
|
||||
this.modInfo = modInfo;
|
||||
@ -88,7 +88,7 @@ public final class JavaMinecraftServer extends MinecraftServer {
|
||||
* @return the Java Minecraft server
|
||||
*/
|
||||
@NonNull
|
||||
public static JavaMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, @NonNull JavaServerStatusToken token) {
|
||||
public static JavaMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, GeoLocation location, @NonNull JavaServerStatusToken token) {
|
||||
String motdString = token.getDescription() instanceof String ? (String) token.getDescription() : null;
|
||||
if (motdString == null) { // Not a string motd, convert from Json
|
||||
motdString = new TextComponent(ComponentSerializer.parse(Main.GSON.toJson(token.getDescription()))).toLegacyText();
|
||||
@ -99,6 +99,7 @@ public final class JavaMinecraftServer extends MinecraftServer {
|
||||
port,
|
||||
MinecraftServer.MOTD.create(motdString),
|
||||
token.getPlayers(),
|
||||
location,
|
||||
records,
|
||||
token.getVersion().detailedCopy(),
|
||||
JavaMinecraftServer.Favicon.create(token.getFavicon(), ServerUtils.getAddress(hostname, port)),
|
||||
|
@ -1,5 +1,6 @@
|
||||
package xyz.mcutils.backend.model.server;
|
||||
|
||||
import com.maxmind.geoip2.model.CityResponse;
|
||||
import io.micrometer.common.lang.NonNull;
|
||||
import lombok.*;
|
||||
import xyz.mcutils.backend.common.ColorUtils;
|
||||
@ -48,6 +49,11 @@ public class MinecraftServer {
|
||||
*/
|
||||
private final Players players;
|
||||
|
||||
/**
|
||||
* The location of the server.
|
||||
*/
|
||||
private final GeoLocation location;
|
||||
|
||||
/**
|
||||
* A platform a Minecraft
|
||||
* server can operate on.
|
||||
@ -147,4 +153,51 @@ public class MinecraftServer {
|
||||
@NonNull private final String name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The location of the server.
|
||||
*/
|
||||
@AllArgsConstructor @Getter
|
||||
public static class GeoLocation {
|
||||
/**
|
||||
* The country of the server.
|
||||
*/
|
||||
private final String country;
|
||||
|
||||
/**
|
||||
* The region of the server.
|
||||
*/
|
||||
private final String region;
|
||||
|
||||
/**
|
||||
* The city of the server.
|
||||
*/
|
||||
private final String city;
|
||||
|
||||
/**
|
||||
* The latitude of the server.
|
||||
*/
|
||||
private final double latitude;
|
||||
|
||||
/**
|
||||
* The longitude of the server.
|
||||
*/
|
||||
private final double longitude;
|
||||
|
||||
/**
|
||||
* Gets the location of the server from Maxmind.
|
||||
*
|
||||
* @param response the response from Maxmind
|
||||
* @return the location of the server
|
||||
*/
|
||||
public static GeoLocation fromMaxMind(CityResponse response) {
|
||||
return new GeoLocation(
|
||||
response.getCountry().getName(),
|
||||
response.getMostSpecificSubdivision().getName(),
|
||||
response.getCity().getName(),
|
||||
response.getLocation().getLatitude(),
|
||||
response.getLocation().getLongitude()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user