pls work first try

This commit is contained in:
Lee 2024-04-17 21:06:43 +01:00
commit ecde2bb2a7
30 changed files with 1258 additions and 0 deletions

@ -0,0 +1,21 @@
name: Publish package to the Maven Central Repository
on:
push:
branches:
- master
-
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
- name: Publish package
run: mvn --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.REPO_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.REPO_PASSWORD }}

31
.gitignore vendored Normal file

@ -0,0 +1,31 @@
### ME template
*.class
*.log
*.ctxt
.mtj.tmp/
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
hs_err_pid*
replay_pid*
.idea
cmake-build-*/
.idea/**/mongoSettings.xml
*.iws
out/
build/
work/
.idea_modules/
atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
git.properties
pom.xml.versionsBackup
application.yml
target/

3
.idea/.gitignore generated vendored Normal file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

7
.idea/encodings.xml generated Normal file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

14
.idea/misc.xml generated Normal file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="azul-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml generated Normal file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

67
pom.xml Normal file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.mcutils</groupId>
<artifactId>mcutils-java-library</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<repository>
<id>mcutils-java-library</id>
<url>https://repo.fascinated.cc/public/mcutils-java-library/</url>
</repository>
</distributionManagement>
<dependencies>
<!-- Libraries -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
<!-- Web Client -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.1.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3</version>
<scope>compile</scope>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,112 @@
package xyz.mcutils;
import xyz.mcutils.common.WebRequest;
import xyz.mcutils.exception.ErrorResponse;
import xyz.mcutils.models.mojang.CachedMojangEndpointStatus;
import xyz.mcutils.models.player.CachedPlayer;
import xyz.mcutils.models.player.CachedPlayerSkinPart;
import xyz.mcutils.models.player.CachedUsernameToUuid;
import xyz.mcutils.models.player.Skin;
import xyz.mcutils.models.server.*;
public class McUtilsAPI {
private static final String API_ENDPOINT = "https://api.mcutils.xyz";
private static final String MOJANG_API_STATUS_ENDPOINT = API_ENDPOINT + "/mojang/status";
private static final String PLAYER_ENDPOINT = API_ENDPOINT + "/player/%s";
private static final String USERNAME_TO_UUID_ENDPOINT = API_ENDPOINT + "/player/uuid/%s";
private static final String PLAYER_SKIN_PART_ENDPOINT = API_ENDPOINT + "/player/%s/%s";
private static final String SERVER_ENDPOINT = API_ENDPOINT + "/server/%s/%s";
private static final String SERVER_ICON_ENDPOINT = API_ENDPOINT + "/server/icon/%s";
private static final String SERVER_BLOCKED_STATUS_ENDPOINT = API_ENDPOINT + "/server/blocked/%s";
/**
* Gets the status of the Mojang APIs.
*
* @return The status of the Mojang API.
* @throws ErrorResponse If an error occurs.
*/
public static CachedMojangEndpointStatus getMojangApiStatus() throws ErrorResponse {
return WebRequest.get(MOJANG_API_STATUS_ENDPOINT, CachedMojangEndpointStatus.class);
}
/**
* Gets a player from the API.
*
* @param id The id of the player to get.
* @return The player.
* @throws ErrorResponse If an error occurs.
*/
public static CachedPlayer getPlayer(String id) throws ErrorResponse {
return WebRequest.get(PLAYER_ENDPOINT.formatted(id), CachedPlayer.class);
}
/**
* Gets a player from the API.
*
* @param username The username of the player to get.
* @return The player.
* @throws ErrorResponse If an error occurs.
*/
public static CachedUsernameToUuid getUsernameToUuid(String username) throws ErrorResponse {
return WebRequest.get(USERNAME_TO_UUID_ENDPOINT.formatted(username), CachedUsernameToUuid.class);
}
/**
* Gets a player skin part from the API.
*
* @param part The part of the skin to get.
* @param id The id of the player to get.
* @return The player skin part.
* @throws ErrorResponse If an error occurs.
*/
public static CachedPlayerSkinPart getPlayerSkinPart(Skin.SkinPart part, String id) throws ErrorResponse {
byte[] partBytes = WebRequest.get(PLAYER_SKIN_PART_ENDPOINT.formatted(part, id), byte[].class);
return new CachedPlayerSkinPart(partBytes);
}
/**
* Gets a Bedrock server from the API.
*
* @param id The id of the server to get.
* @return The server.
* @throws ErrorResponse If an error occurs.
*/
public static CachedBedrockMinecraftServer getBedrockServer(String id) throws ErrorResponse {
return WebRequest.get(SERVER_ENDPOINT.formatted(ServerPlatform.BEDROCK.name(), id), CachedBedrockMinecraftServer.class);
}
/**
* Gets a Java server from the API.
*
* @param id The id of the server to get.
* @return The server.
* @throws ErrorResponse If an error occurs.
*/
public static CachedJavaMinecraftServer getJavaServer(String id) throws ErrorResponse {
return WebRequest.get(SERVER_ENDPOINT.formatted(ServerPlatform.JAVA.name(), id), CachedJavaMinecraftServer.class);
}
/**
* Gets the icon of a Java server from the API.
*
* @param id The id of the server to get the icon of.
* @return The server icon.
* @throws ErrorResponse If an error occurs.
*/
public static CachedServerIcon getServerIcon(String id) throws ErrorResponse {
byte[] bytes = WebRequest.get(SERVER_ICON_ENDPOINT.formatted(id), byte[].class);
return new CachedServerIcon(bytes);
}
/**
* Gets the blocked status of a Java server from the API.
*
* @param id The id of the server to get the blocked status of.
* @return The server blocked status.
* @throws ErrorResponse If an error occurs.
*/
public static CachedServerBlockedStatus getServerBlockedStatus(String id) throws ErrorResponse {
return WebRequest.get(SERVER_BLOCKED_STATUS_ENDPOINT.formatted(id), CachedServerBlockedStatus.class);
}
}

