Add /ld updateprotocollib, improve version checking for nms

This commit is contained in:
libraryaddict
2020-06-30 16:06:27 +12:00
parent 31672fce7b
commit f3d5f7efc3
7 changed files with 185 additions and 48 deletions

View File

@@ -35,6 +35,8 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.watchers.CompileMethods;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.logging.log4j.util.Strings;
@@ -152,6 +154,7 @@ public class DisguiseUtilities {
private static boolean invalidFile;
@Getter
private static char[] alphabet = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();
private static Pattern hexColor;
public static void setPlayerVelocity(Player player) {
if (player == null) {
@@ -163,6 +166,10 @@ public class DisguiseUtilities {
}
}
public static String getProtocolLibRequiredVersion() {
return NmsVersion.v1_16.isSupported() ? "4.6.0" : "4.5.1";
}
/**
* Returns if this velocity is due to a PlayerVelocityEvent
*/
@@ -972,7 +979,10 @@ public class DisguiseUtilities {
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
}
catch (Exception ex) {
}
if (NmsVersion.v1_16.isSupported()) {
hexColor = Pattern.compile("<#[0-9a-fA-F]{6}>");
}
GsonBuilder gsonBuilder = new GsonBuilder();
@@ -2067,7 +2077,7 @@ public class DisguiseUtilities {
public static int[] getNumericVersion(String version) {
int[] v = new int[0];
for (String split : version.split("\\.-")) {
for (String split : version.split("\\.|-")) {
if (!split.matches("[0-9]+")) {
return v;
}
@@ -2079,6 +2089,33 @@ public class DisguiseUtilities {
return v;
}
public static BaseComponent[] getColoredChat(String string) {
if (hexColor == null) {
return new ComponentBuilder().appendLegacy(string).create();
}
Matcher match = hexColor.matcher(string);
ComponentBuilder builder = new ComponentBuilder();
int lastMatch = 0;
while (match.find()) {
if (match.start() > lastMatch) {
builder.appendLegacy(string.substring(lastMatch, match.start()));
}
lastMatch = match.end();
builder.color(net.md_5.bungee.api.ChatColor.of(match.group().substring(1, 8)));
}
if (lastMatch < string.length()) {
builder.appendLegacy(string.substring(lastMatch));
}
return builder.create();
}
public static boolean isOlderThan(String requiredVersion, String theirVersion) {
int[] ourVersion = getNumericVersion(requiredVersion);
int[] theirs = getNumericVersion(theirVersion);
@@ -2401,8 +2438,13 @@ public class DisguiseUtilities {
WrappedDataWatcher watcher = new WrappedDataWatcher();
Object name = NmsVersion.v1_13.isSupported() ? Optional.of(WrappedChatComponent.fromText(newNames[i])) :
newNames[i];
Object name;
if (NmsVersion.v1_13.isSupported()) {
name = Optional.of(WrappedChatComponent.fromText(newNames[i]));
} else {
name = newNames[i];
}
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(
NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME :

View File

@@ -19,6 +19,7 @@ import me.libraryaddict.disguise.utilities.modded.ModdedManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
@@ -323,6 +324,20 @@ public class DisguiseListener implements Listener {
p.removeMetadata("ld_loggedin", LibsDisguises.getInstance());
plugin.getUpdateChecker().notifyUpdate(p);
if (p.isOp()) {
String requiredProtocolLib = DisguiseUtilities.getProtocolLibRequiredVersion();
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) {
p.sendMessage(ChatColor.RED + "Update your ProtocolLib! You are running " + version +
" but the minimum version you should be on is " + requiredProtocolLib + "!");
p.sendMessage(ChatColor.RED + "https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" +
"/ProtocolLib" +
".jar");
p.sendMessage(ChatColor.RED + "Use /ld updateprotocollib - To update to the latest development build");
}
}
if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() &&
DisguiseUtilities.hasGameProfile(p.getName())) {
WrappedGameProfile profile = WrappedGameProfile.fromPlayer(p);

View File

@@ -14,6 +14,6 @@ public enum NmsVersion {
* If this nms version isn't newer than the running version
*/
public boolean isSupported() {
return ReflectionManager.getVersion().ordinal() >= ordinal();
return ReflectionManager.getVersion() != null && ReflectionManager.getVersion().ordinal() >= ordinal();
}
}

View File

@@ -327,6 +327,8 @@ public enum LibsMsg {
USING_DEFAULT_CONFIG(ChatColor.DARK_GREEN + "Using the default config!"),
LIBS_SCOREBOARD_ISSUES(ChatColor.GREEN + "Too many issues found, hidden %s"),
LIBS_SCOREBOARD_NO_ISSUES(ChatColor.GREEN + "No issues found in player disguise scoreboard name teams"),
LD_COMMAND_UPDATEPROTOCOLLIB(ChatColor.BLUE + "/libsdisguises updateprotocollib - " + ChatColor.AQUA +
"Updates ProtocolLib to the latest development version"),
LD_COMMAND_HELP(ChatColor.BLUE + "/libsdisguises help - " + ChatColor.AQUA + "Returns this!"),
LD_COMMAND_COUNT(ChatColor.BLUE + "/libsdisguises count - " + ChatColor.AQUA +
"Tells you how many active disguises there are"),
@@ -357,15 +359,6 @@ public enum LibsMsg {
SELF_DISGUISE_HIDDEN(ChatColor.GREEN + "Self disguise hidden as it's too tall..");
private final String string;
private static final Pattern hexColor;
static {
if (NmsVersion.v1_16.isSupported()) {
hexColor = Pattern.compile("<#[0-9a-fA-F]{6}>");
} else {
hexColor = null;
}
}
LibsMsg(String string) {
this.string = string;
@@ -378,30 +371,7 @@ public enum LibsMsg {
public BaseComponent[] getChat(Object... strings) {
String string = get(strings);
if (hexColor == null) {
return new ComponentBuilder().appendLegacy(string).create();
}
Matcher match = hexColor.matcher(string);
ComponentBuilder builder = new ComponentBuilder();
int lastMatch = 0;
while (match.find()) {
if (match.start() > lastMatch) {
builder.appendLegacy(string.substring(lastMatch, match.start()));
}
lastMatch = match.end();
builder.color(net.md_5.bungee.api.ChatColor.of(match.group().substring(1, 8)));
}
if (lastMatch < string.length()) {
builder.appendLegacy(string.substring(lastMatch));
}
return builder.create();
return DisguiseUtilities.getColoredChat(string);
}
public String get(Object... strings) {