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

This commit is contained in:
Lee
2024-04-21 23:27:44 +01:00
parent bf992713dc
commit 3faf2d3319
9 changed files with 217 additions and 11 deletions

View File

@ -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()
);
}
}
}