From 8034d8852aec2b17e1bfde20805fc027c4f76e79 Mon Sep 17 00:00:00 2001 From: Jkobs <66284145+Minzilein2003@users.noreply.github.com> Date: Thu, 10 Nov 2022 11:28:55 +0100 Subject: [PATCH 01/19] New Updater --- pom.xml | 13 ++++ .../SPIGOT/api/messages/T2Ctemplate.java | 2 +- .../SPIGOT/api/update/T2CupdateAPI.java | 31 ++++---- .../SPIGOT/api/update/T2CupdateChecker.java | 76 ++++++++++--------- .../SPIGOT/api/update/T2CupdateObject.java | 9 +-- .../SPIGOT/api/update/T2CupdateWebData.java | 31 ++++++++ .../SPIGOT/system/T2CodeLibMain.java | 2 +- 7 files changed, 106 insertions(+), 58 deletions(-) create mode 100644 src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java diff --git a/pom.xml b/pom.xml index b8a3786..a58e9d2 100644 --- a/pom.xml +++ b/pom.xml @@ -147,5 +147,18 @@ adventure-platform-bukkit 4.1.2 + + + org.projectlombok + lombok + 1.18.24 + provided + + + + org.json + json + 20220924 + diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java index 5f9084f..4aba421 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java @@ -82,7 +82,7 @@ public class T2Ctemplate { public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) { String pluginVersion = plugin.getDescription().getVersion(); - String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).publicVersion; + String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getTag_name(); boolean update = !publicVersion.equalsIgnoreCase(pluginVersion); boolean player = sender instanceof Player; 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 afb48d6..932405a 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 @@ -29,7 +29,7 @@ public class T2CupdateAPI { }.runTaskLaterAsynchronously(plugin, 20L); return; } - String publicVersion = pluginVersions.get(plugin.getName()).publicVersion; + String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name(); String pluginVersion = plugin.getDescription().getVersion(); if (pluginVersion.equals(publicVersion)) return; new BukkitRunnable() { @@ -41,7 +41,7 @@ public class T2CupdateAPI { } public static void sendUpdateMsg(String prefix, Integer spigotID, String discord, Plugin plugin, Player player) { - String publicVersion = pluginVersions.get(plugin.getName()).publicVersion; + String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name(); String pluginVersion = plugin.getDescription().getVersion(); if (publicVersion.equals("§4No public version found!")) { return; @@ -67,15 +67,16 @@ public class T2CupdateAPI { .replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord)); } - public static void sendUpdateMsg(String prefix, Integer spigot, String discord, Plugin plugin) { - String publicVersion = pluginVersions.get(plugin.getName()).publicVersion; + public static void sendUpdateMsg(String prefix, T2CupdateWebData data, String discord, Plugin plugin) { + String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name(); String pluginVersion = plugin.getDescription().getVersion(); String h = "§4=========== " + prefix + " §4==========="; String s1 = ""; String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion; - String s3 = "§6You can download it here: §ehttps://www.spigotmc.org/resources/" + spigot; + String s3 = "§6You can download it here: §e" + data.getUpdateurl(); String s4 = "§6You can find more information on Discord: §e" + discord; - if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) { + if (data.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"; } @@ -92,35 +93,39 @@ public class T2CupdateAPI { T2Csend.console(text); } - public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) { + public static void onUpdateCheck(Plugin plugin, String prefix, String discord, String RepoURL) { + if(!RepoURL.contains("?limit=1")){ + RepoURL = RepoURL + "?limit=1"; + } + String finalRepoURL = RepoURL; new BukkitRunnable() { @Override public void run() { - (new T2CupdateChecker((JavaPlugin) plugin, spigotID)).getVersion((update_version) -> { + (new T2CupdateChecker((JavaPlugin) plugin)).getVersion((webData) -> { T2CupdateObject update = new T2CupdateObject( plugin.getName(), plugin.getDescription().getVersion(), - update_version, + webData, false ); pluginVersions.put(plugin.getName(), update); - if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) { + if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTag_name())) { if (!update.load) { new BukkitRunnable() { @Override public void run() { update.load = true; - sendUpdateMsg(prefix, spigotID, discord, plugin); + sendUpdateMsg(prefix, webData, discord, plugin); } }.runTaskLaterAsynchronously(plugin, 600L); - } else sendUpdateMsg(prefix, spigotID, discord, plugin); + } else sendUpdateMsg(prefix, webData, discord, plugin); } else { if (!update.load){ T2Csend.console(prefix + " §2No update found."); update.load = true; } } - }, prefix, plugin.getDescription().getVersion()); + }, prefix, plugin.getDescription().getVersion(), finalRepoURL); } }.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L); } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java index 4cf9c7c..2b5376e 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java @@ -2,62 +2,63 @@ package net.t2code.t2codelib.SPIGOT.api.update; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URL; -import java.util.Scanner; +import java.net.URLConnection; import java.util.function.Consumer; public class T2CupdateChecker { private JavaPlugin plugin; - private int resourceId; - public T2CupdateChecker(JavaPlugin plugin, int resourceId) { + public T2CupdateChecker(JavaPlugin plugin) { this.plugin = plugin; - this.resourceId = resourceId; } - public void getVersion(Consumer consumer, String Prefix, String pluginVersion) { + public void getVersion(Consumer consumer, String Prefix, String pluginVersion, String URL) { if (!plugin.isEnabled()) { return; } Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { try { - InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream(); - try { - Scanner scanner = new Scanner(inputStream); - - try { - if (scanner.hasNext()) { - consumer.accept(scanner.next()); - } - } catch (Throwable var8) { - try { - scanner.close(); - } catch (Throwable var7) { - var8.addSuppressed(var7); - } - throw var8; - } - scanner.close(); - } catch (Throwable var9) { - if (inputStream != null) { - try { - inputStream.close(); - } catch (Throwable var6) { - var9.addSuppressed(var6); - } - } - throw var9; + 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; } - inputStream.close(); - } catch (IOException var10) { + 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"); + boolean prerelease = obj.getBoolean("prerelease"); + String published_at = obj.getString("published_at"); + JSONArray downloadArray = obj.getJSONArray("assets"); + String downloadURL; + if (downloadArray.isEmpty()) { + downloadURL = ""; + } else { + downloadURL = downloadArray.getJSONObject(0).getString("browser_download_url"); + } + T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, published_at, downloadURL, prerelease); + consumer.accept(webData); + } catch (Exception var10) { Boolean load = false; - if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())){ + if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())) { load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load; } - T2CupdateObject update = new T2CupdateObject( plugin.getName(), pluginVersion, @@ -69,4 +70,5 @@ public class T2CupdateChecker { } }); } + } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java index 529d7ca..3bf0780 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java @@ -5,19 +5,16 @@ public class T2CupdateObject { public String pluginName; public String pluginVersion; - public String publicVersion; - public String changeLog; + public T2CupdateWebData webData; public Boolean load; public T2CupdateObject(String pluginName, String pluginVersion, - String publicVersion , - String changeLog , + T2CupdateWebData webData , Boolean load) { this.pluginName = pluginName; this.pluginVersion = pluginVersion; - this.publicVersion = publicVersion; - this.changeLog = changeLog; + this.webData = webData; this.load=load; } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java new file mode 100644 index 0000000..f635232 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java @@ -0,0 +1,31 @@ +package net.t2code.t2codelib.SPIGOT.api.update; + +import lombok.Getter; + +public class T2CupdateWebData { + @Getter + private String UpdateName; + @Getter + private String tag_name; + @Getter + private String body; + @Getter + private String updateurl; + @Getter + private String published_at; + @Getter + private String downloadURL; + @Getter + private boolean prerelease; + + public T2CupdateWebData(String updateName, String tag_name, String body, String updateurl, String published_at, String downloadURL, boolean prerelease) { + UpdateName = updateName; + this.tag_name = tag_name; + this.body = body; + this.updateurl = updateurl; + this.published_at = published_at; + this.downloadURL = downloadURL; + this.prerelease = prerelease; + } +} + diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java index d5f9cf8..821daf3 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -90,7 +90,7 @@ public final class T2CodeLibMain extends JavaPlugin { SelectLibConfig.onSelect(); SelectLibMsg.onSelect(); - T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getSpigotID(), Util.getDiscord()); + T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getDiscord(), "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1"); Metrics.Bstats(plugin, Util.getBstatsID()); if (SelectLibConfig.getBungee()){ Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd"); From 3bdbaacd64dadbd654b109b85301c25d3b4d5923 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Thu, 10 Nov 2022 14:00:59 +0100 Subject: [PATCH 02/19] uc --- .../SPIGOT/api/messages/T2CminiMessage.java | 8 +- .../SPIGOT/api/messages/T2Ctemplate.java | 2 +- .../SPIGOT/api/update/T2CupdateAPI.java | 74 ++++++++++++----- .../SPIGOT/api/update/T2CupdateChecker.java | 76 +++++++++--------- .../api/update/T2CupdateCheckerGit.java | 80 +++++++++++++++++++ .../SPIGOT/api/update/T2CupdateObject.java | 4 +- .../SPIGOT/api/update/T2CupdateWebData.java | 22 ++--- .../SPIGOT/system/T2CodeLibMain.java | 8 +- src/main/java/net/t2code/t2codelib/Util.java | 3 + 9 files changed, 198 insertions(+), 79 deletions(-) create mode 100644 src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java index e654ca2..bd07d51 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java @@ -1,5 +1,6 @@ package net.t2code.t2codelib.SPIGOT.api.messages; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; @@ -8,17 +9,18 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class T2CminiMessage { + private static final BukkitAudiences bukkitAudiences = T2CodeLibMain.getPlugin().getAdventure(); public static void miniMessage(String msg, CommandSender sender) { - T2CodeLibMain.adventure().sender(sender).sendMessage(replace(msg)); + bukkitAudiences.sender(sender).sendMessage(replace(msg)); } public static void sendMiniMessage(String msg) { - T2CodeLibMain.adventure().console().sendMessage(replace(msg)); + bukkitAudiences.console().sendMessage(replace(msg)); } public static void miniMessage(String msg, Player player) { - T2CodeLibMain.adventure().player(player).sendMessage(replace(msg)); + bukkitAudiences.player(player).sendMessage(replace(msg)); } protected static Component replace(String text) { diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java index 4aba421..b61d131 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java @@ -82,7 +82,7 @@ public class T2Ctemplate { public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) { String pluginVersion = plugin.getDescription().getVersion(); - String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getTag_name(); + String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getTagName(); boolean update = !publicVersion.equalsIgnoreCase(pluginVersion); boolean player = sender instanceof Player; 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 932405a..12f8104 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 @@ -29,19 +29,19 @@ public class T2CupdateAPI { }.runTaskLaterAsynchronously(plugin, 20L); return; } - String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name(); + T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData; String pluginVersion = plugin.getDescription().getVersion(); - if (pluginVersion.equals(publicVersion)) return; + if (pluginVersion.equals(webData.getTagName())) return; new BukkitRunnable() { @Override public void run() { - sendUpdateMsg(prefix, spigotID, discord, plugin, player); + sendUpdateMsg(prefix, webData, discord, plugin, player); } }.runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), 200L); } - public static void sendUpdateMsg(String prefix, Integer spigotID, String discord, Plugin plugin, Player player) { - String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name(); + public static void sendUpdateMsg(String prefix, T2CupdateWebData webData, String discord, Plugin plugin, Player player) { + String publicVersion = webData.getTagName(); String pluginVersion = plugin.getDescription().getVersion(); if (publicVersion.equals("§4No public version found!")) { return; @@ -52,7 +52,9 @@ public class T2CupdateAPI { "[dc]'>[prefix] You can find more information on Discord.
" + "[prefix]"; String value = ""; - if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) { + + if (webData.isPreRelease()) { + value = "Pre-Release "; if (publicVersion.toLowerCase().contains("dev")) { value = "DEV "; } @@ -63,19 +65,19 @@ public class T2CupdateAPI { value = "SNAPSHOT "; } } - T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", "https://www.spigotmc.org/resources/" + spigotID) + 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, T2CupdateWebData data, String discord, Plugin plugin) { - String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name(); + public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin) { + String publicVersion =webData.getTagName(); String pluginVersion = plugin.getDescription().getVersion(); String h = "§4=========== " + prefix + " §4==========="; String s1 = ""; String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion; - String s3 = "§6You can download it here: §e" + data.getUpdateurl(); + String s3 = "§6You can download it here: §e" + webData.getUpdateUrl(); String s4 = "§6You can find more information on Discord: §e" + discord; - if (data.isPrerelease()) { + 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"; @@ -93,15 +95,49 @@ public class T2CupdateAPI { T2Csend.console(text); } - public static void onUpdateCheck(Plugin plugin, String prefix, String discord, String RepoURL) { - if(!RepoURL.contains("?limit=1")){ + public static void onUpdateCheck(Plugin plugin, String prefix, Integer spigotID, String discord) { + new BukkitRunnable() { + @Override + public void run() { + (new T2CupdateChecker((JavaPlugin) plugin, spigotID)).getVersion((update_version) -> { + T2CupdateObject update = new T2CupdateObject( + plugin.getName(), + plugin.getDescription().getVersion(), + new T2CupdateWebData("OLD", update_version, "", "https://www.spigotmc.org/resources/" + spigotID, "", + "https://www.spigotmc.org/resources/" + spigotID, false), + false + ); + pluginVersions.put(plugin.getName(), update); + if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) { + if (!update.load) { + new BukkitRunnable() { + @Override + public void run() { + update.load = true; + sendUpdateMsg(prefix, discord, update.webData, plugin); + } + }.runTaskLaterAsynchronously(plugin, 600L); + } else sendUpdateMsg(prefix, discord, update.webData, plugin); + } else { + if (!update.load) { + T2Csend.console(prefix + " §2No update found."); + update.load = true; + } + } + }, prefix, plugin.getDescription().getVersion()); + } + }.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L); + } + + public static void onUpdateCheck(Plugin plugin, String prefix, String RepoURL, Integer spigotID, String discord) { + if (!RepoURL.contains("?limit=1")) { RepoURL = RepoURL + "?limit=1"; } String finalRepoURL = RepoURL; new BukkitRunnable() { @Override public void run() { - (new T2CupdateChecker((JavaPlugin) plugin)).getVersion((webData) -> { + (new T2CupdateCheckerGit((JavaPlugin) plugin)).getVersion((webData) -> { T2CupdateObject update = new T2CupdateObject( plugin.getName(), plugin.getDescription().getVersion(), @@ -109,23 +145,23 @@ public class T2CupdateAPI { false ); pluginVersions.put(plugin.getName(), update); - if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTag_name())) { + if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTagName())) { if (!update.load) { new BukkitRunnable() { @Override public void run() { update.load = true; - sendUpdateMsg(prefix, webData, discord, plugin); + sendUpdateMsg(prefix, discord, webData, plugin); } }.runTaskLaterAsynchronously(plugin, 600L); - } else sendUpdateMsg(prefix, webData, discord, plugin); + } else sendUpdateMsg(prefix, discord, webData, plugin); } else { - if (!update.load){ + if (!update.load) { T2Csend.console(prefix + " §2No update found."); update.load = true; } } - }, prefix, plugin.getDescription().getVersion(), finalRepoURL); + }, plugin.getDescription().getVersion(), spigotID, finalRepoURL); } }.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L); } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java index 2b5376e..4cf9c7c 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java @@ -2,63 +2,62 @@ package net.t2code.t2codelib.SPIGOT.api.update; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; -import java.io.*; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; -import java.net.URLConnection; +import java.util.Scanner; import java.util.function.Consumer; public class T2CupdateChecker { private JavaPlugin plugin; + private int resourceId; - public T2CupdateChecker(JavaPlugin plugin) { + public T2CupdateChecker(JavaPlugin plugin, int resourceId) { this.plugin = plugin; + this.resourceId = resourceId; } - public void getVersion(Consumer consumer, String Prefix, String pluginVersion, String URL) { + public void getVersion(Consumer consumer, String Prefix, String pluginVersion) { if (!plugin.isEnabled()) { return; } Bukkit.getScheduler().runTaskAsynchronously(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; + InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream(); + try { + Scanner scanner = new Scanner(inputStream); + + try { + if (scanner.hasNext()) { + consumer.accept(scanner.next()); + } + } catch (Throwable var8) { + try { + scanner.close(); + } catch (Throwable var7) { + var8.addSuppressed(var7); + } + throw var8; + } + scanner.close(); + } catch (Throwable var9) { + if (inputStream != null) { + try { + inputStream.close(); + } catch (Throwable var6) { + var9.addSuppressed(var6); + } + } + throw var9; } - 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"); - boolean prerelease = obj.getBoolean("prerelease"); - String published_at = obj.getString("published_at"); - JSONArray downloadArray = obj.getJSONArray("assets"); - String downloadURL; - if (downloadArray.isEmpty()) { - downloadURL = ""; - } else { - downloadURL = downloadArray.getJSONObject(0).getString("browser_download_url"); - } - T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, published_at, downloadURL, prerelease); - consumer.accept(webData); - } catch (Exception var10) { + inputStream.close(); + } catch (IOException var10) { Boolean load = false; - if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())) { + if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())){ load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load; } + T2CupdateObject update = new T2CupdateObject( plugin.getName(), pluginVersion, @@ -70,5 +69,4 @@ public class T2CupdateChecker { } }); } - } 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 new file mode 100644 index 0000000..b8cdaa1 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java @@ -0,0 +1,80 @@ +package net.t2code.t2codelib.SPIGOT.api.update; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.*; +import java.net.URL; +import java.net.URLConnection; +import java.util.function.Consumer; + +public class T2CupdateCheckerGit { + private JavaPlugin plugin; + + public T2CupdateCheckerGit(JavaPlugin plugin) { + this.plugin = plugin; + } + + public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String URL) { + if (!plugin.isEnabled()) { + return; + } + Bukkit.getScheduler().runTaskAsynchronously(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"); + String updateurl = obj.getString("url"); + boolean prerelease = obj.getBoolean("prerelease"); + String published_at = obj.getString("published_at"); + 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, published_at, downloadURL, prerelease); + consumer.accept(webData); + } catch (Exception var10) { + Boolean load = false; + if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())) { + load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load; + } + T2CupdateObject update = new T2CupdateObject( + plugin.getName(), + pluginVersion, + null, + load + ); + T2CupdateAPI.pluginVersions.put(plugin.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/T2CupdateObject.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java index 3bf0780..1102d0c 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java @@ -10,11 +10,11 @@ public class T2CupdateObject { public T2CupdateObject(String pluginName, String pluginVersion, - T2CupdateWebData webData , + T2CupdateWebData webData, Boolean load) { this.pluginName = pluginName; this.pluginVersion = pluginVersion; this.webData = webData; - this.load=load; + this.load = load; } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java index f635232..b2afbf2 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java @@ -4,28 +4,28 @@ import lombok.Getter; public class T2CupdateWebData { @Getter - private String UpdateName; + private String updateName; @Getter - private String tag_name; + private String tagName; @Getter private String body; @Getter - private String updateurl; + private String updateUrl; @Getter - private String published_at; + private String publishedAt; @Getter private String downloadURL; @Getter - private boolean prerelease; + private boolean preRelease; - public T2CupdateWebData(String updateName, String tag_name, String body, String updateurl, String published_at, String downloadURL, boolean prerelease) { - UpdateName = updateName; - this.tag_name = tag_name; + 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; - this.updateurl = updateurl; - this.published_at = published_at; + this.updateUrl = updateUrl; + this.publishedAt = publishedAt; this.downloadURL = downloadURL; - this.prerelease = prerelease; + this.preRelease = preRelease; } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java index 821daf3..9ac0fcf 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -39,7 +39,7 @@ public final class T2CodeLibMain extends JavaPlugin { plugin = this; autor = plugin.getDescription().getAuthors(); version = plugin.getDescription().getVersion(); - this.adventure = BukkitAudiences.create(this); + adventure = BukkitAudiences.create(this); long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord()); String prefix = Util.getPrefix(); @@ -90,9 +90,9 @@ public final class T2CodeLibMain extends JavaPlugin { SelectLibConfig.onSelect(); SelectLibMsg.onSelect(); - T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getDiscord(), "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1"); + T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), Util.getSpigotID(), Util.getDiscord()); Metrics.Bstats(plugin, Util.getBstatsID()); - if (SelectLibConfig.getBungee()){ + if (SelectLibConfig.getBungee()) { Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd"); } @@ -155,7 +155,7 @@ public final class T2CodeLibMain extends JavaPlugin { private static BukkitAudiences adventure; - public static BukkitAudiences adventure() { + public BukkitAudiences getAdventure() { if (adventure == null) { throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); } diff --git a/src/main/java/net/t2code/t2codelib/Util.java b/src/main/java/net/t2code/t2codelib/Util.java index ea6ab55..88b48cf 100644 --- a/src/main/java/net/t2code/t2codelib/Util.java +++ b/src/main/java/net/t2code/t2codelib/Util.java @@ -16,6 +16,9 @@ public class Util { public static Integer getSpigotID() { return 96388; } + public static String getGit() { + return "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1"; + } public static Integer getBstatsID() { return 12518; From eb466f0df1ec9161cecd19d52ab3092c71c774c9 Mon Sep 17 00:00:00 2001 From: Jkobs <66284145+Minzilein2003@users.noreply.github.com> Date: Thu, 10 Nov 2022 18:27:55 +0100 Subject: [PATCH 03/19] Init --- pom.xml | 7 ++++ .../t2codelib/SPIGOT/system/CmdExecuter.java | 35 ++++++++++++---- .../SPIGOT/system/CreateReportLog.java | 42 ++++++++++++++++--- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index a58e9d2..7d61fa9 100644 --- a/pom.xml +++ b/pom.xml @@ -160,5 +160,12 @@ json 20220924 + + + org.apache.httpcomponents + httpmime + 4.3.1 + + diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java index 7904140..41809cb 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java @@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -24,7 +25,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { return false; } if (args.length == 0) { - T2Ctemplate.sendInfo(sender,T2CodeLibMain.getPlugin(), Util.getSpigotID(),Util.getDiscord(),null, Util.getInfoText()); + T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText()); return false; } switch (args[0].toLowerCase()) { @@ -33,20 +34,40 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { case "pl": case "version": case "ver": - T2Ctemplate.sendInfo(sender,T2CodeLibMain.getPlugin(), Util.getSpigotID(),Util.getDiscord(),null, Util.getInfoText()); + T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText()); return false; case "reloadconfig": SelectLibConfig.onSelect(); return false; case "debug": - if (args.length != 2) { + if (args.length < 2) { T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); return false; } - if ("createreportlog".equals(args[1].toLowerCase())) { - CreateReportLog.create(sender); - } else T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); - return false; + switch (args[1].toLowerCase()) { + case "createreportlog": + try { + CreateReportLog.create(sender); + } catch (IOException e) { + throw new RuntimeException(e); + } + break; + case "deleteReportLog": + if(args.length != 3){ + T2Csend.sender(sender, "§4Use: §7/t2code debug deleteReportLog [id]"); + return false; + } + try { + CreateReportLog.delete(args[2]); + } catch (IOException e) { + throw new RuntimeException(e); + } + break; + default: + T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog/deleteReportLog"); + break; + } + return false; default: T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java index a1a91da..46c0b15 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java @@ -5,13 +5,23 @@ import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck; import net.t2code.t2codelib.Util; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.mime.MultipartEntity; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; - +import org.json.JSONObject; import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -19,7 +29,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class CreateReportLog { - protected static void create(CommandSender sender) { + protected static void create(CommandSender sender) throws IOException { T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog is created..."); String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime()); @@ -113,10 +123,26 @@ public class CreateReportLog { e.printStackTrace(); } file.delete(); + HttpClient httpclient = new DefaultHttpClient(); + HttpPost httppost = new HttpPost("https://debug.t2code.net/uploadFile"); + File zipFile = new File(zipPath); + FileBody bin = new FileBody(zipFile); + MultipartEntity reqEntity = new MultipartEntity(); + reqEntity.addPart("file", bin); + httppost.setEntity(reqEntity); + HttpResponse response = httpclient.execute(httppost); + HttpEntity resEntity = response.getEntity(); + String responseString = EntityUtils.toString(resEntity, "UTF-8"); + JSONObject obj = new JSONObject(responseString); + String downloadURL = obj.getString("fileDownloadUri"); + String fileID = obj.getString("fileID"); + String fileType = obj.getString("fileType"); + Integer fileSize = obj.getInt("size"); + zipFile.delete(); if (sender instanceof Player) { - T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath); - T2Csend.console(Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath); - } else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath); + T2Csend.sender(sender, Util.getPrefix() + "A DebugLog zip has been created. You can download it here. Please enter the following key in the ticket: key
Do not share the download URL with anyone!
You can 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: §ekey.\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".replace("key",fileID).replace("url",downloadURL)); + } else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. You can download it here: url.\n§6Please enter the following key in the ticket: §ekey.\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".replace("key",fileID).replace("url",downloadURL)); } @@ -183,4 +209,10 @@ public class CreateReportLog { } } } + + public static void delete(String arg) throws IOException { + URL url = new URL("https://debug.t2code.net/delte/" + arg); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + } } From 855b0ee3cd88e098d30cee5629217f4ce6d36cf4 Mon Sep 17 00:00:00 2001 From: Jkobs <66284145+Minzilein2003@users.noreply.github.com> Date: Thu, 10 Nov 2022 19:03:56 +0100 Subject: [PATCH 04/19] Update CmdExecuter.java --- .../java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java index 41809cb..0e84900 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java @@ -99,6 +99,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { if (sender.hasPermission("t2code.admin")) { if (hasPermission(p, arg1.get("debug")) && passend("debug", args[1])) { list.add("createReportLog"); + list.add("deleteReportLog"); } } return list; From a15d667244b3836b1425613d9234161b5ee239b3 Mon Sep 17 00:00:00 2001 From: Jkobs <66284145+Minzilein2003@users.noreply.github.com> Date: Thu, 10 Nov 2022 19:13:54 +0100 Subject: [PATCH 05/19] Update CmdExecuter.java --- .../t2codelib/SPIGOT/system/CmdExecuter.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java index 29a9d22..9388b28 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java @@ -47,20 +47,19 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { } switch (args[1].toLowerCase()) { case "createreportlog": - Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { - @Override - public void run() { - try { - CreateReportLog.create(sender); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - }); - + Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { + @Override + public void run() { + try { + CreateReportLog.create(sender); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); break; case "deleteReportLog": - if(args.length != 3){ + if (args.length != 3) { T2Csend.sender(sender, "§4Use: §7/t2code debug deleteReportLog [id]"); return false; } @@ -74,7 +73,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog/deleteReportLog"); break; } - return false; + return false; default: T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); From 8147a5a2b475183cb5a42f20ebf360591083a69d Mon Sep 17 00:00:00 2001 From: Jkobs <66284145+Minzilein2003@users.noreply.github.com> Date: Thu, 10 Nov 2022 19:29:44 +0100 Subject: [PATCH 06/19] Update CreateReportLog.java --- .../net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java index 46c0b15..c80f31e 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java @@ -141,7 +141,7 @@ public class CreateReportLog { zipFile.delete(); if (sender instanceof Player) { T2Csend.sender(sender, Util.getPrefix() + "A DebugLog zip has been created. You can download it here. Please enter the following key in the ticket: key
Do not share the download URL with anyone!
You can 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: §ekey.\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".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: §ekey.\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".replace("key",fileID).replace("url",downloadURL)); } else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. You can download it here: url.\n§6Please enter the following key in the ticket: §ekey.\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".replace("key",fileID).replace("url",downloadURL)); } From 55d7a4496c63ec70c253d7246a6b993b52b80557 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Thu, 10 Nov 2022 21:37:15 +0100 Subject: [PATCH 07/19] Update Util.java --- src/main/java/net/t2code/t2codelib/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/t2code/t2codelib/Util.java b/src/main/java/net/t2code/t2codelib/Util.java index 998dae2..cb018f4 100644 --- a/src/main/java/net/t2code/t2codelib/Util.java +++ b/src/main/java/net/t2code/t2codelib/Util.java @@ -38,7 +38,7 @@ public class Util { "T2C-LuckyBox", "WonderBagShop", "CommandGUI", - "T2C-OPSecurity", + // "T2C-OPSecurity", "OPSecurity", "PaPiTest", "T2C-Alias", From a2e8a672fa476a189ffa2fc1418ef14be85271e5 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Sun, 13 Nov 2022 15:43:49 +0100 Subject: [PATCH 08/19] Update CreateReportLog.java --- .../net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java index c80f31e..ca835c5 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java @@ -141,8 +141,8 @@ public class CreateReportLog { zipFile.delete(); if (sender instanceof Player) { T2Csend.sender(sender, Util.getPrefix() + "A DebugLog zip has been created. You can download it here. Please enter the following key in the ticket: key
Do not share the download URL with anyone!
You can 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: §ekey.\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".replace("key",fileID).replace("url",downloadURL)); - } else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. You can download it here: url.\n§6Please enter the following key in the ticket: §ekey.\n§4Do not share the download URL with anyone!\nYou can delte yor Debug-File with the following command: /t2code debug deleteReportLog key.".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.".replace("[key]",fileID).replace("url",downloadURL)); + } else T2Csend.sender(sender, 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.".replace("[key]",fileID).replace("url",downloadURL)); } From 564288c9abef2c1bf5270746152da8045446ab65 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Sun, 13 Nov 2022 17:50:23 +0100 Subject: [PATCH 09/19] fix minimessage --- pom.xml | 17 +++++++++++++++-- .../SPIGOT/api/messages/T2CminiMessage.java | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1ff47b6..2632a00 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 13.3 + 13.4_DEV-1 jar T2CodeLib @@ -17,6 +17,7 @@ + ${project.artifactId}_${project.version} org.apache.maven.plugins @@ -39,6 +40,12 @@ false + + + net.kyori.adventure + net.t2code.t2codelib.shaded.adventure + + @@ -109,11 +116,13 @@ net.t2code bungee 1642 + provided net.t2code LuckyBox-API 4.2.7 + provided @@ -141,11 +150,13 @@ net.kyori adventure-text-minimessage 4.11.0 + compile net.kyori adventure-platform-bukkit 4.1.2 + compile @@ -159,13 +170,15 @@ org.json json 20220924 + provided org.apache.httpcomponents httpmime 4.3.1 + provided - + diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java index bd07d51..b54dc38 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java @@ -4,7 +4,6 @@ import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; From a0e590a2c1c908c0d725866cb0c2698eb8c04577 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 01:06:44 +0100 Subject: [PATCH 10/19] dev 2 --- pom.xml | 8 +- .../SPIGOT/api/messages/T2Ctemplate.java | 26 ++-- .../SPIGOT/api/update/T2CupdateAPI.java | 139 ++++++++++++++---- .../SPIGOT/api/update/T2CupdateChecker.java | 3 +- .../api/update/T2CupdateCheckerGit.java | 19 ++- .../SPIGOT/api/update/T2CupdateObject.java | 5 +- .../SPIGOT/api/update/T2CupdateWebData.java | 14 +- .../SPIGOT/system/T2CodeLibMain.java | 4 + .../t2codelib/SPIGOT/system/UpdateType.java | 15 ++ .../SPIGOT/system/{ => cmd}/CmdExecuter.java | 80 +++++----- .../t2codelib/SPIGOT/system/cmd/Commands.java | 60 ++++++++ .../system/{ => cmd}/CreateReportLog.java | 8 +- .../SPIGOT/system/cmd/ReportLogStorage.java | 43 ++++++ src/main/java/net/t2code/t2codelib/Util.java | 3 +- 14 files changed, 319 insertions(+), 108 deletions(-) create mode 100644 src/main/java/net/t2code/t2codelib/SPIGOT/system/UpdateType.java rename src/main/java/net/t2code/t2codelib/SPIGOT/system/{ => cmd}/CmdExecuter.java (59%) create mode 100644 src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java rename src/main/java/net/t2code/t2codelib/SPIGOT/system/{ => cmd}/CreateReportLog.java (94%) create mode 100644 src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java diff --git a/pom.xml b/pom.xml index 2632a00..bb4e351 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 13.4_DEV-1 + 13.4_DEV-2 jar T2CodeLib @@ -170,14 +170,14 @@ org.json json 20220924 - provided + compile org.apache.httpcomponents httpmime - 4.3.1 - provided + 4.5.13 + compile diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java index b61d131..d3d9cf0 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java @@ -82,26 +82,26 @@ public class T2Ctemplate { public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) { String pluginVersion = plugin.getDescription().getVersion(); - String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getTagName(); + String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getVersion(); boolean update = !publicVersion.equalsIgnoreCase(pluginVersion); boolean player = sender instanceof Player; - String stPlugin = "| Plugin: [pl]".replace("[pl]", plugin.getName()); - String stVersion = "| Version: [ver]".replace("[ver]", pluginVersion); - String stAutor = "| Autor(s): [autor]".replace("[autor]", plugin.getDescription().getAuthors().toString()); - String stNVersion = "| Newest Version: [nver]".replace("[nver]", publicVersion); - String stStable = "| Stable version available: [up]".replace("[up]", update ? "YES" : "no"); - String stLinkPlayer = "| Go to the Spigot page'>Spigot " + String stPlugin = " Plugin: [pl]".replace("[pl]", plugin.getName()); + String stVersion = " Version: [ver]".replace("[ver]", pluginVersion); + String stAutor = " Autor(s): [autor]".replace("[autor]", plugin.getDescription().getAuthors().toString()); + String stNVersion = " Newest Version: [nver]".replace("[nver]", publicVersion); + String stStable = " Stable version available: [up]".replace("[up]", update ? "YES" : "no"); + String stLinkPlayer = " Go to the Spigot page'>Spigot " .replace("[slink]", "https://www.spigotmc.org/resources/" + spigotID) + "- Go to the T2Code Support Discord'>Discord" .replace("[dlink]", discord); - String stLinkConsole = "| Spigot: https://www.spigotmc.org/resources/" + spigotID + "" - + "
| Discord: " + discord + ""; + String stLinkConsole = " Spigot: https://www.spigotmc.org/resources/" + spigotID + "" + + "
Discord: " + discord + ""; String stLink = player ? stLinkPlayer : stLinkConsole; - String pr = premiumVerified != null ? "
| Premium verified: [pr]".replace("[pr]", premiumVerified ? "YES" : "NO") : ""; + String pr = premiumVerified != null ? "
Premium verified: [pr]".replace("[pr]", premiumVerified ? "YES" : "NO") : ""; - String stMSG = text == null || text.equals("") ? "" : "
| " + text + "
"; - T2Csend.sender(sender, "---------------------" + String stMSG = text == null || text.equals("") ? "" : "
" + text + "
"; + T2Csend.sender(sender, "╔══════════════════════════════════════" + "
" + stPlugin + stMSG + stVersion @@ -110,7 +110,7 @@ public class T2Ctemplate { + "
" + stStable + "
" + stLink + pr - + "
---------------------"); + + "
╚══════════════════════════════════════"); } public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, String text) { 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 12f8104..b3690ec 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 @@ -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]
" + - "You can download it here: [link]'>[prefix] A new [value]version was found!
" + - "You can download it here: [link]'>[prefix] [plv] -> [puv]
" + + "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
" + "[prefix]"; - String value = ""; + + String value; if (webData.isPreRelease()) { - value = "Pre-Release "; + value = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { - value = "DEV "; + value = UpdateType.DEVELOPMENT.text; } if (publicVersion.toLowerCase().contains("beta")) { - value = "BETA "; + value = UpdateType.BETA.text; } if (publicVersion.toLowerCase().contains("snapshot")) { - value = "SNAPSHOT "; + 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 = "
" + h + "
" + s1 + "
" + s2 + "
" + s3 + "
" + s4 + "
" + 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 = "
Plugin: " + pluginName + ""; + String pluginVersionString = "
Your version: " + pluginVersion + ""; + String updateInfoString = "
[value]:"; + String updateTitleString = "
Title: " + updateTitle + ""; + String updateVersionString = "
Version: " + updateVersion + ""; + String updateAtString = "
Update at: " + updateAt + ""; + String updateTypeString = "
Update type: " + updateType + ""; + + String updateButton; + if (player) { + // updateButton = "
" + updateUpdate + "'>Download"; + updateButton = "
" + updateUpdate + "'>Download | Update Description"; + } else updateButton = "
Download: " + updateUpdate + ""; + + String text; + + text = "╔══════════════════════"; + 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 + "
This plugin does not have the new update checker yet, so there is no exact update / " + + "version information available!"; + + text = text + "
╚══════════════════════"; + + 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 diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java index 4cf9c7c..da33cc7 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java @@ -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()); 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 b8cdaa1..60f0dfd 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 @@ -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","
").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()); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java index 1102d0c..e0e5238 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java @@ -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; } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java index b2afbf2..cd72606 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java @@ -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; diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java index 9ac0fcf..95b6be7 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -10,6 +10,8 @@ import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; import net.t2code.t2codelib.SPIGOT.system.bstats.Metrics; +import net.t2code.t2codelib.SPIGOT.system.cmd.CmdExecuter; +import net.t2code.t2codelib.SPIGOT.system.cmd.ReportLogStorage; import net.t2code.t2codelib.SPIGOT.system.config.config.ConfigCreate; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate; @@ -96,6 +98,7 @@ public final class T2CodeLibMain extends JavaPlugin { Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd"); } + ReportLogStorage.load(); Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin); T2Ctemplate.onLoadFooter(prefix, long_); load = true; @@ -105,6 +108,7 @@ public final class T2CodeLibMain extends JavaPlugin { public void onDisable() { // Plugin shutdown logic if (!load) return; + ReportLogStorage.save(); if (SelectLibConfig.getInventoriesCloseByServerStop()) { for (Player player : Bukkit.getOnlinePlayers()) { player.closeInventory(); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/UpdateType.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/UpdateType.java new file mode 100644 index 0000000..27e4f96 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/UpdateType.java @@ -0,0 +1,15 @@ +package net.t2code.t2codelib.SPIGOT.system; + +public enum UpdateType { + PRERELEASE("Pre-Release"), + DEVELOPMENT("DEV"), + BETA("BETA"), + SNAPSHOT("SNAPSHOT"), + STABLE("STABLE"); + + public String text; + + UpdateType(String text) { + this.text = text; + } +} diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java similarity index 59% rename from src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java rename to src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java index 9388b28..3bde5e5 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java @@ -1,21 +1,19 @@ -package net.t2code.t2codelib.SPIGOT.system; +package net.t2code.t2codelib.SPIGOT.system.cmd; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; -import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate; -import net.t2code.t2codelib.SPIGOT.system.CreateReportLog; +import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; +import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateObject; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; -import net.t2code.t2codelib.Util; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; public class CmdExecuter implements CommandExecutor, TabCompleter { @@ -26,7 +24,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { return false; } if (args.length == 0) { - T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText()); + Commands.info(sender); return false; } switch (args[0].toLowerCase()) { @@ -35,44 +33,16 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { case "pl": case "version": case "ver": - T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText()); + Commands.info(sender); + return false; + case "updateinfo": + Commands.updateInfo(sender,args); return false; case "reloadconfig": SelectLibConfig.onSelect(); return false; case "debug": - if (args.length < 2) { - T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); - return false; - } - switch (args[1].toLowerCase()) { - case "createreportlog": - Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { - @Override - public void run() { - try { - CreateReportLog.create(sender); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - }); - break; - case "deleteReportLog": - if (args.length != 3) { - T2Csend.sender(sender, "§4Use: §7/t2code debug deleteReportLog [id]"); - return false; - } - try { - CreateReportLog.delete(args[2]); - } catch (IOException e) { - throw new RuntimeException(e); - } - break; - default: - T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog/deleteReportLog"); - break; - } + Commands.debug(sender,args); return false; default: @@ -86,6 +56,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { put("debug", "t2code.admin"); put("info", "t2code.admin"); put("reloadconfig", "t2code.admin"); + put("updateinfo", "t2code.admin"); }}; @Override @@ -103,9 +74,32 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { if (args.length == 2 && args[0].equalsIgnoreCase("debug")) { if (sender.hasPermission("t2code.admin")) { - if (hasPermission(p, arg1.get("debug")) && passend("debug", args[1])) { - list.add("createReportLog"); - list.add("deleteReportLog"); + if (hasPermission(p, arg1.get("debug"))) { + if (passend("createReportLog",args[1])) list.add("createReportLog"); + if (passend("deleteReportLog",args[1])) list.add("deleteReportLog"); + } + } + return list; + } + if (args.length == 2 && args[0].equalsIgnoreCase("updateinfo")) { + if (sender.hasPermission("t2code.admin")) { + if (hasPermission(p, arg1.get("updateinfo"))) { + for (Map.Entry pl : T2CupdateAPI.pluginVersions.entrySet()){ + if (passend(pl.getValue().pluginName,args[1])) list.add(pl.getValue().pluginName); + } + } + } + return list; + } + + + if (args.length == 3 && args[0].equalsIgnoreCase("debug")&& args[1].equalsIgnoreCase("deleteReportLog")) { + if (sender.hasPermission("t2code.admin")) { + if (hasPermission(p, arg1.get("debug"))) { + for (String st : ReportLogStorage.list){ + String[] string = st.split(" - "); + if (passend(st,args[2])) list.add(string[0]); + } } } return list; 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 new file mode 100644 index 0000000..b9bda7d --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java @@ -0,0 +1,60 @@ +package net.t2code.t2codelib.SPIGOT.system.cmd; + +import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; +import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate; +import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; +import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateObject; +import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateWebData; +import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; +import net.t2code.t2codelib.SPIGOT.system.UpdateType; +import net.t2code.t2codelib.Util; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.IOException; + +public class Commands { + public static void info(CommandSender sender) { + T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText()); + } + + public static void debug(CommandSender sender, String[] args) { + if (args.length < 2) { + T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); + return; + } + switch (args[1].toLowerCase()) { + case "createreportlog": + Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { + @Override + public void run() { + try { + CreateReportLog.create(sender); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + break; + case "deletereportlog": + if (args.length != 3) { + T2Csend.sender(sender, "§4Use: §7/t2code debug deleteReportLog [id]"); + return; + } + try { + CreateReportLog.delete(args[2]); + } catch (IOException e) { + throw new RuntimeException(e); + } + break; + default: + T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog/deleteReportLog"); + break; + } + } + + public static void updateInfo(CommandSender sender, String[] args) { + T2Csend.sender(sender, T2CupdateAPI.updateInfo(sender, args, sender instanceof Player)); + } +} diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java similarity index 94% rename from src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java rename to src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java index 95d0c60..7cc9a67 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CreateReportLog.java @@ -1,9 +1,11 @@ -package net.t2code.t2codelib.SPIGOT.system; +package net.t2code.t2codelib.SPIGOT.system.cmd; import net.t2code.luckyBox.api.LuckyBoxAPI; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck; +import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; +import net.t2code.t2codelib.SPIGOT.system.Vault; import net.t2code.t2codelib.Util; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -146,11 +148,14 @@ public class CreateReportLog { String fileType = obj.getString("fileType"); Integer fileSize = obj.getInt("size"); zipFile.delete(); + directory.delete(); if (sender instanceof Player) { T2Csend.sender(sender, Util.getPrefix() + "A DebugLog zip has been created. You can download it here. Please enter the following key in the ticket: key
Do not share the download URL with anyone!
You can delte yor Debug-File by clicking me.".replace("key",fileID).replace("url",downloadURL)); + System.out.println(Util.getPrefix() + "A DebugLog zip has been created. You can download it here. Please enter the following key in the ticket: key
Do not share the download URL with anyone!
You can 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.".replace("[key]",fileID).replace("url",downloadURL)); } else T2Csend.sender(sender, 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.".replace("[key]",fileID).replace("url",downloadURL)); + ReportLogStorage.add(fileID +" - "+downloadURL); } private static void pluginToDebug(String pluginName, ZipOutputStream zip) throws IOException { @@ -221,5 +226,6 @@ public class CreateReportLog { URL url = new URL("https://debug.t2code.net/delte/" + arg); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); + ReportLogStorage.remove(arg); } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java new file mode 100644 index 0000000..b626ef3 --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java @@ -0,0 +1,43 @@ +package net.t2code.t2codelib.SPIGOT.system.cmd; + +import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.security.PublicKey; +import java.util.ArrayList; +import java.util.List; + +public class ReportLogStorage { + public static List list = new ArrayList<>(); + + protected static File config = new File("T2CodeReportKeys.yml"); + protected static YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); + + public static void add(String key){ + list.add(key); + save(); + } + + public static void remove(String key){ + list.remove(key); + save(); + } + + public static void save(){ + if (list.isEmpty()) return; + yamlConfiguration.set("Keys",list); + + try { + yamlConfiguration.save(config); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void load(){ + if (!config.exists()) return; + list = yamlConfiguration.getStringList("Keys"); + } +} diff --git a/src/main/java/net/t2code/t2codelib/Util.java b/src/main/java/net/t2code/t2codelib/Util.java index cb018f4..661e1a9 100644 --- a/src/main/java/net/t2code/t2codelib/Util.java +++ b/src/main/java/net/t2code/t2codelib/Util.java @@ -16,6 +16,7 @@ public class Util { public static Integer getSpigotID() { return 96388; } + public static String getGit() { return "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1"; } @@ -38,7 +39,7 @@ public class Util { "T2C-LuckyBox", "WonderBagShop", "CommandGUI", - // "T2C-OPSecurity", + // "T2C-OPSecurity", "OPSecurity", "PaPiTest", "T2C-Alias", From f1065ad5a15ec7afb3a2162670e6ef43cb2b92b5 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 01:42:43 +0100 Subject: [PATCH 11/19] small bugfix --- pom.xml | 2 +- .../t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java | 2 +- .../t2codelib/SPIGOT/system/cmd/CreateReportLog.java | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index bb4e351..a8998f8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 13.4_DEV-2 + 13.4_DEV-3 jar T2CodeLib 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 b3690ec..b0a1787 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 @@ -94,7 +94,7 @@ public class T2CupdateAPI { } else value = UpdateType.STABLE.text; String h = "§4=========== " + prefix + " §4==========="; String s1 = "§6A new [value] version was found!§r".replace("[value]", value); - String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion; + String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + webData.getVersion(); String s3 = "§6You can download it here: §e" + webData.getUpdateUrl(); String s4 = "§6You can find more information on Discord: §e" + discord; String text = "
" + h + "
" + s1 + "
" + s2 + "
" + s3 + "
" + s4 + "
" + h; 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 7cc9a67..cca7e31 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 @@ -101,8 +101,9 @@ public class CreateReportLog { pWriter.println("Plugins amount: " + Bukkit.getPluginManager().getPlugins().length); pWriter.println("Plugins: "); for (Plugin pl : Bukkit.getPluginManager().getPlugins()) { - pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + pl.getDescription() - .getAuthors() + " - Website: " + pl.getDescription().getWebsite()); + pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + + pl.getDescription().getAuthors()+" - SoftDepend: " + pl.getDescription().getSoftDepend() + " - Depend: " + pl.getDescription().getDepend() + + " LoadBefore: " + pl.getDescription().getLoadBefore() + " - Website: " + pl.getDescription().getWebsite()); } } catch (IOException ioe) { ioe.printStackTrace(); @@ -150,8 +151,7 @@ public class CreateReportLog { zipFile.delete(); directory.delete(); if (sender instanceof Player) { - T2Csend.sender(sender, Util.getPrefix() + "A DebugLog zip has been created. You can download it here. Please enter the following key in the ticket: key
Do not share the download URL with anyone!
You can delte yor Debug-File by clicking me.".replace("key",fileID).replace("url",downloadURL)); - System.out.println(Util.getPrefix() + "A DebugLog zip has been created. You can download it here. Please enter the following key in the ticket: key
Do not share the download URL with anyone!
You can delte yor Debug-File by clicking me.".replace("key",fileID).replace("url",downloadURL)); + 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)); 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.".replace("[key]",fileID).replace("url",downloadURL)); } else T2Csend.sender(sender, 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.".replace("[key]",fileID).replace("url",downloadURL)); From 9d233ba5a62bccd1b55c73be0b201c1168124fb3 Mon Sep 17 00:00:00 2001 From: Jkobs <66284145+Minzilein2003@users.noreply.github.com> Date: Mon, 14 Nov 2022 10:04:53 +0100 Subject: [PATCH 12/19] Fixes and Changes --- .../t2codelib/SPIGOT/system/cmd/CmdExecuter.java | 3 +-- .../t2codelib/SPIGOT/system/cmd/Commands.java | 2 +- .../SPIGOT/system/cmd/CreateReportLog.java | 15 +++++++++++---- .../SPIGOT/system/cmd/ReportLogStorage.java | 6 ++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java index 3bde5e5..da6cbc1 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java @@ -97,8 +97,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter { if (sender.hasPermission("t2code.admin")) { if (hasPermission(p, arg1.get("debug"))) { for (String st : ReportLogStorage.list){ - String[] string = st.split(" - "); - if (passend(st,args[2])) list.add(string[0]); + if (passend(st,args[2])) list.add(st); } } } 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 b9bda7d..9c1bd36 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 @@ -43,7 +43,7 @@ public class Commands { return; } try { - CreateReportLog.delete(args[2]); + CreateReportLog.delete(args[2], sender); } catch (IOException e) { 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 cca7e31..0410c69 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 @@ -155,7 +155,7 @@ public class CreateReportLog { 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.".replace("[key]",fileID).replace("url",downloadURL)); } else T2Csend.sender(sender, 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.".replace("[key]",fileID).replace("url",downloadURL)); - ReportLogStorage.add(fileID +" - "+downloadURL); + ReportLogStorage.add(fileID); } private static void pluginToDebug(String pluginName, ZipOutputStream zip) throws IOException { @@ -222,10 +222,17 @@ public class CreateReportLog { } } - public static void delete(String arg) throws IOException { - URL url = new URL("https://debug.t2code.net/delte/" + arg); + public static void delete(String arg, CommandSender sender) throws IOException { + URL url = new URL("https://debug.t2code.net/delete/" + arg); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); - ReportLogStorage.remove(arg); + int response = con.getResponseCode(); + if(response == 200){ + ReportLogStorage.remove(arg); + T2Csend.sender(sender,"Deleted report: " + arg); + }else { + T2Csend.sender(sender,"Error while deleting report: " + arg); + } + con.disconnect(); } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java index b626ef3..f99d53d 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java @@ -2,17 +2,15 @@ package net.t2code.t2codelib.SPIGOT.system.cmd; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; import org.bukkit.configuration.file.YamlConfiguration; - import java.io.File; import java.io.IOException; -import java.security.PublicKey; import java.util.ArrayList; import java.util.List; public class ReportLogStorage { public static List list = new ArrayList<>(); - protected static File config = new File("T2CodeReportKeys.yml"); + protected static File config = new File(T2CodeLibMain.getPath(),"T2CodeReportKeys.yml"); protected static YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); public static void add(String key){ @@ -26,7 +24,7 @@ public class ReportLogStorage { } public static void save(){ - if (list.isEmpty()) return; + if (list == null) return; yamlConfiguration.set("Keys",list); try { From 5857e0269500e9e9a71b3faedec12de18fa777b4 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 14:16:46 +0100 Subject: [PATCH 13/19] small fix --- .../SPIGOT/system/cmd/CreateReportLog.java | 14 +++++++++----- .../SPIGOT/system/cmd/ReportLogStorage.java | 13 +++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) 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 0410c69..127a13b 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 @@ -149,12 +149,16 @@ public class CreateReportLog { String fileType = obj.getString("fileType"); Integer fileSize = obj.getInt("size"); zipFile.delete(); - directory.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)); - 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.".replace("[key]",fileID).replace("url",downloadURL)); - } else T2Csend.sender(sender, 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.".replace("[key]",fileID).replace("url",downloadURL)); - + 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)); + } + 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].") + .replace("[key]",fileID).replace("[url]",downloadURL)); ReportLogStorage.add(fileID); } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java index f99d53d..55df04a 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java @@ -2,6 +2,7 @@ package net.t2code.t2codelib.SPIGOT.system.cmd; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; import org.bukkit.configuration.file.YamlConfiguration; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -10,22 +11,22 @@ import java.util.List; public class ReportLogStorage { public static List list = new ArrayList<>(); - protected static File config = new File(T2CodeLibMain.getPath(),"T2CodeReportKeys.yml"); + protected static File config = new File(T2CodeLibMain.getPath(), "/DebugLogs/T2CodeReportKeys.yml"); protected static YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); - public static void add(String key){ + public static void add(String key) { list.add(key); save(); } - public static void remove(String key){ + public static void remove(String key) { list.remove(key); save(); } - public static void save(){ + public static void save() { if (list == null) return; - yamlConfiguration.set("Keys",list); + yamlConfiguration.set("Keys", list); try { yamlConfiguration.save(config); @@ -34,7 +35,7 @@ public class ReportLogStorage { } } - public static void load(){ + public static void load() { if (!config.exists()) return; list = yamlConfiguration.getStringList("Keys"); } From f70767b361fa2c34265f0a44bac57c0ab2573a8a Mon Sep 17 00:00:00 2001 From: Jkobs <66284145+Minzilein2003@users.noreply.github.com> Date: Mon, 14 Nov 2022 14:41:45 +0100 Subject: [PATCH 14/19] New Bungee Updater --- .../BUNGEE/api/messages/T2CBtemplate.java | 2 +- .../BUNGEE/api/update/T2CBupdateAPI.java | 133 +++++++++++------- .../BUNGEE/api/update/T2CBupdateObject.java | 12 -- .../t2codelib/BUNGEE/system/T2CBload.java | 4 +- .../t2codelib/BUNGEE/system/T2CodeBMain.java | 2 +- .../SPIGOT/api/update/T2CupdateAPI.java | 2 + .../SPIGOT/api/update/T2CupdateChecker.java | 1 + .../api/update/T2CupdateCheckerGit.java | 2 + .../SPIGOT/system/cmd/CmdExecuter.java | 2 +- .../t2codelib/SPIGOT/system/cmd/Commands.java | 3 - .../api/update => }/T2CupdateObject.java | 2 +- .../api/update => }/T2CupdateWebData.java | 2 +- 12 files changed, 94 insertions(+), 73 deletions(-) delete mode 100644 src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateObject.java rename src/main/java/net/t2code/t2codelib/{SPIGOT/api/update => }/T2CupdateObject.java (92%) rename src/main/java/net/t2code/t2codelib/{SPIGOT/api/update => }/T2CupdateWebData.java (94%) diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java index a599df1..cc47a10 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java @@ -39,7 +39,7 @@ public class T2CBtemplate { } public static void sendInfo(CommandSender sender, Plugin plugin, String prefix, String spigot, String discord, String autor) { - String publicVersion = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).publicVersion; + String publicVersion = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).webData.getVersion(); String pluginVersion = plugin.getDescription().getVersion(); T2CBsend.sender(sender, prefix + "§4======= " + prefix + " §4======="); T2CBsend.sender(sender, prefix + " §2Autor: §6" + autor); 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 fccb1d8..9088a95 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 @@ -1,20 +1,26 @@ package net.t2code.t2codelib.BUNGEE.api.update; +import net.md_5.bungee.BungeeCord; 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 java.io.IOException; -import java.io.InputStream; +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.HashMap; -import java.util.Scanner; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; public class T2CBupdateAPI { - public static HashMap bungeePluginVersins = new HashMap(); + public static HashMap bungeePluginVersins = new HashMap<>(); public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version) { T2CBsend.console("§4=========== " + Prefix + " §4==========="); @@ -24,29 +30,34 @@ public class T2CBupdateAPI { T2CBsend.console("§6You can find more information on Discord: §e" + Discord); T2CBsend.console("§4=========== " + Prefix + " §4==========="); } + public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version, CommandSender sender) { - T2CBsend.sender(sender,"§4=========== " + Prefix + " §4==========="); - T2CBsend.sender(sender,"§6A new version was found!"); - T2CBsend.sender(sender,"§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version); - T2CBsend.sender(sender,"§6You can download it here: §e" + Spigot); - T2CBsend.sender(sender,"§6You can find more information on Discord: §e" + Discord); - T2CBsend.sender(sender,"§4=========== " + Prefix + " §4==========="); + T2CBsend.sender(sender, "§4=========== " + Prefix + " §4==========="); + T2CBsend.sender(sender, "§6A new version was found!"); + T2CBsend.sender(sender, "§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version); + T2CBsend.sender(sender, "§6You can download it here: §e" + Spigot); + T2CBsend.sender(sender, "§6You can find more information on Discord: §e" + Discord); + T2CBsend.sender(sender, "§4=========== " + Prefix + " §4==========="); } + private static Boolean noUpdate = true; private static String pluginVersion; - public static void onUpdateCheckTimer(Plugin plugin, String Prefix, String Spigot, String Discord, Integer SpigotID) { + + public static void onUpdateCheckTimer(Plugin plugin, String Prefix, String Spigot, String Discord, Integer SpigotID, String url) { ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() { public void run() { (new T2CBupdateAPI(plugin, SpigotID)).getVersion((update_version) -> { pluginVersion = plugin.getDescription().getVersion(); - T2CBupdateObject update = new T2CBupdateObject( + T2CupdateObject update = new T2CupdateObject( plugin.getDescription().getName(), - pluginVersion, - update_version + plugin.getDescription().getVersion(), + update_version, + false, + !plugin.getDescription().getVersion().equals(update_version.getVersion()) ); bungeePluginVersins.put(plugin.getDescription().getName(), update); - if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(update_version)) { - sendUpdateMsg(Prefix, Spigot, Discord, pluginVersion, update_version); + if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(update_version.getVersion())) { + sendUpdateMsg(Prefix, Spigot, Discord, pluginVersion, update_version.getVersion()); noUpdate = true; } else { if (noUpdate) { @@ -54,10 +65,11 @@ public class T2CBupdateAPI { noUpdate = false; } } - },Prefix, pluginVersion); + }, pluginVersion, SpigotID, url); } }, 0, 20 * 60 * 60L, TimeUnit.SECONDS); } + private Plugin plugin; private int resourceId; @@ -66,47 +78,66 @@ public class T2CBupdateAPI { this.resourceId = resourceId; } - public void getVersion(Consumer consumer, String Prefix, String pluginVersion) { - ProxyServer.getInstance().getScheduler().runAsync(this.plugin, () -> { + public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String URL) { + BungeeCord.getInstance().getScheduler().runAsync(this.plugin, () -> { try { - InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream(); - try { - Scanner scanner = new Scanner(inputStream); + 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"); - try { - if (scanner.hasNext()) { - consumer.accept(scanner.next()); - } - } catch (Throwable var8) { - try { - scanner.close(); - } catch (Throwable var7) { - var8.addSuppressed(var7); - } - throw var8; - } - scanner.close(); - } catch (Throwable var9) { - if (inputStream != null) { - try { - inputStream.close(); - } catch (Throwable var6) { - var9.addSuppressed(var6); - } - } - throw var9; + 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 (inputStream != null) { - inputStream.close(); + + if (!prerelease) { + downloadURL = "https://www.spigotmc.org/resources/" + spigotID; + updateurl = "https://www.spigotmc.org/resources/" + spigotID; } - } catch (IOException var10) { - T2CBupdateObject update = new T2CBupdateObject( + + 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, - "§4No public version found!" + null, + load, + false ); bungeePluginVersins.put(plugin.getDescription().getName(), update); - this.plugin.getLogger().severe(Prefix + "§4 Cannot look for updates: " + var10.getMessage()); + this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage()); } }); } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateObject.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateObject.java deleted file mode 100644 index 114ab3c..0000000 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateObject.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.t2code.t2codelib.BUNGEE.api.update; - -public class T2CBupdateObject { - public String pluginName; - public String pluginVersion; - public String publicVersion; - public T2CBupdateObject(String pluginName, String pluginVersion, String publicVersion){ - this.pluginName = pluginName; - this.pluginVersion = pluginVersion; - this.publicVersion = publicVersion; - } -} diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java index d3c8a7e..d5243b7 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java @@ -13,7 +13,7 @@ import net.t2code.t2codelib.BUNGEE.system.pluginMessaging.opSecurity.T2CapiOpSec import java.io.IOException; public class T2CBload { - public static void onLoad(Plugin plugin, String prefix, String autor, String version, String spigot, String discord, Integer spigotID, Integer bstatsID) { + public static void onLoad(Plugin plugin, String prefix, String autor, String version, String spigot, String discord, Integer spigotID, Integer bstatsID, String url) { long long_ = System.currentTimeMillis(); T2CBsend.console(prefix + "§4============================= " + prefix + " §4============================="); T2CBsend.console(prefix + " §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", "")); @@ -33,7 +33,7 @@ public class T2CBload { throw new RuntimeException(e); } - T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, spigot, discord, spigotID); + T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, spigot, discord, spigotID,url); //API plugin.getProxy().registerChannel("t2c:bcmd"); diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java index 2379741..f044239 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java @@ -23,7 +23,7 @@ public class T2CodeBMain extends Plugin { plugin = this; orgVersion = plugin.getDescription().getVersion(); autor = plugin.getDescription().getAuthor(); - T2CBload.onLoad(plugin, Util.getPrefix(), autor, orgVersion, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID()); + T2CBload.onLoad(plugin, Util.getPrefix(), autor, orgVersion, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID(),Util.getGit()); String[] fv = orgVersion.split("_"); plugin.getDescription().setVersion(fv[0]); version = plugin.getDescription().getVersion(); 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 b0a1787..06af3e1 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 @@ -4,6 +4,8 @@ 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 net.t2code.t2codelib.T2CupdateObject; +import net.t2code.t2codelib.T2CupdateWebData; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java index da33cc7..02bf593 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java @@ -1,5 +1,6 @@ package net.t2code.t2codelib.SPIGOT.api.update; +import net.t2code.t2codelib.T2CupdateObject; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; 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 60f0dfd..a2fd6cb 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 @@ -1,5 +1,7 @@ package net.t2code.t2codelib.SPIGOT.api.update; +import net.t2code.t2codelib.T2CupdateObject; +import net.t2code.t2codelib.T2CupdateWebData; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.json.JSONArray; diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java index da6cbc1..32bcf3a 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java @@ -2,7 +2,7 @@ package net.t2code.t2codelib.SPIGOT.system.cmd; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; -import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateObject; +import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; 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 9c1bd36..6b7f4b9 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 @@ -3,10 +3,7 @@ package net.t2code.t2codelib.SPIGOT.system.cmd; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; -import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateObject; -import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateWebData; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; -import net.t2code.t2codelib.SPIGOT.system.UpdateType; import net.t2code.t2codelib.Util; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java b/src/main/java/net/t2code/t2codelib/T2CupdateObject.java similarity index 92% rename from src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java rename to src/main/java/net/t2code/t2codelib/T2CupdateObject.java index e0e5238..feedd0a 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java +++ b/src/main/java/net/t2code/t2codelib/T2CupdateObject.java @@ -1,4 +1,4 @@ -package net.t2code.t2codelib.SPIGOT.api.update; +package net.t2code.t2codelib; public class T2CupdateObject { diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java b/src/main/java/net/t2code/t2codelib/T2CupdateWebData.java similarity index 94% rename from src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java rename to src/main/java/net/t2code/t2codelib/T2CupdateWebData.java index cd72606..f523d81 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateWebData.java +++ b/src/main/java/net/t2code/t2codelib/T2CupdateWebData.java @@ -1,4 +1,4 @@ -package net.t2code.t2codelib.SPIGOT.api.update; +package net.t2code.t2codelib; import lombok.Getter; From f9b0b512b954f0423980b21719682aacf77432fb Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 18:45:54 +0100 Subject: [PATCH 15/19] 13.4_SNAPSHOT-1 --- pom.xml | 8 ++- .../BUNGEE/api/messages/T2CBminiMessage.java | 30 +++++++++ .../BUNGEE/api/messages/T2CBsend.java | 31 +++++---- .../BUNGEE/api/messages/T2CBtemplate.java | 7 ++- .../BUNGEE/api/update/T2CBupdateAPI.java | 63 ++++++++++++------- .../t2codelib/BUNGEE/system/T2CBload.java | 4 +- .../t2codelib/BUNGEE/system/T2CodeBMain.java | 26 ++++++++ .../BUNGEE/system/config/T2CBlibConfig.java | 9 +++ .../SPIGOT/api/messages/T2ChoverModule.java | 8 +-- .../SPIGOT/api/messages/T2CminiMessage.java | 6 +- .../SPIGOT/api/messages/T2Ctemplate.java | 35 ++++++----- .../SPIGOT/api/update/T2CupdateAPI.java | 28 ++++----- .../SPIGOT/system/T2CodeLibMain.java | 39 +++++++++--- .../t2codelib/SPIGOT/system/cmd/Commands.java | 2 +- .../SPIGOT/system/cmd/CreateReportLog.java | 23 ++++--- .../system/config/config/SelectLibConfig.java | 2 +- .../{SPIGOT/system => }/UpdateType.java | 2 +- src/main/java/net/t2code/t2codelib/Util.java | 2 +- 18 files changed, 222 insertions(+), 103 deletions(-) create mode 100644 src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBminiMessage.java rename src/main/java/net/t2code/t2codelib/{SPIGOT/system => }/UpdateType.java (88%) diff --git a/pom.xml b/pom.xml index a8998f8..8298a3b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 13.4_DEV-3 + 13.4_SNAPSHOT-1 jar T2CodeLib @@ -158,6 +158,12 @@ 4.1.2 compile + + net.kyori + adventure-platform-bungeecord + 4.1.2 + compile + org.projectlombok diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBminiMessage.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBminiMessage.java new file mode 100644 index 0000000..19398ed --- /dev/null +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBminiMessage.java @@ -0,0 +1,30 @@ +package net.t2code.t2codelib.BUNGEE.api.messages; + + +import net.kyori.adventure.platform.bungeecord.BungeeAudiences; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.t2code.t2codelib.BUNGEE.system.T2CodeBMain; +import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace; + +public class T2CBminiMessage { + private static final BungeeAudiences bungeeAudiences = T2CodeBMain.getAdventure(); + + public static void sendSenderMiniMessage(String msg, CommandSender sender) { + bungeeAudiences.sender(sender).sendMessage(replace(msg)); + } + + public static void sendConsoleMiniMessage(String msg) { + bungeeAudiences.console().sendMessage(replace(msg)); + } + + public static void sendPlayerMiniMessage(String msg, ProxiedPlayer player) { + bungeeAudiences.player(player).sendMessage(replace(msg)); + } + + protected static Component replace(String text) { + return MiniMessage.miniMessage().deserialize(T2Creplace.convertColorCode(text)); + } +} diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java index e909438..a43c87d 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java @@ -5,16 +5,21 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.Title; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Plugin; +import net.t2code.t2codelib.BUNGEE.system.T2CodeBMain; import java.util.logging.Level; public class T2CBsend { public static void console(String msg) { - ProxyServer.getInstance().getConsole().sendMessage(msg); + if (T2CodeBMain.getMmIsLoad()) { + T2CBminiMessage.sendConsoleMiniMessage(msg); + } else ProxyServer.getInstance().getConsole().sendMessage(msg); } public static void player(ProxiedPlayer player, String msg) { - player.sendMessage(msg); + if (T2CodeBMain.getMmIsLoad()) { + T2CBminiMessage.sendPlayerMiniMessage(msg, player); + } else player.sendMessage(msg); } public static void title(ProxiedPlayer player, Title msg) { @@ -22,7 +27,9 @@ public class T2CBsend { } public static void sender(CommandSender sender, String msg) { - sender.sendMessage(msg); + if (T2CodeBMain.getMmIsLoad()) { + T2CBminiMessage.sendSenderMiniMessage(msg, sender); + } else sender.sendMessage(msg); } public static void debug(Plugin plugin, String msg) { @@ -31,15 +38,15 @@ public class T2CBsend { public static void debug(Plugin plugin, String msg, Integer stage) { // if (!new File(Main.getPath(), "config.yml").exists()) return; - if (stage == null) { - //todo if (plugin.getConfig().getBoolean("Plugin.Debug")){ - // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg); - // } - return; - } - // todo if (plugin.getConfig().getInt("Plugin.Debug") >= stage) { - // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg); - // } + // if (stage == null) { + // if (plugin.getConfig().getBoolean("Plugin.Debug")) { + // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg); + // } + // return; + //} + //if (plugin.getConfig().getInt("Plugin.Debug") >= stage) { + // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg); + //} } public static void debugmsg(Plugin plugin, String msg) { diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java index cc47a10..09ca8dc 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java @@ -3,6 +3,7 @@ package net.t2code.t2codelib.BUNGEE.api.messages; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.plugin.Plugin; import net.t2code.t2codelib.BUNGEE.api.update.T2CBupdateAPI; +import net.t2code.t2codelib.T2CupdateWebData; public class T2CBtemplate { @@ -39,14 +40,14 @@ public class T2CBtemplate { } public static void sendInfo(CommandSender sender, Plugin plugin, String prefix, String spigot, String discord, String autor) { - String publicVersion = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).webData.getVersion(); + T2CupdateWebData webData = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).webData; String pluginVersion = plugin.getDescription().getVersion(); T2CBsend.sender(sender, prefix + "§4======= " + prefix + " §4======="); T2CBsend.sender(sender, prefix + " §2Autor: §6" + autor); - if (publicVersion.equalsIgnoreCase(pluginVersion)) { + if (webData.getVersion().equalsIgnoreCase(pluginVersion)) { T2CBsend.sender(sender, prefix + " §2Version: §6" + pluginVersion); } else { - T2CBupdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion, sender); + T2CBupdateAPI.sendUpdateMsg(prefix, discord, webData, plugin, sender); } T2CBsend.sender(sender, prefix + " §2Spigot: §6" + spigot); T2CBsend.sender(sender, prefix + " §2Discord: §6" + discord); 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 9088a95..8a1156c 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 @@ -5,10 +5,14 @@ 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.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; +import net.t2code.t2codelib.UpdateType; import org.json.JSONArray; import org.json.JSONObject; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; @@ -22,52 +26,63 @@ import java.util.function.Consumer; public class T2CBupdateAPI { public static HashMap bungeePluginVersins = new HashMap<>(); - public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version) { - T2CBsend.console("§4=========== " + Prefix + " §4==========="); - T2CBsend.console("§6A new version was found!"); - T2CBsend.console("§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version); - T2CBsend.console("§6You can download it here: §e" + Spigot); - T2CBsend.console("§6You can find more information on Discord: §e" + Discord); - T2CBsend.console("§4=========== " + Prefix + " §4==========="); - } + 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 = "
╔══════════════" + 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 f = "
╚══════════════" + prefix + "══════════════"; + String text = h + s1 + s2 + s3 + s4 + f; + if (sender == null) { + T2CBsend.console(text); + } else T2CBsend.sender(sender, text); - public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version, CommandSender sender) { - T2CBsend.sender(sender, "§4=========== " + Prefix + " §4==========="); - T2CBsend.sender(sender, "§6A new version was found!"); - T2CBsend.sender(sender, "§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version); - T2CBsend.sender(sender, "§6You can download it here: §e" + Spigot); - T2CBsend.sender(sender, "§6You can find more information on Discord: §e" + Discord); - T2CBsend.sender(sender, "§4=========== " + Prefix + " §4==========="); } private static Boolean noUpdate = true; private static String pluginVersion; - public static void onUpdateCheckTimer(Plugin plugin, String Prefix, String Spigot, String Discord, Integer SpigotID, String url) { + 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((update_version) -> { + (new T2CBupdateAPI(plugin, spigotID)).getVersion((webData) -> { pluginVersion = plugin.getDescription().getVersion(); T2CupdateObject update = new T2CupdateObject( plugin.getDescription().getName(), plugin.getDescription().getVersion(), - update_version, + webData, false, - !plugin.getDescription().getVersion().equals(update_version.getVersion()) + !plugin.getDescription().getVersion().equals(webData.getVersion()) ); bungeePluginVersins.put(plugin.getDescription().getName(), update); - if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(update_version.getVersion())) { - sendUpdateMsg(Prefix, Spigot, Discord, pluginVersion, update_version.getVersion()); + if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(webData.getVersion())) { + sendUpdateMsg(prefix, discord, webData, plugin, null); noUpdate = true; } else { if (noUpdate) { - T2CBsend.console(Prefix + " §2No update found."); + T2CBsend.console(prefix + " §2No update found."); noUpdate = false; } } - }, pluginVersion, SpigotID, url); + }, pluginVersion, spigotID, url); } - }, 0, 20 * 60 * 60L, TimeUnit.SECONDS); + }, 0, T2CBlibConfig.getUpdateTimer() * 60 * 20L, TimeUnit.SECONDS); } private Plugin plugin; diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java index d5243b7..f3398e7 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java @@ -33,7 +33,7 @@ public class T2CBload { throw new RuntimeException(e); } - T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, spigot, discord, spigotID,url); + T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, discord, spigotID,url); //API plugin.getProxy().registerChannel("t2c:bcmd"); @@ -48,7 +48,7 @@ public class T2CBload { plugin.getProxy().registerChannel("t2c:aresp"); plugin.getProxy().getPluginManager().registerListener(plugin, new T2CapiAutoResponse()); } - if (T2CBlibConfig.getApiAutoResponse()) { + if (T2CBlibConfig.getApiOpSecurity()) { plugin.getProxy().registerChannel("t2c:t2c:opsec"); plugin.getProxy().getPluginManager().registerListener(plugin, new T2CapiOpSecurity()); } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java index f044239..db5cd3e 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java @@ -1,5 +1,7 @@ package net.t2code.t2codelib.BUNGEE.system; +import lombok.NonNull; +import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.md_5.bungee.api.plugin.Plugin; import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend; import net.t2code.t2codelib.Util; @@ -16,6 +18,16 @@ public class T2CodeBMain extends Plugin { private static String orgVersion; private static String autor; + private static Boolean mmIsLoad = true; + private static BungeeAudiences adventure; + + public static BungeeAudiences getAdventure() { + if(adventure == null) { + throw new IllegalStateException("Cannot retrieve audience provider while plugin is not enabled"); + } + return adventure; + } + @Override public void onEnable() { @@ -23,6 +35,11 @@ public class T2CodeBMain extends Plugin { plugin = this; orgVersion = plugin.getDescription().getVersion(); autor = plugin.getDescription().getAuthor(); + try { + adventure = BungeeAudiences.create(this); + } catch (Exception e){ + mmIsLoad = false; + } T2CBload.onLoad(plugin, Util.getPrefix(), autor, orgVersion, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID(),Util.getGit()); String[] fv = orgVersion.split("_"); plugin.getDescription().setVersion(fv[0]); @@ -32,6 +49,12 @@ public class T2CodeBMain extends Plugin { @Override public void onDisable() { // Plugin shutdown logic + if (mmIsLoad){ + if(adventure != null) { + adventure.close(); + adventure = null; + } + } T2CBsend.console(Util.getPrefix() + "§4============================= " + Util.getPrefix() + " §4============================="); T2CBsend.console(Util.getPrefix() + " §2Autor: §6" + String.valueOf(plugin.getDescription().getAuthor()).replace("[", "").replace("]", "")); T2CBsend.console(Util.getPrefix() + " §2Version: §6" + version); @@ -40,4 +63,7 @@ public class T2CodeBMain extends Plugin { T2CBsend.console(Util.getPrefix() + " §4Plugin successfully disabled."); T2CBsend.console(Util.getPrefix() + "§4============================= " + Util.getPrefix() + " §4============================="); } + public static Boolean getMmIsLoad() { + return mmIsLoad; + } } diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java index c5f2bbe..88ba548 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java @@ -21,6 +21,8 @@ public class T2CBlibConfig { config.createNewFile(); } Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); + T2CBconfig.set("UpdateCheck.TimerInMin", 60, configuration); + T2CBconfig.set("API.CommandGUI.Enable", false, configuration); T2CBconfig.set("API.AutoResponse.Enable", false, configuration); T2CBconfig.set("API.OPSecurity.Enable", false, configuration); @@ -33,15 +35,22 @@ public class T2CBlibConfig { File config = new File(T2CodeBMain.getPlugin().getDataFolder(), "config.yml"); Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); + updateTimer = configuration.getInt("UpdateCheck.TimerInMin"); + apiCommandGUIEnable = configuration.getBoolean("API.CommandGUI.Enable"); apiAutoResponse = configuration.getBoolean("API.AutoResponse.Enable"); apiOpSecurity = configuration.getBoolean("API.OPSecurity.Enable"); } + private static Integer updateTimer; private static Boolean apiCommandGUIEnable; private static Boolean apiAutoResponse; private static Boolean apiOpSecurity; + public static Integer getUpdateTimer() { + return updateTimer; + } + public static Boolean getApiCommandGUIEnable() { return apiCommandGUIEnable; } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java index 9971720..7dbbd17 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java @@ -18,16 +18,16 @@ public class T2ChoverModule { t2cmodule(msg, player); return; } - T2CminiMessage.miniMessage(msg, player); + T2CminiMessage.sendPlayerMiniMessage(msg, player); } public static void moduleSender(String msg, CommandSender sender) { - T2CminiMessage.miniMessage(msg, sender); + T2CminiMessage.sendSenderMiniMessage(msg, sender); } public static void moduleConsole(String msg) { - if (T2CodeLibMain.getNmIsLoad()) { - T2CminiMessage.sendMiniMessage(msg); + if (T2CodeLibMain.getMmIsLoad()) { + T2CminiMessage.sendConsoleMiniMessage(msg); return; } Bukkit.getConsoleSender().sendMessage(msg); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java index b54dc38..12d8940 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java @@ -10,15 +10,15 @@ import org.bukkit.entity.Player; public class T2CminiMessage { private static final BukkitAudiences bukkitAudiences = T2CodeLibMain.getPlugin().getAdventure(); - public static void miniMessage(String msg, CommandSender sender) { + public static void sendSenderMiniMessage(String msg, CommandSender sender) { bukkitAudiences.sender(sender).sendMessage(replace(msg)); } - public static void sendMiniMessage(String msg) { + public static void sendConsoleMiniMessage(String msg) { bukkitAudiences.console().sendMessage(replace(msg)); } - public static void miniMessage(String msg, Player player) { + public static void sendPlayerMiniMessage(String msg, Player player) { bukkitAudiences.player(player).sendMessage(replace(msg)); } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java index d3d9cf0..17995c8 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java @@ -1,6 +1,7 @@ package net.t2code.t2codelib.SPIGOT.api.messages; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; +import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -24,31 +25,33 @@ public class T2Ctemplate { T2Csend.console(prefix + " | | / /| | "); T2Csend.console(prefix + " | | / /_| |____ "); T2Csend.console(prefix + " |_| |____|\\_____|"); - T2Csend.console(prefix + " §4 §e------------------"); - T2Csend.console(prefix + " §4 §e| §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", "")); - T2Csend.console(prefix + " §4 §e| §2Version: §6" + version); - T2Csend.console(prefix + " §4 §e| §2Spigot: §6" + spigot); - T2Csend.console(prefix + " §4 §e| §2Discord: §6" + discord); + T2Csend.console(prefix + " §4 §e╔══════════════════════════"); + T2Csend.console(prefix + " §4 §e║ §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", "")); + T2Csend.console(prefix + " §4 §e║ §2Version: §6" + version); + T2Csend.console(prefix + " §4 §e║ §2Spigot: §6" + spigot); + T2Csend.console(prefix + " §4 §e║ §2Discord: §6" + discord); if (isPremium != null) { if (isPremium) { - T2Csend.console(prefix + " §4 §e| §6Premium: §2true"); - } else T2Csend.console(prefix + " §4 §e| §6Premium: §4false"); + T2Csend.console(prefix + " §4 §e║ §6Premium: §2true"); + } else T2Csend.console(prefix + " §4 §e║ §6Premium: §4false"); if (isVerify != null) { if (isVerify) { - T2Csend.console(prefix + " §4 §e| §6Verify: §2true"); - } else T2Csend.console(prefix + " §4 §e| §6Verify: §4false"); - } else T2Csend.console(prefix + " §4 §e| §6Verify: §4false"); + T2Csend.console(prefix + " §4 §e║ §6Verify: §2true"); + } else T2Csend.console(prefix + " §4 §e║ §6Verify: §4false"); + } else T2Csend.console(prefix + " §4 §e║ §6Verify: §4false"); } - T2Csend.console(prefix + " §4 §e-------------------"); + T2Csend.console(prefix + " §4 §e╚══════════════════════════"); if (version.toLowerCase().contains("dev") || version.toLowerCase().contains("snapshot") || version.toLowerCase().contains("beta")) { T2Csend.console(prefix + " §eYou are running §4" + version + " §eof " + prefix + "§e! Some features may not be working as expected. Please report all" + " bugs here: http://dc.t2code.net §4UpdateChecker & bStats may be disabled!"); - T2Csend.console(prefix + " §4 §e-------------------"); - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); + onLoadSeparateStroke(prefix); + if (!SelectLibConfig.getT2cTestDevelopment()){ + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } } } 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 06af3e1..430e1e9 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 @@ -2,11 +2,10 @@ 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.UpdateType; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -94,16 +93,17 @@ public class T2CupdateAPI { value = UpdateType.SNAPSHOT.text; } } else value = UpdateType.STABLE.text; - String h = "§4=========== " + prefix + " §4==========="; - String s1 = "§6A new [value] version was found!§r".replace("[value]", value); - String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + webData.getVersion(); - String s3 = "§6You can download it here: §e" + webData.getUpdateUrl(); - String s4 = "§6You can find more information on Discord: §e" + discord; - String text = "
" + h + "
" + s1 + "
" + s2 + "
" + s3 + "
" + s4 + "
" + h; + 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 f = "
╚══════════════" + prefix + "══════════════"; + String text = h + s1 + s2 + s3 + s4 + f; T2Csend.console(text); } - public static String updateInfo(CommandSender sender, String[] args, Boolean player) { + public static String updateInfo(String[] args, Boolean player) { T2CupdateObject object; try { object = T2CupdateAPI.pluginVersions.get(args[1]); @@ -140,12 +140,11 @@ public class T2CupdateAPI { String updateInfoString = "
[value]:"; String updateTitleString = "
Title: " + updateTitle + ""; String updateVersionString = "
Version: " + updateVersion + ""; - String updateAtString = "
Update at: " + updateAt + ""; - String updateTypeString = "
Update type: " + updateType + ""; + String updateAtString = "
Published on: " + updateAt + ""; + String updateTypeString = "
Version type: " + updateType + ""; String updateButton; if (player) { - // updateButton = "
" + updateUpdate + "'>Download"; updateButton = "
" + updateUpdate + "'>Download | Update Description"; } else updateButton = "
Download: " + updateUpdate + ""; @@ -170,7 +169,6 @@ public class T2CupdateAPI { return text; } - public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) { new BukkitRunnable() { @Override @@ -184,7 +182,7 @@ public class T2CupdateAPI { false, !plugin.getDescription().getVersion().equals(update_version) ); pluginVersions.put(plugin.getName(), update); - if (!pluginVersions.get(plugin.getName()).updateAvailable) { + if (pluginVersions.get(plugin.getName()).updateAvailable) { if (!update.load) { new BukkitRunnable() { @Override @@ -222,7 +220,7 @@ public class T2CupdateAPI { !plugin.getDescription().getVersion().equals(webData.getVersion()) ); pluginVersions.put(plugin.getName(), update); - if (!pluginVersions.get(plugin.getName()).updateAvailable) { + if (pluginVersions.get(plugin.getName()).updateAvailable) { if (!update.load) { new BukkitRunnable() { @Override diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java index 95b6be7..28c6baf 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -18,6 +18,7 @@ import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate; import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg; import net.t2code.t2codelib.Util; import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -32,7 +33,7 @@ public final class T2CodeLibMain extends JavaPlugin { private static List autor; private static String version; - private static Boolean nmIsLoad = true; + private static Boolean mmIsLoad = true; private static Boolean load = false; @Override @@ -41,7 +42,11 @@ public final class T2CodeLibMain extends JavaPlugin { plugin = this; autor = plugin.getDescription().getAuthors(); version = plugin.getDescription().getVersion(); - adventure = BukkitAudiences.create(this); + try { + adventure = BukkitAudiences.create(this); + } catch (Exception e) { + mmIsLoad = false; + } long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord()); String prefix = Util.getPrefix(); @@ -58,10 +63,12 @@ public final class T2CodeLibMain extends JavaPlugin { T2Csend.warning(plugin, "The 1.20.* is a very fresh / new version. If there are any bugs in our plugins, please report them to us via our Discord: http://dc.t2code.net"); T2Csend.console(prefix); T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!"); - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); + if (!SelectLibConfig.getT2cTestDevelopment()) { + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } } } T2Csend.console(prefix + " §3Server run on: §6" + T2CmcVersion.getMcVersion() + " / " + T2CmcVersion.getNms()); @@ -100,6 +107,7 @@ public final class T2CodeLibMain extends JavaPlugin { ReportLogStorage.load(); Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin); + checkIsBungee(); T2Ctemplate.onLoadFooter(prefix, long_); load = true; } @@ -117,7 +125,7 @@ public final class T2CodeLibMain extends JavaPlugin { Vault.vaultDisable(); T2Ctemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord()); - if (nmIsLoad) { + if (mmIsLoad) { if (this.adventure != null) { this.adventure.close(); this.adventure = null; @@ -167,7 +175,20 @@ public final class T2CodeLibMain extends JavaPlugin { return adventure; } - public static Boolean getNmIsLoad() { - return nmIsLoad; + private static void checkIsBungee() { + File config = new File("spigot.yml"); + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); + + isBungee = yamlConfiguration.getBoolean("settings.bungeecord"); + } + + private static Boolean isBungee; + + public static Boolean getIsBungee() { + return isBungee; + } + + public static Boolean getMmIsLoad() { + return mmIsLoad; } } 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 6b7f4b9..87e168c 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 @@ -52,6 +52,6 @@ public class Commands { } public static void updateInfo(CommandSender sender, String[] args) { - T2Csend.sender(sender, T2CupdateAPI.updateInfo(sender, args, sender instanceof Player)); + T2Csend.sender(sender, T2CupdateAPI.updateInfo(args, sender instanceof Player)); } } 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 127a13b..aa44837 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 @@ -17,10 +17,12 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.json.JSONObject; + import java.io.*; import java.net.HttpURLConnection; import java.net.URL; @@ -45,13 +47,15 @@ public class CreateReportLog { try { pWriter = new PrintWriter(new FileWriter(file.getPath())); String timeStamp = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy").format(Calendar.getInstance().getTime()); - pWriter.println("Created on: " + timeStamp); + pWriter.println("Created on: " + timeStamp + " - from: " + sender.getName()); pWriter.println(); pWriter.println("Server Bukkit version: " + T2CmcVersion.getBukkitVersion()); pWriter.println("Server run on: " + T2CmcVersion.getMcVersion()); pWriter.println("Server NMS: " + T2CmcVersion.getNms()); - pWriter.println(); pWriter.println("Online Mode: " + Bukkit.getOnlineMode()); + pWriter.println("Bungee Mode: " + T2CodeLibMain.getIsBungee()); + pWriter.println("Server Port: " + Bukkit.getServer().getPort()); + pWriter.println(); pWriter.println("Worlds: " + Bukkit.getWorlds()); pWriter.println("OP-Player:"); for (OfflinePlayer player : Bukkit.getOperators()) { @@ -92,7 +96,6 @@ public class CreateReportLog { pWriter.println("T2C-LuckyBox isV: " + LuckyBoxAPI.isV()); pWriter.println(); } - pWriter.println(); pWriter.println("OfflinePlayers: "); for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { pWriter.println(" - " + player.getName() + " - " + player.getUniqueId()); @@ -102,7 +105,7 @@ public class CreateReportLog { pWriter.println("Plugins: "); for (Plugin pl : Bukkit.getPluginManager().getPlugins()) { pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " - + pl.getDescription().getAuthors()+" - SoftDepend: " + pl.getDescription().getSoftDepend() + " - Depend: " + pl.getDescription().getDepend() + + pl.getDescription().getAuthors() + " - SoftDepend: " + pl.getDescription().getSoftDepend() + " - Depend: " + pl.getDescription().getDepend() + " LoadBefore: " + pl.getDescription().getLoadBefore() + " - Website: " + pl.getDescription().getWebsite()); } } catch (IOException ioe) { @@ -154,11 +157,11 @@ public class CreateReportLog { "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 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].") - .replace("[key]",fileID).replace("[url]",downloadURL)); + .replace("[key]", fileID).replace("[url]", downloadURL)); ReportLogStorage.add(fileID); } @@ -231,11 +234,11 @@ public class CreateReportLog { HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int response = con.getResponseCode(); - if(response == 200){ + if (response == 200) { ReportLogStorage.remove(arg); - T2Csend.sender(sender,"Deleted report: " + arg); - }else { - T2Csend.sender(sender,"Error while deleting report: " + arg); + T2Csend.sender(sender, "Deleted report: " + arg); + } else { + T2Csend.sender(sender, "Error while deleting report: " + arg); } con.disconnect(); } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java index f1bb07b..93b9ad0 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java @@ -8,7 +8,7 @@ import java.io.File; public class SelectLibConfig { private static Boolean UpdateCheckOnJoin; - private static Boolean t2cTestDevelopment; + private static Boolean t2cTestDevelopment = false; private static Integer UpdateCheckTimeInterval; private static Boolean Debug; private static String language; diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/UpdateType.java b/src/main/java/net/t2code/t2codelib/UpdateType.java similarity index 88% rename from src/main/java/net/t2code/t2codelib/SPIGOT/system/UpdateType.java rename to src/main/java/net/t2code/t2codelib/UpdateType.java index 27e4f96..b7b897e 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/UpdateType.java +++ b/src/main/java/net/t2code/t2codelib/UpdateType.java @@ -1,4 +1,4 @@ -package net.t2code.t2codelib.SPIGOT.system; +package net.t2code.t2codelib; public enum UpdateType { PRERELEASE("Pre-Release"), diff --git a/src/main/java/net/t2code/t2codelib/Util.java b/src/main/java/net/t2code/t2codelib/Util.java index 661e1a9..0470258 100644 --- a/src/main/java/net/t2code/t2codelib/Util.java +++ b/src/main/java/net/t2code/t2codelib/Util.java @@ -35,7 +35,7 @@ public class Util { public static List getT2cPlugins() { return Arrays.asList( - //"T2CodeLib", + "T2CodeLib", "T2C-LuckyBox", "WonderBagShop", "CommandGUI", From f0b5b2e65b600fa6f24633dc312f42904626a7e5 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 22:37:36 +0100 Subject: [PATCH 16/19] 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() { From 8114035cd945d403e795f867bf1fbf5df8d2a1f6 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 22:59:17 +0100 Subject: [PATCH 17/19] seePreReleaseUpdates #1 --- .../BUNGEE/api/update/T2CBupdateAPI.java | 1 + .../BUNGEE/system/config/T2CBlibConfig.java | 6 ++++ .../SPIGOT/api/update/T2CupdateAPI.java | 1 + .../SPIGOT/system/cmd/CreateReportLog.java | 12 ++++--- .../system/config/config/ConfigCreate.java | 1 + .../system/config/config/SelectLibConfig.java | 35 ++++++++++++------- 6 files changed, 38 insertions(+), 18 deletions(-) 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 8e2bf32..7a0b001 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 @@ -31,6 +31,7 @@ public class T2CBupdateAPI { String pluginVersion = plugin.getDescription().getVersion(); String value; if (webData.isPreRelease()) { + if (!T2CBlibConfig.getSeePreReleaseUpdates()) return; value = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { value = UpdateType.DEVELOPMENT.text; diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java index 88ba548..1ee83fd 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java @@ -36,6 +36,7 @@ public class T2CBlibConfig { Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); updateTimer = configuration.getInt("UpdateCheck.TimerInMin"); + seePreReleaseUpdates = configuration.getBoolean("UpdateCheck.SeePreReleaseUpdates"); apiCommandGUIEnable = configuration.getBoolean("API.CommandGUI.Enable"); apiAutoResponse = configuration.getBoolean("API.AutoResponse.Enable"); @@ -43,6 +44,7 @@ public class T2CBlibConfig { } private static Integer updateTimer; + private static Boolean seePreReleaseUpdates; private static Boolean apiCommandGUIEnable; private static Boolean apiAutoResponse; private static Boolean apiOpSecurity; @@ -51,6 +53,10 @@ public class T2CBlibConfig { return updateTimer; } + public static Boolean getSeePreReleaseUpdates() { + return seePreReleaseUpdates; + } + public static Boolean getApiCommandGUIEnable() { return apiCommandGUIEnable; } 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 7e92a48..8d2c819 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 @@ -61,6 +61,7 @@ public class T2CupdateAPI { String value; if (webData.isPreRelease()) { + if (!SelectLibConfig.getSeePreReleaseUpdates()) return; value = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { value = UpdateType.DEVELOPMENT.text; 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 8d49b21..3835b40 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 @@ -158,11 +158,13 @@ public class CreateReportLog { 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 Click to delete'>delte yor Debug-File by clicking me.").replace("[key]", fileID).replace("[url]", downloadURL)); + T2Csend.sender(sender, ("[prefix] A DebugLog zip has been created." + + "
[prefix] You can download it Download the debug file'>here." + + "
[prefix] Please enter the following key in the ticket: Copy to clipboard'>[key]
" + + "
[prefix]Do not share the download URL with anyone!" + + "
[prefix] Click to delete'>You can delte yor Debug-File by clicking me." + + "
[prefix] (If you do not delete the debug file, it will be deleted automatically after 14 days!)").replace("[key]", fileID) + .replace("[url]", downloadURL).replace("[prefix]",Util.getPrefix())); } 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/SPIGOT/system/config/config/ConfigCreate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java index 6cb30b2..4b20482 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java @@ -24,6 +24,7 @@ public class ConfigCreate { T2Cconfig.set("Plugin.UpdateCheck.OnJoin", true, yamlConfiguration); T2Cconfig.set("Plugin.UpdateCheck.TimeInterval", 60, yamlConfiguration); + T2Cconfig.set("Plugin.UpdateCheck.SeePreReleaseUpdates", true, yamlConfiguration); T2Cconfig.set("Plugin.language", "english", yamlConfiguration); T2Cconfig.set("BungeeCord.Enable", false, yamlConfiguration); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java index 93b9ad0..5ac9f9a 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java @@ -7,29 +7,34 @@ import java.io.File; public class SelectLibConfig { - private static Boolean UpdateCheckOnJoin; + private static Boolean updateCheckOnJoin; private static Boolean t2cTestDevelopment = false; - private static Integer UpdateCheckTimeInterval; - private static Boolean Debug; + private static Integer updateCheckTimeInterval; + private static Boolean seePreReleaseUpdates; + private static Boolean debug; private static String language; private static Boolean bungee; - private static Boolean InventoriesCloseByServerStop; + private static Boolean inventoriesCloseByServerStop; public static void onSelect() { File config = new File(T2CodeLibMain.getPath(), "config.yml"); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); - UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin"); - t2cTestDevelopment = yamlConfiguration.getBoolean("t2cTestDevelopment"); - UpdateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval"); - Debug = yamlConfiguration.getBoolean("Plugin.Debug"); + if (yamlConfiguration.contains("t2cTestDevelopment")){ + t2cTestDevelopment = yamlConfiguration.getBoolean("t2cTestDevelopment"); + } + + updateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin"); + updateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval"); + seePreReleaseUpdates = yamlConfiguration.getBoolean("Plugin.UpdateCheck.SeePreReleaseUpdates"); + debug = yamlConfiguration.getBoolean("Plugin.Debug"); language = yamlConfiguration.getString("Plugin.language"); bungee = yamlConfiguration.getBoolean("BungeeCord.Enable"); - InventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop"); + inventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop"); } public static Boolean getUpdateCheckOnJoin() { - return UpdateCheckOnJoin; + return updateCheckOnJoin; } public static Boolean getT2cTestDevelopment() { @@ -37,11 +42,15 @@ public class SelectLibConfig { } public static Integer getUpdateCheckTimeInterval() { - return UpdateCheckTimeInterval; + return updateCheckTimeInterval; + } + + public static Boolean getSeePreReleaseUpdates() { + return seePreReleaseUpdates; } public static Boolean getDebug() { - return Debug; + return debug; } public static String getLanguage() { @@ -53,7 +62,7 @@ public class SelectLibConfig { } public static Boolean getInventoriesCloseByServerStop() { - return InventoriesCloseByServerStop; + return inventoriesCloseByServerStop; } } From d27ef185e6bc586cc91e7503f1d8542a05929eb4 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Tue, 15 Nov 2022 00:36:25 +0100 Subject: [PATCH 18/19] 13.4_SNAPSHOT-2 --- .../BUNGEE/api/update/T2CBupdateAPI.java | 4 +- .../api/update/T2CBupdateCheckerGit.java | 11 ++++- .../SPIGOT/api/update/T2CupdateAPI.java | 24 +++++++---- .../SPIGOT/api/update/T2CupdateChecker.java | 6 ++- .../api/update/T2CupdateCheckerGit.java | 7 ++-- .../SPIGOT/system/T2CodeLibMain.java | 3 +- .../t2codelib/SPIGOT/system/cmd/Commands.java | 41 ++++++++++++++----- .../SPIGOT/system/cmd/CreateReportLog.java | 20 ++++++++- .../net/t2code/t2codelib/T2CupdateObject.java | 5 ++- 9 files changed, 88 insertions(+), 33 deletions(-) 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 7a0b001..aefd39f 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 @@ -31,7 +31,6 @@ public class T2CBupdateAPI { String pluginVersion = plugin.getDescription().getVersion(); String value; if (webData.isPreRelease()) { - if (!T2CBlibConfig.getSeePreReleaseUpdates()) return; value = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { value = UpdateType.DEVELOPMENT.text; @@ -69,7 +68,8 @@ public class T2CBupdateAPI { plugin.getDescription().getVersion(), webData, false, - !plugin.getDescription().getVersion().equals(webData.getVersion()) + !plugin.getDescription().getVersion().equals(webData.getVersion()), + true ); bungeePluginVersins.put(plugin.getDescription().getName(), update); if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(webData.getVersion())) { 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 index 5571f51..5e8addc 100644 --- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java +++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java @@ -2,6 +2,8 @@ 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.BUNGEE.system.config.T2CBlibConfig; +import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.T2CupdateObject; import net.t2code.t2codelib.T2CupdateWebData; import org.json.JSONArray; @@ -26,9 +28,13 @@ public class T2CBupdateCheckerGit { public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String gitKey) { String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; + if (!T2CBlibConfig.getSeePreReleaseUpdates()){ + RepoURL = RepoURL + "&pre-release=false"; + } + String finalRepoURL = RepoURL; BungeeCord.getInstance().getScheduler().runAsync(this.plugin, () -> { try { - URL url = new URL(RepoURL); + URL url = new URL(finalRepoURL); URLConnection yc = url.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( @@ -81,7 +87,8 @@ public class T2CBupdateCheckerGit { pluginVersion, null, load, - false + false, + true ); 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 8d2c819..c8c9bfe 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 @@ -1,5 +1,6 @@ package net.t2code.t2codelib.SPIGOT.api.update; +import com.sun.org.apache.xpath.internal.operations.Bool; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; import net.t2code.t2codelib.UpdateType; @@ -17,7 +18,7 @@ public class T2CupdateAPI { public static HashMap pluginVersions = new HashMap<>(); public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) { - if (!SelectLibConfig.getUpdateCheckOnJoin()) { + if (! pluginVersions.get(plugin.getName()).updateCheckOnJoin) { return; } if (!player.hasPermission(perm) && !player.isOp()) { @@ -33,7 +34,6 @@ public class T2CupdateAPI { return; } T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData; - String pluginVersion = plugin.getDescription().getVersion(); if (!pluginVersions.get(plugin.getName()).updateAvailable) return; new BukkitRunnable() { @Override @@ -61,7 +61,7 @@ public class T2CupdateAPI { String value; if (webData.isPreRelease()) { - if (!SelectLibConfig.getSeePreReleaseUpdates()) return; + //todo if (!SelectLibConfig.getSeePreReleaseUpdates()) return; value = UpdateType.PRERELEASE.text; if (publicVersion.toLowerCase().contains("dev")) { value = UpdateType.DEVELOPMENT.text; @@ -180,7 +180,9 @@ 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, !plugin.getDescription().getVersion().equals(update_version) + false, + !plugin.getDescription().getVersion().equals(update_version), + true ); pluginVersions.put(plugin.getName(), update); if (pluginVersions.get(plugin.getName()).updateAvailable) { @@ -199,13 +201,16 @@ public class T2CupdateAPI { update.load = true; } } - }, prefix, plugin.getDescription().getVersion()); + }, prefix, plugin.getDescription().getVersion(),true,true,60); } }.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L); } - public static void onUpdateCheck(Plugin plugin, String prefix, String gitKey, Integer spigotID, String discord) { + public static void onUpdateCheck(Plugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) { String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; + if (!SelectLibConfig.getSeePreReleaseUpdates()) { + RepoURL = RepoURL + "&pre-release=false"; + } if (!RepoURL.contains("?limit=1")) { RepoURL = RepoURL + "?limit=1"; } @@ -219,7 +224,8 @@ public class T2CupdateAPI { plugin.getDescription().getVersion(), webData, false, - !plugin.getDescription().getVersion().equals(webData.getVersion()) + !plugin.getDescription().getVersion().equals(webData.getVersion()), + updateCheckOnJoin ); pluginVersions.put(plugin.getName(), update); if (pluginVersions.get(plugin.getName()).updateAvailable) { @@ -238,8 +244,8 @@ public class T2CupdateAPI { update.load = true; } } - }, plugin.getDescription().getVersion(), spigotID, finalRepoURL); + }, plugin.getDescription().getVersion(), spigotID, finalRepoURL, updateCheckOnJoin, seePreReleaseUpdates, timeInterval); } - }.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L); + }.runTaskTimerAsynchronously(plugin, 0L, timeInterval * 60 * 20L); } } diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java index 02bf593..b519197 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java @@ -19,7 +19,7 @@ public class T2CupdateChecker { this.resourceId = resourceId; } - public void getVersion(Consumer consumer, String Prefix, String pluginVersion) { + public void getVersion(Consumer consumer, String Prefix, String pluginVersion, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) { if (!plugin.isEnabled()) { return; } @@ -64,7 +64,9 @@ public class T2CupdateChecker { pluginVersion, null, load, - false + false, + updateCheckOnJoin + ); T2CupdateAPI.pluginVersions.put(plugin.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/T2CupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java index 0626f3f..73ac024 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 @@ -21,7 +21,7 @@ public class T2CupdateCheckerGit { this.plugin = plugin; } - public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String URL) { + public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String URL, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) { if (!plugin.isEnabled()) { return; } @@ -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("'","''").replace("**",""); + String body = obj.getString("body").replace("\n", "
").replace("\r", "").replace("'", "''").replace("**", ""); String updateurl = obj.getString("html_url"); boolean prerelease = obj.getBoolean("prerelease"); @@ -80,7 +80,8 @@ public class T2CupdateCheckerGit { pluginVersion, null, load, - false + false, + updateCheckOnJoin ); T2CupdateAPI.pluginVersions.put(plugin.getName(), update); this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage()); diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java index 28c6baf..402b0f5 100644 --- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java +++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java @@ -99,7 +99,8 @@ public final class T2CodeLibMain extends JavaPlugin { SelectLibConfig.onSelect(); SelectLibMsg.onSelect(); - T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), Util.getSpigotID(), Util.getDiscord()); + T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), Util.getSpigotID(), Util.getDiscord(), SelectLibConfig.getUpdateCheckOnJoin(), SelectLibConfig.getSeePreReleaseUpdates(), + SelectLibConfig.getUpdateCheckTimeInterval()); Metrics.Bstats(plugin, Util.getBstatsID()); if (SelectLibConfig.getBungee()) { Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd"); 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 e5506ae..cec196e 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 @@ -23,17 +23,36 @@ public class Commands { } switch (args[1].toLowerCase()) { case "createreportlog": - Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { - @Override - public void run() { - 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); - } - } - }); + switch (args.length){ + case 2: + if (sender instanceof Player) { + T2Csend.sender(sender, "The debug zip file is automatically uploaded to T2Code's servers
and automatically deleted " + + "after 14 days!
The file can also be deleted manually by you via command!

