rename the package
This commit is contained in:
@ -0,0 +1,121 @@
|
||||
package cc.fascinated.model.server;
|
||||
|
||||
import cc.fascinated.model.dns.DNSRecord;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* A Bedrock edition {@link MinecraftServer}.
|
||||
*
|
||||
* @author Braydon
|
||||
*/
|
||||
@Getter @ToString(callSuper = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
|
||||
public final class BedrockMinecraftServer extends MinecraftServer {
|
||||
/**
|
||||
* The unique ID of this server.
|
||||
*/
|
||||
@EqualsAndHashCode.Include @NonNull private final String id;
|
||||
|
||||
/**
|
||||
* The edition of this server.
|
||||
*/
|
||||
@NonNull private final Edition edition;
|
||||
|
||||
/**
|
||||
* The version information of this server.
|
||||
*/
|
||||
@NonNull private final Version version;
|
||||
|
||||
/**
|
||||
* The gamemode of this server.
|
||||
*/
|
||||
@NonNull private final GameMode gamemode;
|
||||
|
||||
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);
|
||||
this.id = id;
|
||||
this.edition = edition;
|
||||
this.version = version;
|
||||
this.gamemode = gamemode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Bedrock Minecraft server.
|
||||
*
|
||||
* @param hostname the hostname of the server
|
||||
* @param ip the IP address of the server
|
||||
* @param port the port of the server
|
||||
* @param token the status token
|
||||
* @return the Bedrock Minecraft server
|
||||
*/
|
||||
@NonNull
|
||||
public static BedrockMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, @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]);
|
||||
Players players = new Players(Integer.parseInt(split[4]), Integer.parseInt(split[5]), null);
|
||||
MOTD motd = MOTD.create(split[1] + "\n" + split[7]);
|
||||
GameMode gameMode = new GameMode(split[8], Integer.parseInt(split[9]));
|
||||
return new BedrockMinecraftServer(
|
||||
split[6],
|
||||
hostname,
|
||||
ip,
|
||||
port,
|
||||
records,
|
||||
edition,
|
||||
version,
|
||||
players,
|
||||
motd,
|
||||
gameMode
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The edition of a Bedrock server.
|
||||
*/
|
||||
@AllArgsConstructor @Getter
|
||||
public enum Edition {
|
||||
/**
|
||||
* Minecraft: Pocket Edition.
|
||||
*/
|
||||
MCPE,
|
||||
|
||||
/**
|
||||
* Minecraft: Education Edition.
|
||||
*/
|
||||
MCEE
|
||||
}
|
||||
|
||||
/**
|
||||
* Version information for a server.
|
||||
*/
|
||||
@AllArgsConstructor @Getter @ToString
|
||||
public static class Version {
|
||||
/**
|
||||
* The protocol version of the server.
|
||||
*/
|
||||
private final int protocol;
|
||||
|
||||
/**
|
||||
* The version name of the server.
|
||||
*/
|
||||
@NonNull private final String name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The gamemode of a server.
|
||||
*/
|
||||
@AllArgsConstructor @Getter @ToString
|
||||
public static class GameMode {
|
||||
/**
|
||||
* The name of this gamemode.
|
||||
*/
|
||||
@NonNull private final String name;
|
||||
|
||||
/**
|
||||
* The numeric of this gamemode.
|
||||
*/
|
||||
private final int numericId;
|
||||
}
|
||||
}
|
@ -0,0 +1,271 @@
|
||||
package cc.fascinated.model.server;
|
||||
|
||||
import xyz.mcutils.backend.Main;
|
||||
import cc.fascinated.common.JavaMinecraftVersion;
|
||||
import cc.fascinated.common.ServerUtils;
|
||||
import cc.fascinated.config.Config;
|
||||
import cc.fascinated.model.dns.DNSRecord;
|
||||
import cc.fascinated.model.token.JavaServerStatusToken;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.*;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
/**
|
||||
* @author Braydon
|
||||
*/
|
||||
@Setter @Getter
|
||||
public final class JavaMinecraftServer extends MinecraftServer {
|
||||
|
||||
/**
|
||||
* The version of the server.
|
||||
*/
|
||||
@NonNull private final 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;
|
||||
|
||||
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);
|
||||
this.version = version;
|
||||
this.favicon = favicon;
|
||||
this.modInfo = modInfo;
|
||||
this.forgeData = forgeData;
|
||||
this.preventsChatReports = preventsChatReports;
|
||||
this.enforcesSecureChat = enforcesSecureChat;
|
||||
this.previewsChat = previewsChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Java Minecraft server.
|
||||
*
|
||||
* @param hostname the hostname of the server
|
||||
* @param ip the IP address of the server
|
||||
* @param port the port of the server
|
||||
* @param token the status token
|
||||
* @return the Java Minecraft server
|
||||
*/
|
||||
@NonNull
|
||||
public static JavaMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, @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();
|
||||
}
|
||||
return new JavaMinecraftServer(
|
||||
hostname,
|
||||
ip,
|
||||
port,
|
||||
MinecraftServer.MOTD.create(motdString),
|
||||
token.getPlayers(),
|
||||
records,
|
||||
token.getVersion().detailedCopy(),
|
||||
JavaMinecraftServer.Favicon.create(token.getFavicon(), ServerUtils.getAddress(hostname, port)),
|
||||
token.getModInfo(),
|
||||
token.getForgeData(),
|
||||
token.isPreventsChatReports(),
|
||||
token.isEnforcesSecureChat(),
|
||||
token.isPreviewsChat()
|
||||
);
|
||||
}
|
||||
|
||||
@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 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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forge mod information for a server.
|
||||
*/
|
||||
@AllArgsConstructor @Getter @ToString
|
||||
public static class ForgeModInfo {
|
||||
/**
|
||||
* The type of modded server this is.
|
||||
*/
|
||||
@NonNull private final String type;
|
||||
|
||||
/**
|
||||
* The list of mods on this server, null or empty if none.
|
||||
*/
|
||||
private final ForgeMod[] modList;
|
||||
|
||||
/**
|
||||
* A forge mod for a server.
|
||||
*/
|
||||
@AllArgsConstructor @Getter @ToString
|
||||
private static class ForgeMod {
|
||||
/**
|
||||
* The id of this mod.
|
||||
*/
|
||||
@NonNull @SerializedName("modid") private final String name;
|
||||
|
||||
/**
|
||||
* The version of this mod.
|
||||
*/
|
||||
private final String version;
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor @Getter
|
||||
public static class ForgeData {
|
||||
|
||||
/**
|
||||
* The list of mod channels on this server, null or empty if none.
|
||||
*/
|
||||
private final Channel[] channels;
|
||||
|
||||
/**
|
||||
* The list of mods on this server, null or empty if none.
|
||||
*/
|
||||
private final Mod[] mods;
|
||||
|
||||
/**
|
||||
* Whether the mod list is truncated.
|
||||
*/
|
||||
private final boolean truncated;
|
||||
|
||||
/**
|
||||
* The version of the FML network.
|
||||
*/
|
||||
private final int fmlNetworkVersion;
|
||||
|
||||
@AllArgsConstructor @Getter
|
||||
public static class Channel {
|
||||
/**
|
||||
* The id of this mod channel.
|
||||
*/
|
||||
@NonNull @SerializedName("res") private final String name;
|
||||
|
||||
/**
|
||||
* The version of this mod channel.
|
||||
*/
|
||||
private final String version;
|
||||
|
||||
/**
|
||||
* Whether this mod channel is required to join.
|
||||
*/
|
||||
private boolean required;
|
||||
}
|
||||
|
||||
@AllArgsConstructor @Getter
|
||||
public static class Mod {
|
||||
/**
|
||||
* The id of this mod.
|
||||
*/
|
||||
@NonNull @SerializedName("modId") private final String name;
|
||||
|
||||
/**
|
||||
* The version of this mod.
|
||||
*/
|
||||
@SerializedName("modmarker") private final String version;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package cc.fascinated.model.server;
|
||||
|
||||
import cc.fascinated.common.ColorUtils;
|
||||
import cc.fascinated.model.dns.DNSRecord;
|
||||
import xyz.mcutils.backend.service.pinger.MinecraftServerPinger;
|
||||
import xyz.mcutils.backend.service.pinger.impl.BedrockMinecraftServerPinger;
|
||||
import xyz.mcutils.backend.service.pinger.impl.JavaMinecraftServerPinger;
|
||||
import io.micrometer.common.lang.NonNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Braydon
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter @Setter
|
||||
public class MinecraftServer {
|
||||
|
||||
/**
|
||||
* The hostname of the server.
|
||||
*/
|
||||
private final String hostname;
|
||||
|
||||
/**
|
||||
* The IP address of the server.
|
||||
*/
|
||||
private final String ip;
|
||||
|
||||
/**
|
||||
* The port of the server.
|
||||
*/
|
||||
private final int port;
|
||||
|
||||
/**
|
||||
* The DNS records for the server.
|
||||
*/
|
||||
private final DNSRecord[] records;
|
||||
|
||||
/**
|
||||
* The motd for the server.
|
||||
*/
|
||||
private final MOTD motd;
|
||||
|
||||
/**
|
||||
* The players on the server.
|
||||
*/
|
||||
private final Players players;
|
||||
|
||||
/**
|
||||
* A platform a Minecraft
|
||||
* server can operate on.
|
||||
*/
|
||||
@AllArgsConstructor @Getter
|
||||
public enum Platform {
|
||||
/**
|
||||
* The Java edition of Minecraft.
|
||||
*/
|
||||
JAVA(new JavaMinecraftServerPinger(), 25565),
|
||||
|
||||
/**
|
||||
* The Bedrock edition of Minecraft.
|
||||
*/
|
||||
BEDROCK(new BedrockMinecraftServerPinger(), 19132);
|
||||
|
||||
/**
|
||||
* The server pinger for this platform.
|
||||
*/
|
||||
@NonNull
|
||||
private final MinecraftServerPinger<?> pinger;
|
||||
|
||||
/**
|
||||
* The default server port for this platform.
|
||||
*/
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Player count data for a server.
|
||||
*/
|
||||
@AllArgsConstructor @Getter
|
||||
public static class Players {
|
||||
/**
|
||||
* The online players on this server.
|
||||
*/
|
||||
private final int online;
|
||||
|
||||
/**
|
||||
* The maximum allowed players on this server.
|
||||
*/
|
||||
private final int max;
|
||||
|
||||
/**
|
||||
* A sample of players on this server, null or empty if no sample.
|
||||
*/
|
||||
private final Sample[] sample;
|
||||
|
||||
/**
|
||||
* A sample player.
|
||||
*/
|
||||
@AllArgsConstructor @Getter @ToString
|
||||
public static class Sample {
|
||||
/**
|
||||
* The unique id of this player.
|
||||
*/
|
||||
@NonNull private final UUID id;
|
||||
|
||||
/**
|
||||
* The name of this player.
|
||||
*/
|
||||
@NonNull private final String name;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user