@ -0,0 +1,22 @@
package xyz.mcutils.common;
import lombok.SneakyThrows;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateUtils {
private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ENGLISH);
/**
* Converts a string to a date.
*
* @param date The date to convert
* @return The date
*/
@SneakyThrows
public static Date stringToDate(String date) {
return FORMATTER.parse(date);
}
}

@ -0,0 +1,58 @@
package xyz.mcutils.common;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import lombok.experimental.UtilityClass;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClient;
import xyz.mcutils.exception.ErrorResponse;
@UtilityClass
public class WebRequest {
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.create();
/**
* The web client.
*/
private static final RestClient CLIENT;
static {
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(2500); // 2.5 seconds
CLIENT = RestClient.builder()
.requestFactory(requestFactory)
.build();
}
/**
* Gets a response from the given URL.
*
* @param url the url
* @return the response
* @param <T> the type of the response
*/
public static <T> T get(String url, Class<T> clazz) throws ErrorResponse {
try {
ResponseEntity<T> responseEntity = CLIENT.get()
.uri(url)
.retrieve()
.toEntity(clazz);
return responseEntity.getBody();
} catch (HttpClientErrorException ex) {
JsonObject json = GSON.fromJson(ex.getResponseBodyAsString(), JsonObject.class);
throw new ErrorResponse(
HttpStatus.valueOf(ex.getStatusCode().value()),
json.get("code").getAsInt(),
json.get("message").getAsString(),
DateUtils.stringToDate(json.get("timestamp").getAsString())
);
}
}
}

@ -0,0 +1,34 @@
package xyz.mcutils.exception;
import io.micrometer.common.lang.NonNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import org.springframework.http.HttpStatus;
import java.util.Date;
@Getter
@ToString @AllArgsConstructor
public class ErrorResponse extends RuntimeException {
/**
* The status code of this error.
*/
@NonNull
private final HttpStatus status;
/**
* The HTTP code of this error.
*/
private final int code;
/**
* The message of this error.
*/
@NonNull private final String message;
/**
* The timestamp this error occurred.
*/
@NonNull private final Date timestamp;
}

