Skip to content

Commit 6585a6b

Browse files
committed
improve accuracy of startup version test
1 parent e24f3f2 commit 6585a6b

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package me.xginko.aef;
22

3+
import com.github.retrooper.packetevents.PacketEvents;
4+
import com.github.retrooper.packetevents.manager.server.ServerVersion;
5+
import com.github.retrooper.packetevents.manager.server.VersionComparison;
36
import de.tr7zw.changeme.nbtapi.NBT;
47
import me.xginko.aef.commands.AEFCommand;
58
import me.xginko.aef.config.Config;
@@ -65,13 +68,6 @@ public void onEnable() {
6568
return;
6669
}
6770

68-
if (PlatformUtil.getMinecraftVersion() < 19) {
69-
getLogger().severe("The Folia jar is intended for Paper and Folia servers running 1.19 and above.");
70-
getLogger().severe("Please replace it with the Legacy jar.");
71-
getServer().getPluginManager().disablePlugin(this);
72-
return;
73-
}
74-
7571
prefixedLogger = ComponentLogger.logger(getLogger().getName());
7672
unPrefixedLogger = ComponentLogger.logger("");
7773

@@ -119,9 +115,20 @@ public void onEnable() {
119115
).map(str -> Component.text(str).color(KyoriUtil.AEF_WHITE)).forEach(prefixedLogger::info);
120116

121117
prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());
118+
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
119+
if (serverVersion.isOlderThanOrEquals(ServerVersion.V_1_19_3) ||
120+
serverVersion.equals(ServerVersion.V_1_19_4) && !PlatformUtil.isFolia()) {
121+
prefixedLogger.error("This plugin jar is incompatible with your Server. Please use the Legacy jar.");
122+
getServer().getPluginManager().disablePlugin(this);
123+
return;
124+
}
122125

123-
if (PlatformUtil.isFolia()) {
124-
prefixedLogger.info("Detected Folia server.");
126+
try {
127+
Files.createDirectories(getDataFolder().toPath());
128+
} catch (Exception e) {
129+
prefixedLogger.error("Unable to create plugin directory.", e);
130+
getServer().getPluginManager().disablePlugin(this);
131+
return;
125132
}
126133

127134
prefixedLogger.info("Loading Config");

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.xginko.aef;
22

3+
import com.github.retrooper.packetevents.PacketEvents;
4+
import com.github.retrooper.packetevents.manager.server.ServerVersion;
35
import de.tr7zw.changeme.nbtapi.NBT;
46
import me.xginko.aef.commands.AEFCommand;
57
import me.xginko.aef.config.Config;
@@ -94,14 +96,6 @@ public void onEnable() {
9496
return;
9597
}
9698

97-
try {
98-
Files.createDirectories(getDataFolder().toPath());
99-
} catch (Exception e) {
100-
prefixedLogger.error("Unable to create plugin directory.", e);
101-
getServer().getPluginManager().disablePlugin(this);
102-
return;
103-
}
104-
10599
instance = this;
106100
permissionHandler = PermissionHandler.create(this);
107101
metrics = new Metrics(this, 8700);
@@ -118,13 +112,21 @@ public void onEnable() {
118112
).forEach(prefixedLogger::info);
119113

120114
prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());
121-
122-
if (PlatformUtil.getMinecraftVersion() < 12) {
123-
prefixedLogger.warn("This version is unsupported. Expect issues.");
124-
} else if (PlatformUtil.getMinecraftVersion() > 19) {
115+
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
116+
if (serverVersion.isNewerThan(ServerVersion.V_1_19_4)) {
125117
prefixedLogger.warn("Legacy is intended for Paper server versions 1.12 - 1.19.4.");
126-
prefixedLogger.warn("Its highly recommended to use the Folia jar for your server.");
127-
prefixedLogger.warn("Some modules may not work properly otherwise.");
118+
prefixedLogger.warn("Please use the Folia jar for your server to avoid issues due to old API calls.");
119+
}
120+
if (serverVersion.isOlderThanOrEquals(ServerVersion.V_1_12_2)) {
121+
prefixedLogger.warn("This version is officially unsupported. Expect issues.");
122+
}
123+
124+
try {
125+
Files.createDirectories(getDataFolder().toPath());
126+
} catch (Exception e) {
127+
prefixedLogger.error("Unable to create plugin directory.", e);
128+
getServer().getPluginManager().disablePlugin(this);
129+
return;
128130
}
129131

130132
prefixedLogger.info("Loading Datastore");

0 commit comments

Comments
 (0)