3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-07-06 07:18:03 +02:00

Hotfix ProtocolLib 5.0.0 compatibility

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-03-09 17:41:36 +01:00
Ursprung f55696a605
Commit c1b993c01b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
2 geänderte Dateien mit 22 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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 {

Datei anzeigen

@ -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);
}
}