13.4_SNAPSHOT-2

This commit is contained in:
JaTiTV 2022-11-15 00:36:25 +01:00
parent 8114035cd9
commit d27ef185e6
9 changed files with 88 additions and 33 deletions

View File

@ -31,7 +31,6 @@ public class T2CBupdateAPI {
String pluginVersion = plugin.getDescription().getVersion(); String pluginVersion = plugin.getDescription().getVersion();
String value; String value;
if (webData.isPreRelease()) { if (webData.isPreRelease()) {
if (!T2CBlibConfig.getSeePreReleaseUpdates()) return;
value = UpdateType.PRERELEASE.text; value = UpdateType.PRERELEASE.text;
if (publicVersion.toLowerCase().contains("dev")) { if (publicVersion.toLowerCase().contains("dev")) {
value = UpdateType.DEVELOPMENT.text; value = UpdateType.DEVELOPMENT.text;
@ -69,7 +68,8 @@ public class T2CBupdateAPI {
plugin.getDescription().getVersion(), plugin.getDescription().getVersion(),
webData, webData,
false, false,
!plugin.getDescription().getVersion().equals(webData.getVersion()) !plugin.getDescription().getVersion().equals(webData.getVersion()),
true
); );
bungeePluginVersins.put(plugin.getDescription().getName(), update); bungeePluginVersins.put(plugin.getDescription().getName(), update);
if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(webData.getVersion())) { if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(webData.getVersion())) {

View File

@ -2,6 +2,8 @@ package net.t2code.t2codelib.BUNGEE.api.update;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.plugin.Plugin; 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.T2CupdateObject;
import net.t2code.t2codelib.T2CupdateWebData; import net.t2code.t2codelib.T2CupdateWebData;
import org.json.JSONArray; import org.json.JSONArray;
@ -26,9 +28,13 @@ public class T2CBupdateCheckerGit {
public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String gitKey) { public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String gitKey) {
String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1"; 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, () -> { BungeeCord.getInstance().getScheduler().runAsync(this.plugin, () -> {
try { try {
URL url = new URL(RepoURL); URL url = new URL(finalRepoURL);
URLConnection yc = url.openConnection(); URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader( BufferedReader in = new BufferedReader(
new InputStreamReader( new InputStreamReader(
@ -81,7 +87,8 @@ public class T2CBupdateCheckerGit {
pluginVersion, pluginVersion,
null, null,
load, load,
false false,
true
); );
T2CBupdateAPI.bungeePluginVersins.put(plugin.getDescription().getName(), update); T2CBupdateAPI.bungeePluginVersins.put(plugin.getDescription().getName(), update);
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage()); this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());

View File

@ -1,5 +1,6 @@
package net.t2code.t2codelib.SPIGOT.api.update; 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.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain; import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
import net.t2code.t2codelib.UpdateType; import net.t2code.t2codelib.UpdateType;
@ -17,7 +18,7 @@ public class T2CupdateAPI {
public static HashMap<String, T2CupdateObject> pluginVersions = new HashMap<>(); public static HashMap<String, T2CupdateObject> pluginVersions = new HashMap<>();
public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) { 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; return;
} }
if (!player.hasPermission(perm) && !player.isOp()) { if (!player.hasPermission(perm) && !player.isOp()) {
@ -33,7 +34,6 @@ public class T2CupdateAPI {
return; return;
} }
T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData; T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData;
String pluginVersion = plugin.getDescription().getVersion();
if (!pluginVersions.get(plugin.getName()).updateAvailable) return; if (!pluginVersions.get(plugin.getName()).updateAvailable) return;
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
@ -61,7 +61,7 @@ public class T2CupdateAPI {
String value; String value;
if (webData.isPreRelease()) { if (webData.isPreRelease()) {
if (!SelectLibConfig.getSeePreReleaseUpdates()) return; //todo if (!SelectLibConfig.getSeePreReleaseUpdates()) return;
value = UpdateType.PRERELEASE.text; value = UpdateType.PRERELEASE.text;
if (publicVersion.toLowerCase().contains("dev")) { if (publicVersion.toLowerCase().contains("dev")) {
value = UpdateType.DEVELOPMENT.text; value = UpdateType.DEVELOPMENT.text;
@ -180,7 +180,9 @@ public class T2CupdateAPI {
plugin.getDescription().getVersion(), plugin.getDescription().getVersion(),
new T2CupdateWebData("OLD", update_version, "", "https://www.spigotmc.org/resources/" + spigotID, "", new T2CupdateWebData("OLD", update_version, "", "https://www.spigotmc.org/resources/" + spigotID, "",
"https://www.spigotmc.org/resources/" + spigotID, false), "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); pluginVersions.put(plugin.getName(), update);
if (pluginVersions.get(plugin.getName()).updateAvailable) { if (pluginVersions.get(plugin.getName()).updateAvailable) {
@ -199,13 +201,16 @@ public class T2CupdateAPI {
update.load = true; update.load = true;
} }
} }
}, prefix, plugin.getDescription().getVersion()); }, prefix, plugin.getDescription().getVersion(),true,true,60);
} }
}.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L); }.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"; 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")) { if (!RepoURL.contains("?limit=1")) {
RepoURL = RepoURL + "?limit=1"; RepoURL = RepoURL + "?limit=1";
} }
@ -219,7 +224,8 @@ public class T2CupdateAPI {
plugin.getDescription().getVersion(), plugin.getDescription().getVersion(),
webData, webData,
false, false,
!plugin.getDescription().getVersion().equals(webData.getVersion()) !plugin.getDescription().getVersion().equals(webData.getVersion()),
updateCheckOnJoin
); );
pluginVersions.put(plugin.getName(), update); pluginVersions.put(plugin.getName(), update);
if (pluginVersions.get(plugin.getName()).updateAvailable) { if (pluginVersions.get(plugin.getName()).updateAvailable) {
@ -238,8 +244,8 @@ public class T2CupdateAPI {
update.load = true; 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);
} }
} }