@ -0,0 +1,58 @@
package xyz.mcutils.models;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
public class CachedResponse {
/**
* The cache information for this response.
*/
private Cache cache;
@AllArgsConstructor
@Getter
@Setter
public static class Cache {
/**
* Whether this request is cached.
*/
private boolean cached;
/**
* The unix timestamp of when this was cached.
*/
private long cachedTime;
/**
* Create a new cache information object with the default values.
* <p>
* The default values are:
* <br>
* <ul>
* <li>cached: true</li>
* <li>cachedAt: {@link System#currentTimeMillis()}</li>
* </ul>
* <br>
* </p>
*
* @return the default cache information object
*/
public static Cache defaultCache() {
return new Cache(true, System.currentTimeMillis());
}
/**
* Sets if this request is cached.
*
* @param cached the new value of if this request is cached
*/
public void setCached(boolean cached) {
this.cached = cached;
if (!cached) {
cachedTime = -1;
}
}
}
}

@ -0,0 +1,29 @@
package xyz.mcutils.models.dns;
import io.micrometer.common.lang.NonNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Setter @Getter
@NoArgsConstructor @AllArgsConstructor
public class DNSRecord {
/**
* The type of this record.
*/
@NonNull
private Type type;
/**
* The TTL (Time To Live) of this record.
*/
private long ttl;
/**
* Types of a record.
*/
public enum Type {
A, SRV
}
}

@ -0,0 +1,15 @@
package xyz.mcutils.models.dns.impl;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import xyz.mcutils.models.dns.DNSRecord;
@Setter @Getter
@NoArgsConstructor
public final class ARecord extends DNSRecord {
/**
* The address of this record, null if unresolved.
*/
private String address;
}

@ -0,0 +1,31 @@
package xyz.mcutils.models.dns.impl;
import io.micrometer.common.lang.NonNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import xyz.mcutils.models.dns.DNSRecord;
@Setter @Getter
@NoArgsConstructor
public final class SRVRecord extends DNSRecord {
/**
* The priority of this record.
*/
private int priority;
/**
* The weight of this record.
*/
private int weight;
/**
* The port of this record.
*/
private int port;
/**
* The target of this record.
*/
@NonNull private String target;
}

@ -0,0 +1,35 @@
package xyz.mcutils.models.mojang;
import lombok.AllArgsConstructor;
import lombok.Getter;
import xyz.mcutils.models.CachedResponse;
import java.util.Map;
@AllArgsConstructor
@Getter
public class CachedMojangEndpointStatus extends CachedResponse {
/**
* The list of endpoints and their status.
*/
private Map<String, Status> endpoints;
public enum Status {
/**
* The service is online and operational.
*/
ONLINE,
/**
* The service is online, but may be experiencing issues.
* This could be due to high load or other issues.
*/
DEGRADED,
/**
* The service is offline and not operational.
*/
OFFLINE
}
}

@ -0,0 +1,62 @@
package xyz.mcutils.models.player;
import lombok.Getter;
import xyz.mcutils.models.CachedResponse;
import java.util.UUID;
@Getter
public class CachedPlayer extends CachedResponse {
/**
* The UUID of the player
*/
private UUID uniqueId;
/**
* The trimmed UUID of the player
*/
private String trimmedUniqueId;
/**
* The username of the player
*/
private String username;
/**
* The skin of the player, null if the
* player does not have a skin
*/
private Skin skin;
/**
* The cape of the player, null if the
* player does not have a cape
*/
private Cape cape;
/**
* The raw properties of the player
*/
private ProfileProperty[] rawProperties;
/**
* A profile property for the player.
*/
private static class ProfileProperty {
/**
* The name of the property.
*/
private String name;
/**
* The base64 value of the property.
*/
private String value;
/**
* Whether the property is signed.
*/
private boolean signed;
}
}

@ -0,0 +1,12 @@
package xyz.mcutils.models.player;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor @Getter
public class CachedPlayerSkinPart {
/**
* The bytes for the skin part
*/
private byte[] partBytes;
}

