Skip to content

Commit

Permalink
improve server type and version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 2, 2025
1 parent be0d646 commit 5a3b110
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.manager.server.VersionComparison;
import de.tr7zw.changeme.nbtapi.NBT;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.config.Config;
Expand Down Expand Up @@ -102,8 +101,9 @@ public void onEnable() {
" "
).map(str -> Component.text(str).color(KyoriUtil.AEF_WHITE)).forEach(prefixedLogger::info);

prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
prefixedLogger.info("Detected {} {}", PlatformUtil.getServerType().niceName(),
serverVersion.name().replace("V_", "").replace('_', '.'));
if (serverVersion.isOlderThanOrEquals(ServerVersion.V_1_19_3) ||
serverVersion.equals(ServerVersion.V_1_19_4) && !PlatformUtil.isFolia()) {
prefixedLogger.error("This plugin jar is incompatible with your Server. Please use the Legacy jar.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public void onEnable() {
" "
).forEach(prefixedLogger::info);

prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
prefixedLogger.info("Detected {} {}", PlatformUtil.getServerType().niceName(),
serverVersion.name().replace("V_", "").replace('_', '.'));
if (serverVersion.isNewerThan(ServerVersion.V_1_19_4)) {
prefixedLogger.warn("Legacy is intended for Paper server versions 1.12 - 1.19.4.");
prefixedLogger.warn("Please use the Folia jar for your server to avoid issues due to old API calls.");
Expand Down
31 changes: 30 additions & 1 deletion shared/src/main/java/me/xginko/aef/utils/PlatformUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public final class PlatformUtil {

private static int minecraftVersion, minecraftPatchVersion, minecraftPreReleaseVersion, minecraftReleaseCandidateVersion;
private static boolean isServerPaper, isServerFolia, isServerPurpur;
private static boolean isServerPaper, isServerFolia, isServerPurpur, isServerSpigot;

public static void load() {
isServerPurpur
Expand All @@ -20,6 +20,8 @@ public static void load() {
|| Crafty.hasClass("io.papermc.paper.configuration.Configuration");
isServerFolia
= Crafty.hasClass("io.papermc.paper.threadedregions.RegionizedServer");
isServerSpigot
= Crafty.hasClass("org.spigotmc.SpigotConfig");

// From PaperLib
Matcher matcher = Pattern.compile("(?i)\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?(?: (Pre-Release|Release Candidate) )?(\\d)?\\)")
Expand Down Expand Up @@ -77,4 +79,31 @@ public static int getMinecraftPreReleaseVersion() {
public static int getMinecraftReleaseCandidateVersion() {
return minecraftReleaseCandidateVersion;
}

public static ServerType getServerType() {
if (isServerFolia) return ServerType.FOLIA;
if (isServerPurpur) return ServerType.PURPUR;
if (isServerPaper) return ServerType.PAPER;
if (isServerSpigot) return ServerType.SPIGOT;
return ServerType.UNKNOWN;
}

public enum ServerType {

PAPER("Paper"),
PURPUR("Purpur"),
FOLIA("Folia"),
SPIGOT("Spigot"),
UNKNOWN("Unknown");

private final String niceName;

ServerType(String niceName) {
this.niceName = niceName;
}

public String niceName() {
return niceName;
}
}
}

0 comments on commit 5a3b110

Please sign in to comment.