Add /ld updateprotocollib, improve version checking for nms
This commit is contained in:
parent
31672fce7b
commit
f3d5f7efc3
@ -80,17 +80,6 @@ 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");
|
||||||
}
|
}
|
||||||
@ -131,6 +120,19 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String requiredProtocolLib = DisguiseUtilities.getProtocolLibRequiredVersion();
|
||||||
|
String version = ProtocolLibrary.getPlugin().getDescription().getVersion();
|
||||||
|
|
||||||
|
if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) {
|
||||||
|
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 + "!");
|
||||||
|
getLogger()
|
||||||
|
.severe("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target/ProtocolLib" +
|
||||||
|
".jar");
|
||||||
|
getLogger().severe("!! May I have your attention please !!");
|
||||||
|
}
|
||||||
|
|
||||||
// If this is a release build, even if jenkins build..
|
// If this is a release build, even if jenkins build..
|
||||||
if (isReleaseBuild()) {
|
if (isReleaseBuild()) {
|
||||||
// If downloaded from spigot, forcibly set release build to true
|
// If downloaded from spigot, forcibly set release build to true
|
||||||
|
@ -34,6 +34,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
|
|||||||
getCommands().add(new LDMetaInfo());
|
getCommands().add(new LDMetaInfo());
|
||||||
getCommands().add(new LDDebugPlayer());
|
getCommands().add(new LDDebugPlayer());
|
||||||
getCommands().add(new LDUploadLogs());
|
getCommands().add(new LDUploadLogs());
|
||||||
|
getCommands().add(new LDUpdateProtocolLib());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
|
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
package me.libraryaddict.disguise.commands.libsdisguises;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||||
|
import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
|
||||||
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by libraryaddict on 30/06/2020.
|
||||||
|
*/
|
||||||
|
public class LDUpdateProtocolLib implements LDCommand {
|
||||||
|
private final AtomicBoolean updateInProgress = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getTabComplete() {
|
||||||
|
return Arrays.asList("updateprotocollib");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(CommandSender sender) {
|
||||||
|
return sender.isOp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCommand(CommandSender sender, String[] args) {
|
||||||
|
if (updateInProgress.get()) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Update already in progress");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.RED + "Please hold, now downloading..");
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
File protocolLibFile = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Method getFile = JavaPlugin.class.getDeclaredMethod("getFile");
|
||||||
|
getFile.setAccessible(true);
|
||||||
|
File theirFile = (File) getFile.invoke(ProtocolLibrary.getPlugin());
|
||||||
|
File dest = new File("plugins/update/" + theirFile.getName());
|
||||||
|
|
||||||
|
// We're connecting to spigot's API
|
||||||
|
URL url = new URL(
|
||||||
|
"https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target/ProtocolLib" +
|
||||||
|
".jar");
|
||||||
|
// Creating a connection
|
||||||
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "libraryaddict/LibsDisguises");
|
||||||
|
|
||||||
|
// Get the input stream, what we receive
|
||||||
|
try (InputStream input = con.getInputStream()) {
|
||||||
|
Files.copy(input, dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Update success! Restart server to finish update!");
|
||||||
|
}
|
||||||
|
}.runTask(LibsDisguises.getInstance());
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Update failed, " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}.runTask(LibsDisguises.getInstance());
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
updateInProgress.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(LibsDisguises.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LibsMsg getHelp() {
|
||||||
|
return LibsMsg.LD_COMMAND_UPDATEPROTOCOLLIB;
|
||||||
|
}
|
||||||
|
}
|
@ -35,6 +35,8 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
|||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||||
import me.libraryaddict.disguise.utilities.watchers.CompileMethods;
|
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.StringUtils;
|
||||||
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.apache.logging.log4j.util.Strings;
|
import org.apache.logging.log4j.util.Strings;
|
||||||
@ -152,6 +154,7 @@ public class DisguiseUtilities {
|
|||||||
private static boolean invalidFile;
|
private static boolean invalidFile;
|
||||||
@Getter
|
@Getter
|
||||||
private static char[] alphabet = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();
|
private static char[] alphabet = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||||
|
private static Pattern hexColor;
|
||||||
|
|
||||||
public static void setPlayerVelocity(Player player) {
|
public static void setPlayerVelocity(Player player) {
|
||||||
if (player == null) {
|
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
|
* 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;
|
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NmsVersion.v1_16.isSupported()) {
|
||||||
|
hexColor = Pattern.compile("<#[0-9a-fA-F]{6}>");
|
||||||
}
|
}
|
||||||
|
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
@ -2067,7 +2077,7 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
public static int[] getNumericVersion(String version) {
|
public static int[] getNumericVersion(String version) {
|
||||||
int[] v = new int[0];
|
int[] v = new int[0];
|
||||||
for (String split : version.split("\\.-")) {
|
for (String split : version.split("\\.|-")) {
|
||||||
if (!split.matches("[0-9]+")) {
|
if (!split.matches("[0-9]+")) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@ -2079,6 +2089,33 @@ public class DisguiseUtilities {
|
|||||||
return v;
|
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) {
|
public static boolean isOlderThan(String requiredVersion, String theirVersion) {
|
||||||
int[] ourVersion = getNumericVersion(requiredVersion);
|
int[] ourVersion = getNumericVersion(requiredVersion);
|
||||||
int[] theirs = getNumericVersion(theirVersion);
|
int[] theirs = getNumericVersion(theirVersion);
|
||||||
@ -2401,8 +2438,13 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||||
|
|
||||||
Object name = NmsVersion.v1_13.isSupported() ? Optional.of(WrappedChatComponent.fromText(newNames[i])) :
|
Object name;
|
||||||
newNames[i];
|
|
||||||
|
if (NmsVersion.v1_13.isSupported()) {
|
||||||
|
name = Optional.of(WrappedChatComponent.fromText(newNames[i]));
|
||||||
|
} else {
|
||||||
|
name = newNames[i];
|
||||||
|
}
|
||||||
|
|
||||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(
|
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(
|
||||||
NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME :
|
NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME :
|
||||||
|
@ -19,6 +19,7 @@ import me.libraryaddict.disguise.utilities.modded.ModdedManager;
|
|||||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||||
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -323,6 +324,20 @@ public class DisguiseListener implements Listener {
|
|||||||
p.removeMetadata("ld_loggedin", LibsDisguises.getInstance());
|
p.removeMetadata("ld_loggedin", LibsDisguises.getInstance());
|
||||||
plugin.getUpdateChecker().notifyUpdate(p);
|
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() &&
|
if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() &&
|
||||||
DisguiseUtilities.hasGameProfile(p.getName())) {
|
DisguiseUtilities.hasGameProfile(p.getName())) {
|
||||||
WrappedGameProfile profile = WrappedGameProfile.fromPlayer(p);
|
WrappedGameProfile profile = WrappedGameProfile.fromPlayer(p);
|
||||||
|
@ -14,6 +14,6 @@ public enum NmsVersion {
|
|||||||
* If this nms version isn't newer than the running version
|
* If this nms version isn't newer than the running version
|
||||||
*/
|
*/
|
||||||
public boolean isSupported() {
|
public boolean isSupported() {
|
||||||
return ReflectionManager.getVersion().ordinal() >= ordinal();
|
return ReflectionManager.getVersion() != null && ReflectionManager.getVersion().ordinal() >= ordinal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,6 +327,8 @@ public enum LibsMsg {
|
|||||||
USING_DEFAULT_CONFIG(ChatColor.DARK_GREEN + "Using the default config!"),
|
USING_DEFAULT_CONFIG(ChatColor.DARK_GREEN + "Using the default config!"),
|
||||||
LIBS_SCOREBOARD_ISSUES(ChatColor.GREEN + "Too many issues found, hidden %s"),
|
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"),
|
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_HELP(ChatColor.BLUE + "/libsdisguises help - " + ChatColor.AQUA + "Returns this!"),
|
||||||
LD_COMMAND_COUNT(ChatColor.BLUE + "/libsdisguises count - " + ChatColor.AQUA +
|
LD_COMMAND_COUNT(ChatColor.BLUE + "/libsdisguises count - " + ChatColor.AQUA +
|
||||||
"Tells you how many active disguises there are"),
|
"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..");
|
SELF_DISGUISE_HIDDEN(ChatColor.GREEN + "Self disguise hidden as it's too tall..");
|
||||||
|
|
||||||
private final String string;
|
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) {
|
LibsMsg(String string) {
|
||||||
this.string = string;
|
this.string = string;
|
||||||
@ -378,30 +371,7 @@ public enum LibsMsg {
|
|||||||
public BaseComponent[] getChat(Object... strings) {
|
public BaseComponent[] getChat(Object... strings) {
|
||||||
String string = get(strings);
|
String string = get(strings);
|
||||||
|
|
||||||
if (hexColor == null) {
|
return DisguiseUtilities.getColoredChat(string);
|
||||||
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 String get(Object... strings) {
|
public String get(Object... strings) {
|
||||||
|
Loading…
Reference in New Issue
Block a user