Add more Java server flags

This commit is contained in:
Braydon 2024-04-06 21:39:42 -04:00
parent a7e6ca2458
commit 7a5219de8e
5 changed files with 42 additions and 16 deletions

@ -2,7 +2,6 @@ package me.braydon.mc.model;
import lombok.*;
import me.braydon.mc.common.ColorUtils;
import me.braydon.mc.model.token.JavaServerStatusToken;
import me.braydon.mc.service.pinger.MinecraftServerPinger;
import me.braydon.mc.service.pinger.impl.BedrockMinecraftServerPinger;
import me.braydon.mc.service.pinger.impl.JavaMinecraftServerPinger;
@ -52,14 +51,6 @@ public class MinecraftServer {
*/
private final String icon;
/**
* Is this server on the list
* of blocked servers by Mojang?
*
* @see <a href="https://wiki.vg/Mojang_API#Blocked_Servers">Mojang API</a>
*/
private final boolean mojangBanned;
/**
* Version information for a server.
*/
@ -142,7 +133,7 @@ public class MinecraftServer {
@AllArgsConstructor @Getter @ToString
public static class MOTD {
/**
* The raw MOTD lines, taken directly from the {@link JavaServerStatusToken}.
* The raw MOTD lines.
*/
@NonNull private final String[] raw;

@ -10,7 +10,7 @@ import me.braydon.mc.model.MinecraftServer;
*/
public final class BedrockMinecraftServer extends MinecraftServer {
private BedrockMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Version version,
@NonNull Players players, @NonNull MOTD motd, String icon, boolean mojangBanned) {
super(hostname, ip, port, version, players, motd, icon, mojangBanned);
@NonNull Players players, @NonNull MOTD motd, String icon) {
super(hostname, ip, port, version, players, motd, icon);
}
}

@ -1,5 +1,6 @@
package me.braydon.mc.model.server;
import lombok.Getter;
import lombok.NonNull;
import me.braydon.mc.RESTfulMC;
import me.braydon.mc.model.MinecraftServer;
@ -12,10 +13,33 @@ import net.md_5.bungee.chat.ComponentSerializer;
*
* @author Braydon
*/
@Getter
public final class JavaMinecraftServer extends MinecraftServer {
/**
* Does this server enforce secure chat?
*/
private final boolean enforcesSecureChat;
/**
* Is this server preventing chat reports?
*/
private final boolean preventsChatReports;
/**
* Is this server on the list
* of blocked servers by Mojang?
*
* @see <a href="https://wiki.vg/Mojang_API#Blocked_Servers">Mojang API</a>
*/
private final boolean mojangBanned;
private JavaMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull Version version,
@NonNull Players players, @NonNull MOTD motd, String icon, boolean mojangBanned) {
super(hostname, ip, port, version, players, motd, icon, mojangBanned);
@NonNull Players players, @NonNull MOTD motd, String icon, boolean enforcesSecureChat,
boolean preventsChatReports, boolean mojangBanned) {
super(hostname, ip, port, version, players, motd, icon);
this.enforcesSecureChat = enforcesSecureChat;
this.preventsChatReports = preventsChatReports;
this.mojangBanned = mojangBanned;
}
/**
@ -33,8 +57,8 @@ public final class JavaMinecraftServer extends MinecraftServer {
if (motdString == null) { // Not a string motd, convert from Json
motdString = new TextComponent(ComponentSerializer.parse(RESTfulMC.GSON.toJson(token.getDescription()))).toLegacyText();
}
return new JavaMinecraftServer(hostname, ip, port, token.getVersion().detailedCopy(),
token.getPlayers(), MOTD.create(motdString), token.getFavicon(), false
return new JavaMinecraftServer(hostname, ip, port, token.getVersion().detailedCopy(), token.getPlayers(),
MOTD.create(motdString), token.getFavicon(), token.isEnforcesSecureChat(), token.isPreventsChatReports(), false
);
}
}

@ -37,4 +37,14 @@ public final class JavaServerStatusToken {
* The player counts of this server.
*/
@NonNull private final MinecraftServer.Players players;
/**
* Does this server enforce secure chat?
*/
private final boolean enforcesSecureChat;
/**
* Is this server preventing chat reports?
*/
private final boolean preventsChatReports;
}

@ -60,6 +60,7 @@ public final class JavaMinecraftServerPinger implements MinecraftServerPinger<Ja
// Send the status request to the server, and await back the response
PacketStatusInStart packetStatusInStart = new PacketStatusInStart();
packetStatusInStart.process(inputStream, outputStream);
System.out.println("JSON ::: " + packetStatusInStart.getResponse());
JavaServerStatusToken token = RESTfulMC.GSON.fromJson(packetStatusInStart.getResponse(), JavaServerStatusToken.class);
return JavaMinecraftServer.create(hostname, ip, port, token); // Return the server
}