@ -0,0 +1,19 @@
package xyz.mcutils.models.player;
import lombok.Getter;
import xyz.mcutils.models.CachedResponse;
import java.util.UUID;
@Getter
public class CachedUsernameToUuid extends CachedResponse {
/**
* The username of the player.
*/
private String username;
/**
* The unique id of the player.
*/
private UUID uniqueId;
}

@ -0,0 +1,8 @@
package xyz.mcutils.models.player;
public class Cape {
/**
* The URL of the cape
*/
private String url;
}

@ -0,0 +1,51 @@
package xyz.mcutils.models.player;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
public class Skin {
/**
* The URL for the skin
*/
private String url;
/**
* The model for the skin
*/
private Model model;
/**
* The legacy status of the skin
*/
private boolean legacy;
/**
* The part URLs of the skin
*/
private Map<String, String> parts = new HashMap<>();
/**
* The model of the skin.
*/
public enum Model {
DEFAULT,
SLIM
}
@AllArgsConstructor
@Getter
public enum SkinPart {
HEAD("head"),
FACE("face"),
BODY("body");
/**
* The name of the skin part
*/
private final String name;
}
}

@ -0,0 +1,75 @@
package xyz.mcutils.models.server;
import lombok.Getter;
import lombok.ToString;
@Getter
public class CachedBedrockMinecraftServer extends MinecraftServer {
/**
* The unique ID of this server.
*/
private String id;
/**
* The edition of this server.
*/
private Edition edition;
/**
* The version information of this server.
*/
private Version version;
/**
* The gamemode of this server.
*/
private GameMode gamemode;
/**
* The edition of a Bedrock server.
*/
@Getter
public enum Edition {
/**
* Minecraft: Pocket Edition.
*/
MCPE,
/**
* Minecraft: Education Edition.
*/
MCEE
}
/**
* Version information for a server.
*/
@Getter @ToString
public static class Version {
/**
* The protocol version of the server.
*/
private int protocol;
/**
* The version name of the server.
*/
private String name;
}
/**
* The gamemode of a server.
*/
@Getter @ToString
public static class GameMode {
/**
* The name of this gamemode.
*/
private String name;
/**
* The numeric of this gamemode.
*/
private int numericId;
}
}

@ -0,0 +1,181 @@
package xyz.mcutils.models.server;
import lombok.Getter;
import lombok.ToString;
@Getter
public class CachedJavaMinecraftServer extends MinecraftServer {
/**
* The version of the server.
*/
private Version version;
/**
* The favicon of the server.
*/
private Favicon favicon;
/**
* The mods running on this server.
*/
private ForgeModInfo modInfo;
/**
* The mods running on this server.
* <p>
* This is only used for servers
* running 1.13 and above.
* </p>
*/
private ForgeData forgeData;
/**
* Whether the server prevents chat reports.
*/
private boolean preventsChatReports;
/**
* Whether the server enforces secure chat.
*/
private boolean enforcesSecureChat;
/**
* Whether the server has previews chat enabled.
* <p>
* Chat Preview sends chat messages to the server as they are typed, even before they're sent.
* <a href="https://www.minecraft.net/es-mx/article/minecraft-snapshot-22w19a">More information</a>
* </p>
*/
private boolean previewsChat;
/**
* The mojang blocked status for the server.
*/
private boolean mojangBlocked;
@Getter
public static class Version {
/**
* The version name of the server.
*/
private String name;
/**
* The server platform.
*/
private String platform;
/**
* The protocol version.
*/
private int protocol;
/**
* The name of the protocol, null if not found.
*/
private String protocolName;
}
@Getter
public static class Favicon {
/**
* The raw base64 of the favicon.
*/
private String base64;
/**
* The url to the favicon.
*/
private String url;
}
/**
* Forge mod information for a server.
*/
@Getter @ToString
public static class ForgeModInfo {
/**
* The type of modded server this is.
*/
private String type;
/**
* The list of mods on this server, null or empty if none.
*/
private ForgeMod[] modList;
/**
* A forge mod for a server.
*/
@Getter @ToString
private static class ForgeMod {
/**
* The id of this mod.
*/
private String name;
/**
* The version of this mod.
*/
private String version;
}
}
@Getter
public static class ForgeData {
/**
* The list of mod channels on this server, null or empty if none.
*/
private Channel[] channels;
/**
* The list of mods on this server, null or empty if none.
*/
private Mod[] mods;
/**
* Whether the mod list is truncated.
*/
private boolean truncated;
/**
* The version of the FML network.
*/
private int fmlNetworkVersion;
@Getter
public static class Channel {
/**
* The id of this mod channel.
*/
private String name;
/**
* The version of this mod channel.
*/
private String version;
/**
* Whether this mod channel is required to join.
*/
private boolean required;
}
@Getter
public static class Mod {
/**
* The id of this mod.
*/
private String name;
/**
* The version of this mod.
*/
private String version;
}
}
}