View File

@ -19,7 +19,7 @@ public class T2CupdateChecker {
this.resourceId = resourceId; this.resourceId = resourceId;
} }
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) { public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
if (!plugin.isEnabled()) { if (!plugin.isEnabled()) {
return; return;
} }
@ -64,7 +64,9 @@ public class T2CupdateChecker {
pluginVersion, pluginVersion,
null, null,
load, load,
false false,
updateCheckOnJoin
); );
T2CupdateAPI.pluginVersions.put(plugin.getName(), update); T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage()); this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());

View File

@ -21,7 +21,7 @@ public class T2CupdateCheckerGit {
this.plugin = plugin; this.plugin = plugin;
} }
public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String URL) { public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String URL, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
if (!plugin.isEnabled()) { if (!plugin.isEnabled()) {
return; return;
} }
@ -45,7 +45,7 @@ public class T2CupdateCheckerGit {
JSONObject obj = new JSONObject(data); JSONObject obj = new JSONObject(data);
String UpdateName = obj.getString("name"); String UpdateName = obj.getString("name");
String tag_name = obj.getString("tag_name"); String tag_name = obj.getString("tag_name");
String body = obj.getString("body").replace("\n","<br>").replace("\r","").replace("'","''").replace("**",""); String body = obj.getString("body").replace("\n", "<br>").replace("\r", "").replace("'", "''").replace("**", "");
String updateurl = obj.getString("html_url"); String updateurl = obj.getString("html_url");
boolean prerelease = obj.getBoolean("prerelease"); boolean prerelease = obj.getBoolean("prerelease");
@ -80,7 +80,8 @@ public class T2CupdateCheckerGit {
pluginVersion, pluginVersion,
null, null,
load, load,
false false,
updateCheckOnJoin
); );
T2CupdateAPI.pluginVersions.put(plugin.getName(), update); T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage()); this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());

View File

