diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index cfa0f1dc..48c82d7e 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -67,7 +67,7 @@ public class LibsDisguises extends JavaPlugin { Plugin plugin = Bukkit.getPluginManager().getPlugin("ProtocolLib"); - if (plugin == null || DisguiseUtilities.isOlderThan(DisguiseUtilities.getProtocolLibRequiredVersion(), plugin.getDescription().getVersion())) { + if (plugin == null || DisguiseUtilities.isProtocolLibOutdated()) { getLogger().warning("Noticed you're using an older version of ProtocolLib (or not using it)! We're forcibly updating you!"); try { @@ -171,10 +171,10 @@ public class LibsDisguises extends JavaPlugin { return; } - String requiredProtocolLib = DisguiseUtilities.getProtocolLibRequiredVersion(); + String requiredProtocolLib = StringUtils.join(DisguiseUtilities.getProtocolLibRequiredVersion(), " or build #"); String version = ProtocolLibrary.getPlugin().getDescription().getVersion(); - if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { + if (DisguiseUtilities.isProtocolLibOutdated()) { getLogger().severe("!! May I have your attention please !!"); getLogger() .severe("Update your ProtocolLib! You are running " + version + " but the minimum version you should be on is " + requiredProtocolLib + diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 9d1d832b..bb239fe0 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -22,6 +22,7 @@ import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; import me.libraryaddict.disguise.utilities.parser.WatcherMethod; import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandExecutor; @@ -69,10 +70,10 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { } protected boolean isNotPremium(CommandSender sender) { - String requiredProtocolLib = DisguiseUtilities.getProtocolLibRequiredVersion(); + String requiredProtocolLib = StringUtils.join(DisguiseUtilities.getProtocolLibRequiredVersion(), " or build #"); String version = ProtocolLibrary.getPlugin().getDescription().getVersion(); - if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { + if (DisguiseUtilities.isProtocolLibOutdated()) { DisguiseUtilities.sendProtocolLibUpdateMessage(sender, version, requiredProtocolLib); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index e6ebdde6..e0c7aff4 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -460,8 +460,49 @@ public class DisguiseUtilities { } } - public static String getProtocolLibRequiredVersion() { - return !NmsVersion.v1_13.isSupported() ? "4.4.0" : NmsVersion.v1_16.isSupported() ? "4.6.0" : "4.5.1"; + public static String[] getProtocolLibRequiredVersion() { + // If we are on 1.12 + if (!NmsVersion.v1_13.isSupported()) { + return new String[]{"4.4.0"}; + } + + // If we are on 1.13, 1.14, 1.15 + if (!NmsVersion.v1_16.isSupported()) { + return new String[]{"4.5.1"}; + } + + // If we are on 1.16 + if (!NmsVersion.v1_17.isSupported()) { + return new String[]{"4.6.0"}; + } + + // If we are on 1.17, future release build or this dev build + return new String[]{"4.7.1", "521"}; + } + + public static boolean isProtocolLibOutdated() { + String plVersion = Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion(); + String[] reqVersion = getProtocolLibRequiredVersion(); + + // If this is also checking for a custom build, and PL has the custom build in.. + // We run this check first as the 4.7.1 isn't out, and it'd always tell us to update otherwise. + if (reqVersion.length > 1 && plVersion.contains("-SNAPSHOT-b")) { + try { + String build = plVersion.substring(plVersion.lastIndexOf("b") + 1); + + // Just incase they're running a custom build? + if (build.length() < 3) { + return false; + } + + int buildNo = Integer.parseInt(build); + + return buildNo < Integer.parseInt(reqVersion[1]); + } catch (Throwable ignored) { + } + } + + return isOlderThan(reqVersion[0], plVersion); } public static File updateProtocolLib() throws Exception { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java index 4479df33..ec83e27e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java @@ -19,6 +19,7 @@ import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.modded.ModdedEntity; import me.libraryaddict.disguise.utilities.modded.ModdedManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.RandomUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -329,10 +330,10 @@ public class DisguiseListener implements Listener { p.removeMetadata("ld_loggedin", LibsDisguises.getInstance()); plugin.getUpdateChecker().notifyUpdate(p); - String requiredProtocolLib = DisguiseUtilities.getProtocolLibRequiredVersion(); + String requiredProtocolLib = StringUtils.join(DisguiseUtilities.getProtocolLibRequiredVersion(), " or build #"); String version = ProtocolLibrary.getPlugin().getDescription().getVersion(); - if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { + if (DisguiseUtilities.isProtocolLibOutdated()) { DisguiseUtilities.sendProtocolLibUpdateMessage(p, version, requiredProtocolLib); new BukkitRunnable() {