This commit is contained in:
2022-11-14 01:06:44 +01:00
parent 564288c9ab
commit a0e590a2c1
14 changed files with 319 additions and 108 deletions

View File

@@ -2,7 +2,9 @@ package net.t2code.t2codelib.SPIGOT.api.update;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
import net.t2code.t2codelib.SPIGOT.system.UpdateType;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@@ -31,7 +33,7 @@ public class T2CupdateAPI {
}
T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData;
String pluginVersion = plugin.getDescription().getVersion();
if (pluginVersion.equals(webData.getTagName())) return;
if (!pluginVersions.get(plugin.getName()).updateAvailable) return;
new BukkitRunnable() {
@Override
public void run() {
@@ -41,61 +43,133 @@ public class T2CupdateAPI {
}
public static void sendUpdateMsg(String prefix, T2CupdateWebData webData, String discord, Plugin plugin, Player player) {
String publicVersion = webData.getTagName();
String publicVersion = webData.getVersion();
String pluginVersion = plugin.getDescription().getVersion();
if (publicVersion.equals("§4No public version found!")) {
if (!pluginVersions.get(plugin.getName()).updateAvailable) {
return;
}
String st = "[prefix]<br>" +
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <gold>A new</gold> [value]<gold>version was found!</gold></hover></click><br>" +
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <red>[plv]</red> <gray>-></gray> <green>[puv]</green></hover></click><br>" +
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <gold>A new</gold> [value] <gold>version was" +
" found!</gold></hover></click><br>" +
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <red>[plv]</red> <gray>-></gray> " +
"<green>[puv]</green></hover></click><br>" +
"<click:open_url:'[dc]'><hover:show_text:'<yellow>[dc]</yellow>'>[prefix] <gold>You can find more information on Discord.</gold></hover></click><br>" +
"[prefix] <blue><hover:show_text:'<red>Click for more information</red>'><click:run_command:'/t2c updateinfo " + plugin.getName() + "'>Update information</click></hover></blue><br>" +
"[prefix]";
String value = "";
String value;
if (webData.isPreRelease()) {
value = "<light_purple>Pre-Release </light_purple>";
value = UpdateType.PRERELEASE.text;
if (publicVersion.toLowerCase().contains("dev")) {
value = "<dark_red>DEV </dark_red>";
value = UpdateType.DEVELOPMENT.text;
}
if (publicVersion.toLowerCase().contains("beta")) {
value = "<green>BETA </green>";
value = UpdateType.BETA.text;
}
if (publicVersion.toLowerCase().contains("snapshot")) {
value = "<yellow>SNAPSHOT </yellow>";
value = UpdateType.SNAPSHOT.text;
}
}
} else value = UpdateType.STABLE.text;
T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", webData.getUpdateUrl())
.replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord));
}
public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin) {
String publicVersion =webData.getTagName();
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 = "§4=========== " + prefix + " §4===========";
String s1 = "";
String s1 = "§6A new [value] version was found!§r".replace("[value]", value);
String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion;
String s3 = "§6You can download it here: §e" + webData.getUpdateUrl();
String s4 = "§6You can find more information on Discord: §e" + discord;
if (webData.isPreRelease()) {
s1 = "§6A new §4Pre-Release§6 version was found!§r";
if (publicVersion.toLowerCase().contains("dev")) {
s1 = "§6A new §4DEV§6 version was found!§r";
}
if (publicVersion.toLowerCase().contains("beta")) {
s1 = "§6A new §2BETA§6 version was found!§r";
}
if (publicVersion.toLowerCase().contains("snapshot")) {
s1 = "§6A new §eSNAPSHOT§6 version was found!§r";
}
} else {
s1 = "§6A new version was found!§r";
}
String text = "<br>" + h + "<br>" + s1 + "<br>" + s2 + "<br>" + s3 + "<br>" + s4 + "<br>" + h;
T2Csend.console(text);
}
public static void onUpdateCheck(Plugin plugin, String prefix, Integer spigotID, String discord) {
public static String updateInfo(CommandSender sender, String[] args, Boolean player) {
T2CupdateObject object;
try {
object = T2CupdateAPI.pluginVersions.get(args[1]);
} catch (Exception e) {
return "Das Plugin " + args[1] + " gibts net"; // todo
}
T2CupdateWebData webData = object.webData;
String pluginName = T2CupdateAPI.pluginVersions.get(args[1]).pluginName;
String pluginVersion = T2CupdateAPI.pluginVersions.get(args[1]).pluginVersion;
String updateTitle = webData.getUpdateTitle();
String updateVersion = webData.getVersion();
String updateType;
if (webData.isPreRelease()) {
updateType = UpdateType.PRERELEASE.text;
if (updateVersion.toLowerCase().contains("dev")) {
updateType = UpdateType.DEVELOPMENT.text;
}
if (updateVersion.toLowerCase().contains("beta")) {
updateType = UpdateType.BETA.text;
}
if (updateVersion.toLowerCase().contains("snapshot")) {
updateType = UpdateType.SNAPSHOT.text;
}
} else updateType = UpdateType.STABLE.text;
String updateAt = webData.getPublishedAt();
String updateUpdate = webData.getUpdateUrl();
String updateDescription = webData.getUpdateDescription();
String pluginNameString = "<br><dark_red>║</dark_red> <yellow>Plugin:</yellow> <color:#5eff89>" + pluginName + "</color>";
String pluginVersionString = "<br><dark_red>║</dark_red> <yellow>Your version:</yellow> <color:#5eff89>" + pluginVersion + "</color>";
String updateInfoString = "<br><dark_red>║</dark_red> <color:#308aff>[value]:</color>";
String updateTitleString = "<br><dark_red>║</dark_red> <yellow>Title:</yellow> <color:#5eff89>" + updateTitle + "</color>";
String updateVersionString = "<br><dark_red>║</dark_red> <yellow>Version:</yellow> <color:#5eff89>" + updateVersion + "</color>";
String updateAtString = "<br><dark_red>║</dark_red> <yellow>Update at:</yellow> <color:#5eff89>" + updateAt + "</color>";
String updateTypeString = "<br><dark_red>║</dark_red> <yellow>Update type:</yellow> <color:#5eff89>" + updateType + "</color>";
String updateButton;
if (player) {
// updateButton = "<br><dark_red>║</dark_red> <color:#5eff89><hover:show_text:'<gold>" + updateUpdate + "</gold>'><click:open_url:'" + updateUpdate +"'>Download</click></hover></color>";
updateButton = "<br><dark_red>║</dark_red> <color:#5eff89><hover:show_text:'<gold>" + updateUpdate + "</gold>'><click:open_url:'" + updateUpdate + "'>Download</click></hover></color> <dark_gray>|</dark_gray> <blue><hover:show_text:'" + updateDescription + "'>Update Description</hover></blue>";
} else updateButton = "<br><dark_red>║</dark_red> <color:#5eff89>Download:</color> <gold>" + updateUpdate + "</gold>";
String text;
text = "<dark_red>╔══════════════════════</dark_red>";
text = text + pluginNameString;
text = text + pluginVersionString;
text = text + updateInfoString.replace("[value]", object.updateAvailable ? "Update available" : "Info about your version");
if (!updateTitle.equals("OLD")) text = text + updateTitleString;
if (object.updateAvailable) text = text + updateVersionString;
if (!updateTitle.equals("OLD")) text = text + updateAtString;
if (!updateTitle.equals("OLD")) text = text + updateTypeString;
if (object.updateAvailable)
text = text + updateButton;
if (updateTitle.equals("OLD")) text = text + "<br><dark_gray>This plugin does not have the new update checker yet, so there is no exact update / " +
"version information available!</dark_gray>";
text = text + "<br><dark_red>╚══════════════════════</dark_red>";
return text;
}
public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) {
new BukkitRunnable() {
@Override
public void run() {
@@ -105,10 +179,10 @@ public class T2CupdateAPI {
plugin.getDescription().getVersion(),
new T2CupdateWebData("OLD", update_version, "", "https://www.spigotmc.org/resources/" + spigotID, "",
"https://www.spigotmc.org/resources/" + spigotID, false),
false
false, !plugin.getDescription().getVersion().equals(update_version)
);
pluginVersions.put(plugin.getName(), update);
if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
if (!pluginVersions.get(plugin.getName()).updateAvailable) {
if (!update.load) {
new BukkitRunnable() {
@Override
@@ -142,10 +216,11 @@ public class T2CupdateAPI {
plugin.getName(),
plugin.getDescription().getVersion(),
webData,
false
false,
!plugin.getDescription().getVersion().equals(webData.getVersion())
);
pluginVersions.put(plugin.getName(), update);
if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTagName())) {
if (!pluginVersions.get(plugin.getName()).updateAvailable) {
if (!update.load) {
new BukkitRunnable() {
@Override

View File

@@ -62,7 +62,8 @@ public class T2CupdateChecker {
plugin.getName(),
pluginVersion,
null,
load
load,
false
);
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());

View File

@@ -8,6 +8,8 @@ import org.json.JSONObject;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.function.Consumer;
public class T2CupdateCheckerGit {
@@ -41,10 +43,16 @@ public class T2CupdateCheckerGit {
JSONObject obj = new JSONObject(data);
String UpdateName = obj.getString("name");
String tag_name = obj.getString("tag_name");
String body = obj.getString("body");
String updateurl = obj.getString("url");
String body = obj.getString("body").replace("\n","<br>").replace("\r","").replace("'","''");
String updateurl = obj.getString("html_url");
boolean prerelease = obj.getBoolean("prerelease");
String published_at = obj.getString("published_at");
String date = obj.getString("published_at");
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
Date parsedDate = inputFormat.parse(date);
String formattedDate = outputFormat.format(parsedDate);
JSONArray downloadArray = obj.getJSONArray("assets");
String downloadURL;
if (downloadArray.isEmpty()) {
@@ -58,7 +66,7 @@ public class T2CupdateCheckerGit {
updateurl = "https://www.spigotmc.org/resources/" + spigotID;
}
T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, published_at, downloadURL, prerelease);
T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, formattedDate, downloadURL, prerelease);
consumer.accept(webData);
} catch (Exception var10) {
Boolean load = false;
@@ -69,7 +77,8 @@ public class T2CupdateCheckerGit {
plugin.getName(),
pluginVersion,
null,
load
load,
false
);
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());

View File

@@ -7,14 +7,17 @@ public class T2CupdateObject {
public String pluginVersion;
public T2CupdateWebData webData;
public Boolean load;
public Boolean updateAvailable;
public T2CupdateObject(String pluginName,
String pluginVersion,
T2CupdateWebData webData,
Boolean load) {
Boolean load,
Boolean updateAvailable) {
this.pluginName = pluginName;
this.pluginVersion = pluginVersion;
this.webData = webData;
this.load = load;
this.updateAvailable = updateAvailable;
}
}

View File

@@ -4,11 +4,11 @@ import lombok.Getter;
public class T2CupdateWebData {
@Getter
private String updateName;
private String updateTitle;
@Getter
private String tagName;
private String version;
@Getter
private String body;
private String updateDescription;
@Getter
private String updateUrl;
@Getter
@@ -18,10 +18,10 @@ public class T2CupdateWebData {
@Getter
private boolean preRelease;
public T2CupdateWebData(String updateName, String tagName, String body, String updateUrl, String publishedAt, String downloadURL, boolean preRelease) {
this.updateName = updateName;
this.tagName = tagName;
this.body = body;
public T2CupdateWebData(String updateTitle, String version, String updateDescription, String updateUrl, String publishedAt, String downloadURL, boolean preRelease) {
this.updateTitle = updateTitle;
this.version = version;
this.updateDescription = updateDescription;
this.updateUrl = updateUrl;
this.publishedAt = publishedAt;
this.downloadURL = downloadURL;