@ -99,7 +99,8 @@ public final class T2CodeLibMain extends JavaPlugin {
SelectLibConfig.onSelect(); SelectLibConfig.onSelect();
SelectLibMsg.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()); Metrics.Bstats(plugin, Util.getBstatsID());
if (SelectLibConfig.getBungee()) { if (SelectLibConfig.getBungee()) {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd"); Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");

View File

@ -23,17 +23,36 @@ public class Commands {
} }
switch (args[1].toLowerCase()) { switch (args[1].toLowerCase()) {
case "createreportlog": case "createreportlog":
Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() { switch (args.length){
@Override case 2:
public void run() { if (sender instanceof Player) {
try { T2Csend.sender(sender, "<dark_red>The debug zip file is <red>automatically uploaded</red> to T2Code's servers<br>and <red>automatically deleted</red> " +
CreateReportLog.create(sender); "after <red>14</red> days!<br>The file can also be deleted manually by you via command!</dark_red><br><dark_green><hover:show_text:'<yellow>Confirm the" +
} catch (IOException e) { " upload</yellow>'><click:run_command:'/t2c debug createReportLog confirmupload'>upload</click></hover></dark_green> <dark_gray>|</dark_gray> " +
T2Csend.sender(sender, Util.getPrefix() + " <red>An error occurred while creating a report log! Please look in the console!</red>"); "<gold><hover:show_text:'<red>Do not upload</red>'><click:run_command:'/t2c debug createReportLog noupload'>keep the file on your server</click></hover></gold>");
throw new RuntimeException(e); } else T2Csend.sender(sender, "<dark_red>The debug zip file is <red>automatically uploaded</red> to T2Code's servers<br>and <red>automatically deleted</red> " +
} "after <red>14</red> days!<br>The file can also be deleted manually by you via command!</dark_red><br><green>Confirm the upload with the command:" +
} "</green><br><yellow>/t2c debug createReportLog confirmupload</yellow><br><red>Keep the file on your server and do not upload it with the command:" +
}); "</red><br><yellow>/t2c debug createReportLog noupload</yellow>");
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() + " <red>An error occurred while creating a report log! Please look in the console!</red>");
throw new RuntimeException(e);
}
}
});
break;
default:
T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
return;
}
break; break;
case "deletereportlog": case "deletereportlog":
if (args.length != 3) { if (args.length != 3) {

View File

@ -27,13 +27,14 @@ import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
public class CreateReportLog { 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..."); T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog is created...");
String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime()); String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime());
@ -140,9 +141,24 @@ public class CreateReportLog {
e.printStackTrace(); e.printStackTrace();
} }
file.delete(); 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(); HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://debug.t2code.net/uploadFile"); HttpPost httppost = new HttpPost("https://debug.t2code.net/uploadFile");
File zipFile = new File(zipPath);
FileBody bin = new FileBody(zipFile); FileBody bin = new FileBody(zipFile);
MultipartEntity reqEntity = new MultipartEntity(); MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("file", bin); reqEntity.addPart("file", bin);

View File

@ -8,16 +8,19 @@ public class T2CupdateObject {
public T2CupdateWebData webData; public T2CupdateWebData webData;
public Boolean load; public Boolean load;
public Boolean updateAvailable; public Boolean updateAvailable;
public Boolean updateCheckOnJoin;
public T2CupdateObject(String pluginName, public T2CupdateObject(String pluginName,
String pluginVersion, String pluginVersion,
T2CupdateWebData webData, T2CupdateWebData webData,
Boolean load, Boolean load,
Boolean updateAvailable) { Boolean updateAvailable,
Boolean updateCheckOnJoin) {
this.pluginName = pluginName; this.pluginName = pluginName;
this.pluginVersion = pluginVersion; this.pluginVersion = pluginVersion;
this.webData = webData; this.webData = webData;
this.load = load; this.load = load;
this.updateAvailable = updateAvailable; this.updateAvailable = updateAvailable;
this.updateCheckOnJoin = updateCheckOnJoin;
} }
} }