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; } }