Skip to content

Commit 5a3b110

Browse files
committed
improve server type and version detection
1 parent be0d646 commit 5a3b110

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/AnarchyExploitFixes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

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

105-
prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());
106104
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
105+
prefixedLogger.info("Detected {} {}", PlatformUtil.getServerType().niceName(),
106+
serverVersion.name().replace("V_", "").replace('_', '.'));
107107
if (serverVersion.isOlderThanOrEquals(ServerVersion.V_1_19_3) ||
108108
serverVersion.equals(ServerVersion.V_1_19_4) && !PlatformUtil.isFolia()) {
109109
prefixedLogger.error("This plugin jar is incompatible with your Server. Please use the Legacy jar.");

AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/AnarchyExploitFixes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ public void onEnable() {
107107
" "
108108
).forEach(prefixedLogger::info);
109109

110-
prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());
111110
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
111+
prefixedLogger.info("Detected {} {}", PlatformUtil.getServerType().niceName(),
112+
serverVersion.name().replace("V_", "").replace('_', '.'));
112113
if (serverVersion.isNewerThan(ServerVersion.V_1_19_4)) {
113114
prefixedLogger.warn("Legacy is intended for Paper server versions 1.12 - 1.19.4.");
114115
prefixedLogger.warn("Please use the Folia jar for your server to avoid issues due to old API calls.");

shared/src/main/java/me/xginko/aef/utils/PlatformUtil.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public final class PlatformUtil {
1111

1212
private static int minecraftVersion, minecraftPatchVersion, minecraftPreReleaseVersion, minecraftReleaseCandidateVersion;
13-
private static boolean isServerPaper, isServerFolia, isServerPurpur;
13+
private static boolean isServerPaper, isServerFolia, isServerPurpur, isServerSpigot;
1414

1515
public static void load() {
1616
isServerPurpur
@@ -20,6 +20,8 @@ public static void load() {
2020
|| Crafty.hasClass("io.papermc.paper.configuration.Configuration");
2121
isServerFolia
2222
= Crafty.hasClass("io.papermc.paper.threadedregions.RegionizedServer");
23+
isServerSpigot
24+
= Crafty.hasClass("org.spigotmc.SpigotConfig");
2325

2426
// From PaperLib
2527
Matcher matcher = Pattern.compile("(?i)\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?(?: (Pre-Release|Release Candidate) )?(\\d)?\\)")
@@ -77,4 +79,31 @@ public static int getMinecraftPreReleaseVersion() {
7779
public static int getMinecraftReleaseCandidateVersion() {
7880
return minecraftReleaseCandidateVersion;
7981
}
82+
83+
public static ServerType getServerType() {
84+
if (isServerFolia) return ServerType.FOLIA;
85+
if (isServerPurpur) return ServerType.PURPUR;
86+
if (isServerPaper) return ServerType.PAPER;
87+
if (isServerSpigot) return ServerType.SPIGOT;
88+
return ServerType.UNKNOWN;
89+
}
90+
91+
public enum ServerType {
92+
93+
PAPER("Paper"),
94+
PURPUR("Purpur"),
95+
FOLIA("Folia"),
96+
SPIGOT("Spigot"),
97+
UNKNOWN("Unknown");
98+
99+
private final String niceName;
100+
101+
ServerType(String niceName) {
102+
this.niceName = niceName;
103+
}
104+
105+
public String niceName() {
106+
return niceName;
107+
}
108+
}
80109
}

0 commit comments

Comments
 (0)