diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 6702238e..e3f0403e 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -1,5 +1,7 @@ package me.libraryaddict.disguise; +import com.comphenix.protocol.ProtocolLib; +import com.comphenix.protocol.ProtocolLibrary; import lombok.Getter; import me.libraryaddict.disguise.commands.LibsDisguisesCommand; import me.libraryaddict.disguise.commands.disguise.DisguiseCommand; @@ -78,6 +80,17 @@ public class LibsDisguises extends JavaPlugin { "reloads gracefully!"); } + String version = ProtocolLibrary.getPlugin().getDescription().getVersion(); + + String requiredProtocolLib = "4.5.1"; + + if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { + getLogger().severe("!! Attention please !!"); + getLogger().severe("Update your ProtocolLib! You are running " + version + + " but the minimum version you should be on is " + requiredProtocolLib + "!"); + getLogger().severe("!! Attention please !!"); + } + try { Class cl = Class.forName("org.bukkit.Server$Spigot"); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index e23fca15..05cdee97 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -2065,6 +2065,35 @@ public class DisguiseUtilities { } } + public static int[] getNumericVersion(String version) { + int[] v = new int[0]; + for (String split : version.split("\\.-")) { + if (!split.matches("[0-9]+")) { + return v; + } + + v = Arrays.copyOf(v, v.length + 1); + v[v.length - 1] = Integer.parseInt(split); + } + + return v; + } + + public static boolean isOlderThan(String requiredVersion, String theirVersion) { + int[] ourVersion = getNumericVersion(requiredVersion); + int[] theirs = getNumericVersion(theirVersion); + + for (int i = 0; i < Math.min(ourVersion.length, theirs.length); i++) { + if (ourVersion[i] <= theirs[i]) { + continue; + } + + return true; + } + + return false; + } + public static Logger getLogger() { return LibsDisguises.getInstance().getLogger(); }