From f0b5b2e65b600fa6f24633dc312f42904626a7e5 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 22:37:36 +0100 Subject: [PATCH] 13.4_SNAPSHOT-2 - From now on a different temporary path is used to create the debug zip to avoid data garbage. - The design of the update messages was changed --- pom.xml | 5 +- .../BUNGEE/api/update/T2CBupdateAPI.java | 74 +-------------- .../api/update/T2CBupdateCheckerGit.java | 91 +++++++++++++++++++ .../SPIGOT/api/update/T2CupdateAPI.java | 43 ++++----- .../api/update/T2CupdateCheckerGit.java | 2 +- .../t2codelib/SPIGOT/system/cmd/Commands.java | 1 + .../SPIGOT/system/cmd/CreateReportLog.java | 13 ++- src/main/java/net/t2code/t2codelib/Util.java | 2 +- 8 files changed, 127 insertions(+), 104 deletions(-) create mode 100644 src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java diff --git a/pom.xml b/pom.xml index 8298a3b..0fbc6fb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 13.4_SNAPSHOT-1 + 13.4_SNAPSHOT-2 jar T2CodeLib @@ -94,7 +94,6 @@ https://nexus.bencodez.com/repository/maven-public/ net.t2code @@ -186,5 +184,4 @@ compile - diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java index 8a1156c..8e2bf32 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java @@ -61,7 +61,7 @@ public class T2CBupdateAPI { public static void onUpdateCheckTimer(Plugin plugin, String prefix, String discord, Integer spigotID, String url) { ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() { public void run() { - (new T2CBupdateAPI(plugin, spigotID)).getVersion((webData) -> { + (new T2CBupdateCheckerGit(plugin, spigotID)).getVersion((webData) -> { pluginVersion = plugin.getDescription().getVersion(); T2CupdateObject update = new T2CupdateObject( plugin.getDescription().getName(), @@ -84,76 +84,4 @@ public class T2CBupdateAPI { } }, 0, T2CBlibConfig.getUpdateTimer() * 60 * 20L, TimeUnit.SECONDS); } - - private Plugin plugin; - private int resourceId; - - public T2CBupdateAPI(Plugin plugin, int resourceId) { - this.plugin = plugin; - this.resourceId = resourceId; - } - - public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String URL) { - BungeeCord.getInstance().getScheduler().runAsync(this.plugin, () -> { - try { - URL url = new URL(URL); - URLConnection yc = url.openConnection(); - BufferedReader in = new BufferedReader( - new InputStreamReader( - yc.getInputStream())); - String inputLine; - String data = ""; - while ((inputLine = in.readLine()) != null) - data = inputLine; - in.close(); - data = data.substring(1, data.length() - 1); - if (data.isEmpty()) { - consumer.accept(null); - return; - } - JSONObject obj = new JSONObject(data); - String UpdateName = obj.getString("name"); - String tag_name = obj.getString("tag_name"); - String body = obj.getString("body").replace("\n", "
").replace("\r", "").replace("'", "''"); - String updateurl = obj.getString("html_url"); - boolean prerelease = obj.getBoolean("prerelease"); - - 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()) { - downloadURL = "https://www.spigotmc.org/resources/" + spigotID; - } else { - downloadURL = downloadArray.getJSONObject(0).getString("browser_download_url"); - } - - if (!prerelease) { - downloadURL = "https://www.spigotmc.org/resources/" + spigotID; - updateurl = "https://www.spigotmc.org/resources/" + spigotID; - } - - T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, formattedDate, downloadURL, prerelease); - consumer.accept(webData); - } catch (Exception var10) { - Boolean load = false; - if (bungeePluginVersins.containsKey(plugin.getDescription().getName())) { - load = bungeePluginVersins.get(plugin.getDescription().getName()).load; - } - T2CupdateObject update = new T2CupdateObject( - plugin.getDescription().getName(), - pluginVersion, - null, - load, - false - ); - bungeePluginVersins.put(plugin.getDescription().getName(), update); - this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage()); - } - }); - } } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java new file mode 100644 index 0000000..5571f51 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java @@ -0,0 +1,91 @@ +package net.t2code.t2codelib.BUNGEE.api.update; + +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.plugin.Plugin; +import net.t2code.t2codelib.T2CupdateObject; +import net.t2code.t2codelib.T2CupdateWebData; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.function.Consumer; + +public class T2CBupdateCheckerGit { + private Plugin plugin; + private int resourceId; + + public T2CBupdateCheckerGit(Plugin plugin, int resourceId) { + this.plugin = plugin; + this.resourceId = resourceId; + } + + public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String gitKey) { + String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; + BungeeCord.getInstance().getScheduler().runAsync(this.plugin, () -> { + try { + URL url = new URL(RepoURL); + URLConnection yc = url.openConnection(); + BufferedReader in = new BufferedReader( + new InputStreamReader( + yc.getInputStream())); + String inputLine; + String data = ""; + while ((inputLine = in.readLine()) != null) + data = inputLine; + in.close(); + data = data.substring(1, data.length() - 1); + if (data.isEmpty()) { + consumer.accept(null); + return; + } + JSONObject obj = new JSONObject(data); + String UpdateName = obj.getString("name"); + String tag_name = obj.getString("tag_name"); + String body = obj.getString("body").replace("\n", "
").replace("\r", "").replace("'", "''"); + String updateurl = obj.getString("html_url"); + boolean prerelease = obj.getBoolean("prerelease"); + + 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()) { + downloadURL = "https://www.spigotmc.org/resources/" + spigotID; + } else { + downloadURL = downloadArray.getJSONObject(0).getString("browser_download_url"); + } + + if (!prerelease) { + downloadURL = "https://www.spigotmc.org/resources/" + spigotID; + updateurl = "https://www.spigotmc.org/resources/" + spigotID; + } + + T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, formattedDate, downloadURL, prerelease); + consumer.accept(webData); + } catch (Exception var10) { + Boolean load = false; + if (T2CBupdateAPI.bungeePluginVersins.containsKey(plugin.getDescription().getName())) { + load = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).load; + } + T2CupdateObject update = new T2CupdateObject( + plugin.getDescription().getName(), + pluginVersion, + null, + load, + false + ); + T2CBupdateAPI.bungeePluginVersins.put(plugin.getDescription().getName(), update); + this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage()); + } + }); + } +} diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java index 430e1e9..7e92a48 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java @@ -50,12 +50,12 @@ public class T2CupdateAPI { return; } String st = "[prefix]
" + - "You can download it here: [link]'>[prefix] A new [value] version was" + - " found!
" + - "You can download it here: [link]'>[prefix] [plv] -> " + + "You can download it here: [link]'>[prefix] A new [value] version was" + + " found!
" + + "You can download it here: [link]'>[prefix] [plv] -> " + "[puv]
" + - "[dc]'>[prefix] You can find more information on Discord.
" + - "[prefix] Click for more information'>Update information
" + + "[dc]'>[prefix] You can find more information on Discord.
" + + "[prefix] Click for more information'>Update information
" + "[prefix]"; String value; @@ -94,10 +94,10 @@ public class T2CupdateAPI { } } else value = UpdateType.STABLE.text; String h = "
╔══════════════" + prefix + "══════════════"; - String s1 = "
A new [value] version was found!".replace("[value]", value); - String s2 = "
Your version: " + pluginVersion + " - Current version: " + webData.getVersion() + ""; - String s3 = "
You can download it here: " + webData.getUpdateUrl() + ""; - String s4 = "
You can find more information on Discord: " + discord + ""; + String s1 = "
A new [value] version was found!".replace("[value]", value); + String s2 = "
Your version: " + pluginVersion + " - Current version: " + webData.getVersion() + ""; + String s3 = "
You can download it here: " + webData.getUpdateUrl() + ""; + String s4 = "
You can find more information on Discord: " + discord + ""; String f = "
╚══════════════" + prefix + "══════════════"; String text = h + s1 + s2 + s3 + s4 + f; T2Csend.console(text); @@ -135,17 +135,18 @@ public class T2CupdateAPI { String updateUpdate = webData.getUpdateUrl(); String updateDescription = webData.getUpdateDescription(); - String pluginNameString = "
Plugin: " + pluginName + ""; - String pluginVersionString = "
Your version: " + pluginVersion + ""; - String updateInfoString = "
[value]:"; - String updateTitleString = "
Title: " + updateTitle + ""; - String updateVersionString = "
Version: " + updateVersion + ""; - String updateAtString = "
Published on: " + updateAt + ""; - String updateTypeString = "
Version type: " + updateType + ""; + String pluginNameString = "
Plugin: " + pluginName + ""; + String pluginVersionString = "
Your version: " + pluginVersion + ""; + String updateInfoString = "
[value]:"; + String updateTitleString = "
Title: " + updateTitle + ""; + String updateVersionString = "
Version: " + updateVersion + ""; + String updateAtString = "
Published on: " + updateAt + ""; + String updateTypeString = "
Version type: " + updateType + ""; String updateButton; if (player) { - updateButton = "
" + updateUpdate + "'>Download | Update Description"; + updateButton = "
" + updateUpdate + "'>Download | Update Description"; } else updateButton = "
Download: " + updateUpdate + ""; String text; @@ -158,8 +159,7 @@ public class T2CupdateAPI { 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; + text = text + updateButton; if (updateTitle.equals("OLD")) text = text + "
This plugin does not have the new update checker yet, so there is no exact update / " + "version information available!"; @@ -190,7 +190,7 @@ public class T2CupdateAPI { update.load = true; sendUpdateMsg(prefix, discord, update.webData, plugin); } - }.runTaskLaterAsynchronously(plugin, 600L); + }.runTaskLaterAsynchronously(plugin, 200L); } else sendUpdateMsg(prefix, discord, update.webData, plugin); } else { if (!update.load) { @@ -203,7 +203,8 @@ public class T2CupdateAPI { }.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L); } - public static void onUpdateCheck(Plugin plugin, String prefix, String RepoURL, Integer spigotID, String discord) { + public static void onUpdateCheck(Plugin plugin, String prefix, String gitKey, Integer spigotID, String discord) { + String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; if (!RepoURL.contains("?limit=1")) { RepoURL = RepoURL + "?limit=1"; } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java index a2fd6cb..0626f3f 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java @@ -45,7 +45,7 @@ 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").replace("\n","
").replace("\r","").replace("'","''"); + String body = obj.getString("body").replace("\n","
").replace("\r","").replace("'","''").replace("**",""); String updateurl = obj.getString("html_url"); boolean prerelease = obj.getBoolean("prerelease"); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java index 87e168c..e5506ae 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java @@ -29,6 +29,7 @@ public class Commands { try { CreateReportLog.create(sender); } catch (IOException e) { + T2Csend.sender(sender, Util.getPrefix() + " An error occurred while creating a report log! Please look in the console!"); throw new RuntimeException(e); } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java index aa44837..8d49b21 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java @@ -38,11 +38,15 @@ public class CreateReportLog { String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime()); File directory = new File(T2CodeLibMain.getPath() + "/DebugLogs"); + File directoryTemp = new File("T2CDebugLogsTemp"); if (!directory.exists()) { directory.mkdir(); } + if (!directoryTemp.exists()) { + directoryTemp.mkdir(); + } - File file = new File(T2CodeLibMain.getPath(), "/DebugLogs/T2CodeLog.txt"); + File file = new File("T2CDebugLogsTemp/T2CodeLog.txt"); PrintWriter pWriter = null; try { pWriter = new PrintWriter(new FileWriter(file.getPath())); @@ -117,9 +121,9 @@ public class CreateReportLog { } } - String filePath = T2CodeLibMain.getPath() + "/DebugLogs/T2CodeLog.txt"; + String filePath = "T2CDebugLogsTemp/T2CodeLog.txt"; String log = "logs/latest.log"; - String zipPath = "plugins/T2CodeLib/DebugLogs/T2CLog-" + timeStampFile + ".zip"; + String zipPath = "T2CDebugLogsTemp/T2CLog-" + timeStampFile + ".zip"; try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipPath))) { File fileToZip = new File(filePath); zip.putNextEntry(new ZipEntry(fileToZip.getName())); @@ -152,12 +156,13 @@ public class CreateReportLog { String fileType = obj.getString("fileType"); Integer fileSize = obj.getInt("size"); zipFile.delete(); + directoryTemp.delete(); if (sender instanceof Player) { T2Csend.sender(sender, Util.getPrefix() + ("A DebugLog zip has been created. You can download it " + "Download the debug file'>here. Please enter the following key " + "in the ticket: Copy to clipboard'>[key]" + "
Do not share the download URL with anyone!
" + - "You can delte yor Debug-File by clicking me.").replace("[key]", fileID).replace("[url]", downloadURL)); + "You can Click to delete'>delte yor Debug-File by clicking me.").replace("[key]", fileID).replace("[url]", downloadURL)); } T2Csend.console(Util.getPrefix() + (" §6A DebugLog zip has been created. You can download it here: [url].\n§6Please enter the following key in the ticket:" + " §e[key].\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog [key].") diff --git a/src/main/java/net/t2code/t2codelib/Util.java b/src/main/java/net/t2code/t2codelib/Util.java index 0470258..1a2ea72 100644 --- a/src/main/java/net/t2code/t2codelib/Util.java +++ b/src/main/java/net/t2code/t2codelib/Util.java @@ -18,7 +18,7 @@ public class Util { } public static String getGit() { - return "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1"; + return "JaTiTV/T2CodeLib"; } public static Integer getBstatsID() {