mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 01:55:47 +01:00
Hotfix ProtocolLib 5.0.0 compatibility
This commit is contained in:
parent
f55696a605
commit
c1b993c01b
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user