@ -0,0 +1,12 @@
package xyz.mcutils.models.server;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor @Getter
public class CachedServerBlockedStatus {
/**
* Whether the server is Mojang blocked.
*/
private boolean blocked;
}

@ -0,0 +1,12 @@
package xyz.mcutils.models.server;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor @Getter
public class CachedServerIcon {
/**
* The bytes for the server icon.
*/
private byte[] bytes;
}

@ -0,0 +1,97 @@
package xyz.mcutils.models.server;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import xyz.mcutils.models.dns.DNSRecord;
import java.util.UUID;
@Getter
public class MinecraftServer {
/**
* The hostname of the server.
*/
private String hostname;
/**
* The IP address of the server.
*/
private String ip;
/**
* The port of the server.
*/
private int port;
/**
* The DNS records for the server.
*/
private DNSRecord[] records;
/**
* The motd for the server.
*/
private MOTD motd;
/**
* The players on the server.
*/
private Players players;
@AllArgsConstructor @Getter
private static class MOTD {
/**
* The raw motd lines
*/
private String[] raw;
/**
* The clean motd lines
*/
private String[] clean;
/**
* The html motd lines
*/
private String[] html;
}
/**
* Player count data for a server.
*/
@Getter
private static class Players {
/**
* The online players on this server.
*/
private int online;
/**
* The maximum allowed players on this server.
*/
private int max;
/**
* A sample of players on this server, null or empty if no sample.
*/
private Sample[] sample;
/**
* A sample player.
*/
@Getter @ToString
private static class Sample {
/**
* The unique id of this player.
*/
private UUID id;
/**
* The name of this player.
*/
private String name;
}
}
}

@ -0,0 +1,20 @@
package xyz.mcutils.models.server;
import lombok.Getter;
@Getter
public enum ServerPlatform {
/**
* The platform is Java Edition.
*/
JAVA,
/**
* The platform is Bedrock Edition.
*/
BEDROCK;
/**
* The name of the platform.
*/
private final String name = name().toLowerCase();
}

@ -0,0 +1,15 @@
package xyz.mcutils;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import xyz.mcutils.models.mojang.CachedMojangEndpointStatus;
public class MojangTests {
@Test
@SneakyThrows
public void ensureMojangApiStatusSuccess() {
CachedMojangEndpointStatus status = McUtilsAPI.getMojangApiStatus();
assert !status.getEndpoints().isEmpty();
}
}

