Hotfix ProtocolLib 5.0.0 compatibility

This commit is contained in:
Nassim Jahnke 2022-03-09 17:41:36 +01:00
parent f55696a605
commit c1b993c01b
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 22 additions and 3 deletions

View File

@ -89,8 +89,8 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
@Override
public void onLoad() {
// Via should load before PL, so we can't check for it in the constructor
boolean hasProtocolLib = Bukkit.getPluginManager().getPlugin("ProtocolLib") != null;
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(hasProtocolLib);
Plugin protocolLib = Bukkit.getPluginManager().getPlugin("ProtocolLib");
ProtocolLibEnableListener.checkCompat(protocolLib);
// Spigot detector
try {

View File

@ -23,6 +23,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;
public class ProtocolLibEnableListener implements Listener {
@ -30,7 +32,7 @@ public class ProtocolLibEnableListener implements Listener {
public void onPluginEnable(PluginEnableEvent e) {
// Will likely never happen, but try to account for hacky plugin loading systems anyways
if (e.getPlugin().getName().equals("ProtocolLib")) {
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(true);
checkCompat(e.getPlugin());
}
}
@ -40,4 +42,21 @@ public class ProtocolLibEnableListener implements Listener {
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(false);
}
}
public static void checkCompat(@Nullable Plugin protocolLib) {
if (protocolLib != null) {
String version = protocolLib.getDescription().getVersion();
String majorVersion = version.split("\\.", 2)[0];
try {
// Only need the compat check for version < 5
if (Integer.parseInt(majorVersion) < 5) {
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(true);
return;
}
} catch (NumberFormatException ignored) {
Via.getPlatform().getLogger().warning("ProtocolLib version check failed for version " + version);
}
}
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(false);
}
}