Start whining about ProtocolLib

This commit is contained in:
libraryaddict 2020-06-27 21:20:03 +12:00
parent ffd6536565
commit 31672fce7b
2 changed files with 42 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package me.libraryaddict.disguise; package me.libraryaddict.disguise;
import com.comphenix.protocol.ProtocolLib;
import com.comphenix.protocol.ProtocolLibrary;
import lombok.Getter; import lombok.Getter;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand; import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand; import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
@ -78,6 +80,17 @@ public class LibsDisguises extends JavaPlugin {
"reloads gracefully!"); "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 { try {
Class cl = Class.forName("org.bukkit.Server$Spigot"); Class cl = Class.forName("org.bukkit.Server$Spigot");
} }

View File

@ -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() { public static Logger getLogger() {
return LibsDisguises.getInstance().getLogger(); return LibsDisguises.getInstance().getLogger();
} }