@ -0,0 +1,77 @@
package xyz.mcutils;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import xyz.mcutils.exception.ErrorResponse;
import xyz.mcutils.models.player.CachedPlayer;
import xyz.mcutils.models.player.CachedPlayerSkinPart;
import xyz.mcutils.models.player.CachedUsernameToUuid;
import xyz.mcutils.models.player.Skin;
public class PlayerTests {
private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";
private final String testPlayer = "ImFascinated";
private final String testInvalidPlayer = "invalidplayeromgyeswow";
@Test
@SneakyThrows
public void ensurePlayerLookupUuidSuccess() {
CachedPlayer player = McUtilsAPI.getPlayer(testPlayerUuid);
assert player.getUsername().equals(testPlayer);
}
@Test
@SneakyThrows
public void ensurePlayerLookupUuidFailure() {
try {
McUtilsAPI.getPlayer(testInvalidPlayer);
} catch (ErrorResponse ex) {
assert ex.getCode() == 404;
}
}
@Test
@SneakyThrows
public void ensurePlayerLookupUsernameSuccess() {
CachedPlayer player = McUtilsAPI.getPlayer(testPlayer);
assert player.getUsername().equals(testPlayer);
}
@Test
@SneakyThrows
public void ensurePlayerLookupUsernameFailure() {
try {
McUtilsAPI.getPlayer(testInvalidPlayer);
} catch (ErrorResponse ex) {
assert ex.getCode() == 404;
}
}
@Test
@SneakyThrows
public void ensurePlayerUsernameToUuidLookupSuccess() {
CachedUsernameToUuid player = McUtilsAPI.getUsernameToUuid(testPlayer);
assert player.getUsername().equals(testPlayer);
assert player.getUniqueId().toString().equals(testPlayerUuid);
}
@Test
@SneakyThrows
public void ensurePlayerUsernameToUuidLookupFailure() {
try {
McUtilsAPI.getUsernameToUuid(testInvalidPlayer);
} catch (ErrorResponse ex) {
assert ex.getCode() == 404;
}
}
@Test
@SneakyThrows
public void ensurePlayerSkinPartsLookupSuccess() {
for (Skin.SkinPart part : Skin.SkinPart.values()) {
CachedPlayerSkinPart partBytes = McUtilsAPI.getPlayerSkinPart(part, testPlayer);
assert partBytes.getPartBytes() != null;
}
}
}

@ -0,0 +1,74 @@
package xyz.mcutils;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import xyz.mcutils.exception.ErrorResponse;
import xyz.mcutils.models.server.CachedBedrockMinecraftServer;
import xyz.mcutils.models.server.CachedJavaMinecraftServer;
import xyz.mcutils.models.server.CachedServerBlockedStatus;
import xyz.mcutils.models.server.CachedServerIcon;
public class ServerTests {
private final String testJavaServer = "play.hypixel.net";
private final String testBedrockServer = "geo.hivebedrock.network";
private final String testInvalidServer = "invalidhostnamehahahahahayesslmaooo";
@Test
@SneakyThrows
public void ensureJavaServerLookupSuccess() {
CachedJavaMinecraftServer server = McUtilsAPI.getJavaServer(testJavaServer);
assert server.getHostname().equals(testJavaServer);
}
@Test
@SneakyThrows
public void ensureJavaServerLookupFailure() {
try {
McUtilsAPI.getJavaServer(testInvalidServer);
} catch (ErrorResponse ex) {
assert ex.getCode() == 400;
}
}
@Test
@SneakyThrows
public void ensureJavaServerIconLookupSuccess() {
CachedServerIcon icon = McUtilsAPI.getServerIcon(testJavaServer);
assert icon.getBytes() != null;
}
@Test
@SneakyThrows
public void ensureJavaServerIconLookupFailure() {
try {
McUtilsAPI.getServerIcon(testInvalidServer);
} catch (ErrorResponse ex) {
assert ex.getCode() == 400;
}
}
@Test
@SneakyThrows
public void ensureJavaServerBlockedLookupSuccess() {
CachedServerBlockedStatus status = McUtilsAPI.getServerBlockedStatus(testJavaServer);
assert !status.isBlocked();
}
@Test
@SneakyThrows
public void ensureBedrockServerLookupSuccess() {
CachedBedrockMinecraftServer server = McUtilsAPI.getBedrockServer(testBedrockServer);
assert server.getHostname().equals(testBedrockServer);
}
@Test
@SneakyThrows
public void ensureBedrockServerLookupFailure() {
try {
McUtilsAPI.getBedrockServer(testInvalidServer);
} catch (ErrorResponse ex) {
assert ex.getCode() == 400;
}
}
}