This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package cc.fascinated.model.mojang;
|
||||
|
||||
import cc.fascinated.model.server.JavaMinecraftServer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
@ -9,5 +10,24 @@ import lombok.ToString;
|
||||
*/
|
||||
@AllArgsConstructor @Getter @ToString
|
||||
public final class JavaServerStatusToken {
|
||||
|
||||
/**
|
||||
* The version of the server.
|
||||
*/
|
||||
private final JavaMinecraftServer.Version version;
|
||||
|
||||
/**
|
||||
* The players on the server.
|
||||
*/
|
||||
private final JavaMinecraftServer.Players players;
|
||||
|
||||
/**
|
||||
* The motd of the server.
|
||||
*/
|
||||
private final String description;
|
||||
}
|
||||
|
||||
/**
|
||||
* The favicon of the server.
|
||||
*/
|
||||
private final String favicon;
|
||||
}
|
||||
|
@ -1,10 +1,128 @@
|
||||
package cc.fascinated.model.server;
|
||||
|
||||
import cc.fascinated.common.JavaMinecraftVersion;
|
||||
import cc.fascinated.config.Config;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author Braydon
|
||||
*/
|
||||
@Setter @Getter
|
||||
public final class JavaMinecraftServer extends MinecraftServer {
|
||||
public JavaMinecraftServer(String hostname, String ip, int port, String motd) {
|
||||
|
||||
/**
|
||||
* The version of the server.
|
||||
*/
|
||||
@NonNull private final Version version;
|
||||
|
||||
/**
|
||||
* The players on the server.
|
||||
*/
|
||||
private Players players;
|
||||
|
||||
/**
|
||||
* The favicon of the server.
|
||||
*/
|
||||
private Favicon favicon;
|
||||
|
||||
public JavaMinecraftServer(String hostname, String ip, int port, MOTD motd, @NonNull Version version, Players players, Favicon favicon) {
|
||||
super(hostname, ip, port, motd);
|
||||
this.version = version;
|
||||
this.players = players;
|
||||
this.favicon = favicon;
|
||||
}
|
||||
|
||||
@AllArgsConstructor @Getter
|
||||
public static class Version {
|
||||
/**
|
||||
* The version name of the server.
|
||||
*/
|
||||
@NonNull
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The server platform.
|
||||
*/
|
||||
private String platform;
|
||||
|
||||
/**
|
||||
* The protocol version.
|
||||
*/
|
||||
private final int protocol;
|
||||
|
||||
/**
|
||||
* The name of the protocol, null if not found.
|
||||
*/
|
||||
private final String protocolName;
|
||||
|
||||
/**
|
||||
* Create a more detailed
|
||||
* copy of this object.
|
||||
*
|
||||
* @return the detailed copy
|
||||
*/
|
||||
@NonNull
|
||||
public Version detailedCopy() {
|
||||
String platform = null;
|
||||
if (name.contains(" ")) { // Parse the server platform
|
||||
String[] split = name.split(" ");
|
||||
if (split.length == 2) {
|
||||
platform = split[0];
|
||||
}
|
||||
}
|
||||
JavaMinecraftVersion minecraftVersion = JavaMinecraftVersion.byProtocol(protocol);
|
||||
return new Version(name, platform, protocol, minecraftVersion == null ? null : minecraftVersion.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Getter @AllArgsConstructor
|
||||
public static class Players {
|
||||
|
||||
/**
|
||||
* The maximum amount of players the server can hold.
|
||||
*/
|
||||
private final int max;
|
||||
|
||||
/**
|
||||
* The amount of players currently online.
|
||||
*/
|
||||
private final int online;
|
||||
|
||||
/**
|
||||
* The sample of players currently online.
|
||||
*/
|
||||
private final String[] sample;
|
||||
}
|
||||
|
||||
@Getter @AllArgsConstructor
|
||||
public static class Favicon {
|
||||
|
||||
/**
|
||||
* The raw base64 of the favicon.
|
||||
*/
|
||||
private final String base64;
|
||||
|
||||
/**
|
||||
* The url to the favicon.
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* Create a new favicon for a server.
|
||||
*
|
||||
* @param base64 the base64 of the favicon
|
||||
* @param address the address of the server
|
||||
* @return the new favicon
|
||||
*/
|
||||
public static Favicon create(String base64, @NonNull String address) {
|
||||
if (base64 == null) { // The server doesn't have a favicon
|
||||
return null;
|
||||
}
|
||||
return new Favicon(base64, Config.INSTANCE.getWebPublicUrl() + "/server/icon/%s".formatted(address));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cc.fascinated.model.server;
|
||||
|
||||
import cc.fascinated.common.ColorUtils;
|
||||
import cc.fascinated.service.pinger.MinecraftServerPinger;
|
||||
import cc.fascinated.service.pinger.impl.JavaMinecraftServerPinger;
|
||||
import io.micrometer.common.lang.NonNull;
|
||||
@ -7,6 +8,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Braydon
|
||||
*/
|
||||
@ -15,7 +18,7 @@ public class MinecraftServer {
|
||||
private final String hostname;
|
||||
private final String ip;
|
||||
private final int port;
|
||||
private final String motd;
|
||||
private final MOTD motd;
|
||||
|
||||
/**
|
||||
* A platform a Minecraft
|
||||
@ -39,4 +42,39 @@ public class MinecraftServer {
|
||||
*/
|
||||
private final int defaultPort;
|
||||
}
|
||||
|
||||
@AllArgsConstructor @Getter
|
||||
public static class MOTD {
|
||||
|
||||
/**
|
||||
* The raw motd lines
|
||||
*/
|
||||
private final String[] raw;
|
||||
|
||||
/**
|
||||
* The clean motd lines
|
||||
*/
|
||||
private final String[] clean;
|
||||
|
||||
/**
|
||||
* The html motd lines
|
||||
*/
|
||||
private final String[] html;
|
||||
|
||||
/**
|
||||
* Create a new MOTD from a raw string.
|
||||
*
|
||||
* @param raw the raw motd string
|
||||
* @return the new motd
|
||||
*/
|
||||
@NonNull
|
||||
public static MOTD create(@NonNull String raw) {
|
||||
String[] rawLines = raw.split("\n"); // The raw lines
|
||||
return new MOTD(
|
||||
rawLines,
|
||||
Arrays.stream(rawLines).map(ColorUtils::stripColor).toArray(String[]::new),
|
||||
Arrays.stream(rawLines).map(ColorUtils::toHTML).toArray(String[]::new)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user