Confirm the" + + " upload'>upload | " + + "Do not upload'>keep the file on your server"); + } else T2Csend.sender(sender, "The debug zip file is automatically uploaded to T2Code's servers
and automatically deleted " + + "after 14 days!
The file can also be deleted manually by you via command!

Confirm the upload with the command:" + + "
/t2c debug createReportLog confirmupload
Keep the file on your server and do not upload it with the command:" + + "
/t2c debug createReportLog noupload"); + break; + case 3: + Boolean upload = args[2].equalsIgnoreCase("confirmupload"); + Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { + @Override + public void run() { + try { + CreateReportLog.create(sender, upload); + } 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); + } + } + }); + break; + default: + T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog"); + return; + } break; case "deletereportlog": if (args.length != 3) { 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 3835b40..3b20f59 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 @@ -27,13 +27,14 @@ import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.file.Files; +import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class CreateReportLog { - protected static void create(CommandSender sender) throws IOException { + protected static void create(CommandSender sender, Boolean confirmUpload) throws IOException { T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog is created..."); String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime()); @@ -140,9 +141,24 @@ public class CreateReportLog { e.printStackTrace(); } file.delete(); + File zipFile = new File(zipPath); + + if (!confirmUpload){ + if (sender instanceof Player) { + T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath); + } + T2Csend.console(Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath); + + Files.move(Paths.get(zipPath),Paths.get(directory+"/"+zipFile.getName())); + zipFile.delete(); + directoryTemp.delete(); + return; + } + + HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("https://debug.t2code.net/uploadFile"); - File zipFile = new File(zipPath); + FileBody bin = new FileBody(zipFile); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("file", bin); diff --git a/src/main/java/net/t2code/t2codelib/T2CupdateObject.java b/src/main/java/net/t2code/t2codelib/T2CupdateObject.java index feedd0a..d70e3b4 100644 --- a/src/main/java/net/t2code/t2codelib/T2CupdateObject.java +++ b/src/main/java/net/t2code/t2codelib/T2CupdateObject.java @@ -8,16 +8,19 @@ public class T2CupdateObject { public T2CupdateWebData webData; public Boolean load; public Boolean updateAvailable; + public Boolean updateCheckOnJoin; public T2CupdateObject(String pluginName, String pluginVersion, T2CupdateWebData webData, Boolean load, - Boolean updateAvailable) { + Boolean updateAvailable, + Boolean updateCheckOnJoin) { this.pluginName = pluginName; this.pluginVersion = pluginVersion; this.webData = webData; this.load = load; this.updateAvailable = updateAvailable; + this.updateCheckOnJoin = updateCheckOnJoin; } } From 9986f477b29203225154770ba6c299ead5bd8cba Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Tue, 15 Nov 2022 02:17:26 +0100 Subject: [PATCH 19/19] 13.4 --- pom.xml | 2 +- .../SPIGOT/api/update/T2CupdateAPI.java | 2 +- .../t2codelib/SPIGOT/system/cmd/Commands.java | 11 ++++++---- .../SPIGOT/system/cmd/CreateReportLog.java | 20 ++++++++++--------- src/main/java/net/t2code/t2codelib/Util.java | 2 +- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 0fbc6fb..90733d7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.t2code T2CodeLib - 13.4_SNAPSHOT-2 + 13.4 jar T2CodeLib 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 c8c9bfe..fdbdc60 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 @@ -208,7 +208,7 @@ public class T2CupdateAPI { public static void onUpdateCheck(Plugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) { String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; - if (!SelectLibConfig.getSeePreReleaseUpdates()) { + if (!seePreReleaseUpdates) { RepoURL = RepoURL + "&pre-release=false"; } if (!RepoURL.contains("?limit=1")) { 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 cec196e..81c2e25 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 @@ -30,10 +30,13 @@ public class Commands { "after 14 days!
The file can also be deleted manually by you via command!
Confirm the" + " upload'>upload | " + "Do not upload'>keep the file on your server"); - } else T2Csend.sender(sender, "The debug zip file is automatically uploaded to T2Code's servers
and automatically deleted " + - "after 14 days!
The file can also be deleted manually by you via command!

Confirm the upload with the command:" + - "
/t2c debug createReportLog confirmupload
Keep the file on your server and do not upload it with the command:" + - "
/t2c debug createReportLog noupload"); + } else T2Csend.sender(sender, "The debug zip file is automatically uploaded to T2Code's servers" + + "
and automatically deleted after 14 days!" + + "
The file can also be deleted manually by you via command!" + + "
Confirm the upload with the command:" + + "
/t2c debug createReportLog confirmupload" + + "
Keep the file on your server and do not upload it with the command:" + + "
/t2c debug createReportLog noupload"); break; case 3: Boolean upload = args[2].equalsIgnoreCase("confirmupload"); 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 3b20f59..d5cfc56 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 @@ -155,7 +155,6 @@ public class CreateReportLog { return; } - HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("https://debug.t2code.net/uploadFile"); @@ -175,15 +174,18 @@ public class CreateReportLog { directoryTemp.delete(); if (sender instanceof Player) { T2Csend.sender(sender, ("[prefix] A DebugLog zip has been created." + - "
[prefix] You can download it Download the debug file'>here." + - "
[prefix] Please enter the following key in the ticket: Copy to clipboard'>[key]
" + - "
[prefix]Do not share the download URL with anyone!" + - "
[prefix] Click to delete'>You can delte yor Debug-File by clicking me." + - "
[prefix] (If you do not delete the debug file, it will be deleted automatically after 14 days!)").replace("[key]", fileID) - .replace("[url]", downloadURL).replace("[prefix]",Util.getPrefix())); + "
[prefix] You can download it Download the debug file'>here." + + "
[prefix] Please enter the following key in the ticket: Copy to clipboard'>[key]" + + "
[prefix] Do not share the download URL with anyone!" + + "
Click to delete'>[prefix] You can delte yor Debug-File by clicking me." + + "
[prefix] (If you do not delete the debug file, it will be deleted automatically after 14 days!)") + .replace("[key]", fileID).replace("[url]", downloadURL).replace("[prefix]",Util.getPrefix())); } - 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].") + T2Csend.console(Util.getPrefix() + (" A DebugLog zip has been created. You can download it here: [url]" + + "
Please enter the following key in the ticket: [key]." + + "
Do not share the download URL with anyone!" + + "
(If you do not delete the debug file, it will be deleted automatically after 14 days!)" + + "
You can delte yor Debug-File with the following command: /t2code debug deleteReportLog [key].") .replace("[key]", fileID).replace("[url]", downloadURL)); ReportLogStorage.add(fileID); } diff --git a/src/main/java/net/t2code/t2codelib/Util.java b/src/main/java/net/t2code/t2codelib/Util.java index 1a2ea72..f149e52 100644 --- a/src/main/java/net/t2code/t2codelib/Util.java +++ b/src/main/java/net/t2code/t2codelib/Util.java @@ -10,7 +10,7 @@ public class Util { } public static String getPrefix() { - return "§8[§4T2Code§5Lib§8]"; + return "[T2CodeLib]"; } public static Integer getSpigotID() {