From a0e590a2c1c908c0d725866cb0c2698eb8c04577 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Mon, 14 Nov 2022 01:06:44 +0100 Subject: [PATCH] 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",