83 lines
4.2 KiB
Java
83 lines
4.2 KiB
Java
package net.t2code.t2codelib.BUNGEE.api.update;
|
|
|
|
import net.md_5.bungee.api.CommandSender;
|
|
import net.md_5.bungee.api.ProxyServer;
|
|
import net.md_5.bungee.api.plugin.Plugin;
|
|
import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend;
|
|
import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig;
|
|
import net.t2code.t2codelib.T2CupdateObject;
|
|
import net.t2code.t2codelib.T2CupdateWebData;
|
|
import net.t2code.t2codelib.UpdateType;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
public class T2CBupdateAPI {
|
|
public static HashMap<String, T2CupdateObject> bungeePluginVersins = new HashMap<>();
|
|
|
|
public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin, CommandSender sender) {
|
|
String publicVersion = webData.getVersion();
|
|
String pluginVersion = plugin.getDescription().getVersion();
|
|
String value;
|
|
if (webData.isPreRelease()) {
|
|
value = UpdateType.PRERELEASE.text;
|
|
if (publicVersion.toLowerCase().contains("dev")) {
|
|
value = UpdateType.DEVELOPMENT.text;
|
|
}
|
|
if (publicVersion.toLowerCase().contains("beta")) {
|
|
value = UpdateType.BETA.text;
|
|
}
|
|
if (publicVersion.toLowerCase().contains("snapshot")) {
|
|
value = UpdateType.SNAPSHOT.text;
|
|
}
|
|
} else value = UpdateType.STABLE.text;
|
|
String h = "<br><dark_red>╔══════════════</dark_red>" + prefix + "<dark_red>══════════════</dark_red>";
|
|
String s1 = "<br><dark_red>║</dark_red> <gold>A new [value] version was found!</gold>".replace("[value]", value);
|
|
String s2 = "<br><dark_red>║</dark_red> <gold>Your version: <red>" + pluginVersion + "</red> <gray>-</gray> Current version:</gold> <green>" + webData.getVersion() + "</green>";
|
|
String s3 = "<br><dark_red>║</dark_red> <gold>You can download it here:</gold> <yellow>" + webData.getUpdateUrl() + "</yellow>";
|
|
String s4 = "<br><dark_red>║</dark_red> <gold>You can find more information on Discord:</gold> <yellow>" + discord + "</yellow>";
|
|
String f = "<br><dark_red>╚══════════════</dark_red>" + prefix + "<dark_red>══════════════</dark_red>";
|
|
String text = h + s1 + s2 + s3 + s4 + f;
|
|
if (sender == null) {
|
|
T2CBsend.console(text);
|
|
} else T2CBsend.sender(sender, text);
|
|
|
|
}
|
|
|
|
private static Boolean noUpdate = true;
|
|
private static String pluginVersion;
|
|
|
|
public static void onUpdateCheckTimer(Plugin plugin, String prefix, String discord, Integer spigotID, String url) {
|
|
Integer finalInterval;
|
|
if (T2CBlibConfig.getUpdateTimer() < 1){
|
|
finalInterval = 1;
|
|
} else finalInterval = T2CBlibConfig.getUpdateTimer();
|
|
ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() {
|
|
public void run() {
|
|
if (T2CBlibConfig.getUpdateCheckFullDisable()) return;
|
|
(new T2CBupdateCheckerGit(plugin, spigotID)).getVersion((webData) -> {
|
|
pluginVersion = plugin.getDescription().getVersion();
|
|
T2CupdateObject update = new T2CupdateObject(
|
|
plugin.getDescription().getName(),
|
|
plugin.getDescription().getVersion(),
|
|
webData,
|
|
false,
|
|
!plugin.getDescription().getVersion().equals(webData.getVersion()),
|
|
true
|
|
);
|
|
bungeePluginVersins.put(plugin.getDescription().getName(), update);
|
|
if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(webData.getVersion())) {
|
|
sendUpdateMsg(prefix, discord, webData, plugin, null);
|
|
noUpdate = true;
|
|
} else {
|
|
if (noUpdate) {
|
|
T2CBsend.console(prefix + " §2No update found.");
|
|
noUpdate = false;
|
|
}
|
|
}
|
|
}, pluginVersion, spigotID, url);
|
|
}
|
|
}, 0, finalInterval * 60 * 20L, TimeUnit.SECONDS);
|
|
}
|
|
}
|