Skip to content

Commit

Permalink
improve accuracy of startup version test
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 2, 2025
1 parent e24f3f2 commit 6585a6b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.xginko.aef;

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 @@ -65,13 +68,6 @@ public void onEnable() {
return;
}

if (PlatformUtil.getMinecraftVersion() < 19) {
getLogger().severe("The Folia jar is intended for Paper and Folia servers running 1.19 and above.");
getLogger().severe("Please replace it with the Legacy jar.");
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger = ComponentLogger.logger(getLogger().getName());
unPrefixedLogger = ComponentLogger.logger("");

Expand Down Expand Up @@ -119,9 +115,20 @@ 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();
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.");
getServer().getPluginManager().disablePlugin(this);
return;
}

if (PlatformUtil.isFolia()) {
prefixedLogger.info("Detected Folia server.");
try {
Files.createDirectories(getDataFolder().toPath());
} catch (Exception e) {
prefixedLogger.error("Unable to create plugin directory.", e);
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger.info("Loading Config");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.xginko.aef;

import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import de.tr7zw.changeme.nbtapi.NBT;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.config.Config;
Expand Down Expand Up @@ -94,14 +96,6 @@ public void onEnable() {
return;
}

try {
Files.createDirectories(getDataFolder().toPath());
} catch (Exception e) {
prefixedLogger.error("Unable to create plugin directory.", e);
getServer().getPluginManager().disablePlugin(this);
return;
}

instance = this;
permissionHandler = PermissionHandler.create(this);
metrics = new Metrics(this, 8700);
Expand All @@ -118,13 +112,21 @@ public void onEnable() {
).forEach(prefixedLogger::info);

prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());

if (PlatformUtil.getMinecraftVersion() < 12) {
prefixedLogger.warn("This version is unsupported. Expect issues.");
} else if (PlatformUtil.getMinecraftVersion() > 19) {
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
if (serverVersion.isNewerThan(ServerVersion.V_1_19_4)) {
prefixedLogger.warn("Legacy is intended for Paper server versions 1.12 - 1.19.4.");
prefixedLogger.warn("Its highly recommended to use the Folia jar for your server.");
prefixedLogger.warn("Some modules may not work properly otherwise.");
prefixedLogger.warn("Please use the Folia jar for your server to avoid issues due to old API calls.");
}
if (serverVersion.isOlderThanOrEquals(ServerVersion.V_1_12_2)) {
prefixedLogger.warn("This version is officially unsupported. Expect issues.");
}

try {
Files.createDirectories(getDataFolder().toPath());
} catch (Exception e) {
prefixedLogger.error("Unable to create plugin directory.", e);
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger.info("Loading Datastore");
Expand Down

0 comments on commit 6585a6b

Please sign in to comment.