This commit is contained in:
JaTiTV 2022-11-14 01:06:44 +01:00
parent 564288c9ab
commit a0e590a2c1
14 changed files with 319 additions and 108 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>13.4_DEV-1</version> <version>13.4_DEV-2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>T2CodeLib</name> <name>T2CodeLib</name>
@ -170,14 +170,14 @@
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20220924</version> <version>20220924</version>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime --> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId> <artifactId>httpmime</artifactId>
<version>4.3.1</version> <version>4.5.13</version>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -82,26 +82,26 @@ public class T2Ctemplate {
public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) { public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) {
String pluginVersion = plugin.getDescription().getVersion(); 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 update = !publicVersion.equalsIgnoreCase(pluginVersion);
boolean player = sender instanceof Player; boolean player = sender instanceof Player;
String stPlugin = "<dark_red>|</dark_red> <yellow>Plugin:</yellow> <gold>[pl]</gold>".replace("[pl]", plugin.getName()); String stPlugin = "<dark_red></dark_red> <yellow>Plugin:</yellow> <gold>[pl]</gold>".replace("[pl]", plugin.getName());
String stVersion = "<dark_red>|</dark_red> <yellow>Version:</yellow> <gold>[ver]</gold>".replace("[ver]", pluginVersion); String stVersion = "<dark_red></dark_red> <yellow>Version:</yellow> <gold>[ver]</gold>".replace("[ver]", pluginVersion);
String stAutor = "<dark_red>|</dark_red> <yellow>Autor(s):</yellow> <gold>[autor]</gold>".replace("[autor]", plugin.getDescription().getAuthors().toString()); String stAutor = "<dark_red></dark_red> <yellow>Autor(s):</yellow> <gold>[autor]</gold>".replace("[autor]", plugin.getDescription().getAuthors().toString());
String stNVersion = "<dark_red>|</dark_red> <yellow>Newest Version:</yellow> <gold>[nver]</gold>".replace("[nver]", publicVersion); String stNVersion = "<dark_red></dark_red> <yellow>Newest Version:</yellow> <gold>[nver]</gold>".replace("[nver]", publicVersion);
String stStable = "<dark_red>|</dark_red> <yellow>Stable version available:</yellow> [up]".replace("[up]", update ? "<dark_green>YES</dark_green>" : "<red>no</red>"); String stStable = "<dark_red></dark_red> <yellow>Stable version available:</yellow> [up]".replace("[up]", update ? "<dark_green>YES</dark_green>" : "<red>no</red>");
String stLinkPlayer = "<dark_red>|</dark_red> <yellow><hover:show_text:'<green>Go to the Spigot page</green>'><click:open_url:'[slink]'>Spigot</click></hover></yellow> " String stLinkPlayer = "<dark_red></dark_red> <yellow><hover:show_text:'<green>Go to the Spigot page</green>'><click:open_url:'[slink]'>Spigot</click></hover></yellow> "
.replace("[slink]", "https://www.spigotmc.org/resources/" + spigotID) .replace("[slink]", "https://www.spigotmc.org/resources/" + spigotID)
+ "<dark_red>-</dark_red> <dark_purple><hover:show_text:'<green>Go to the T2Code Support Discord</green>'><click:open_url:'[dlink]'>Discord</click></hover></dark_purple>" + "<dark_red>-</dark_red> <dark_purple><hover:show_text:'<green>Go to the T2Code Support Discord</green>'><click:open_url:'[dlink]'>Discord</click></hover></dark_purple>"
.replace("[dlink]", discord); .replace("[dlink]", discord);
String stLinkConsole = "<dark_red>|</dark_red> <yellow>Spigot:</yellow> <gold>https://www.spigotmc.org/resources/" + spigotID + "</gold>" String stLinkConsole = "<dark_red></dark_red> <yellow>Spigot:</yellow> <gold>https://www.spigotmc.org/resources/" + spigotID + "</gold>"
+ "<br><dark_red>|</dark_red> <yellow>Discord:</yellow> <gold>" + discord + "</gold>"; + "<br><dark_red></dark_red> <yellow>Discord:</yellow> <gold>" + discord + "</gold>";
String stLink = player ? stLinkPlayer : stLinkConsole; String stLink = player ? stLinkPlayer : stLinkConsole;
String pr = premiumVerified != null ? "<br><dark_red>|</dark_red> <yellow>Premium verified:</yellow> [pr]".replace("[pr]", premiumVerified ? "<dark_green>YES</dark_green>" : "<red>NO</red>") : ""; String pr = premiumVerified != null ? "<br><dark_red></dark_red> <yellow>Premium verified:</yellow> [pr]".replace("[pr]", premiumVerified ? "<dark_green>YES</dark_green>" : "<red>NO</red>") : "";
String stMSG = text == null || text.equals("") ? "" : "<br><dark_red>|</dark_red> " + text + "<br>"; String stMSG = text == null || text.equals("") ? "" : "<br><dark_red></dark_red> " + text + "<br>";
T2Csend.sender(sender, "<dark_red>---------------------</dark_red>" T2Csend.sender(sender, "<dark_red>╔══════════════════════════════════════</dark_red>"
+ "<br>" + stPlugin + "<br>" + stPlugin
+ stMSG + stMSG
+ stVersion + stVersion
@ -110,7 +110,7 @@ public class T2Ctemplate {
+ "<br>" + stStable + "<br>" + stStable
+ "<br>" + stLink + "<br>" + stLink
+ pr + pr
+ "<br><dark_red>---------------------</dark_red>"); + "<br><dark_red>╚══════════════════════════════════════</dark_red>");
} }
public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, String text) { public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, String text) {

View File

@ -2,7 +2,9 @@ package net.t2code.t2codelib.SPIGOT.api.update;
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.SPIGOT.system.UpdateType;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -31,7 +33,7 @@ public class T2CupdateAPI {
} }
T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData; T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData;
String pluginVersion = plugin.getDescription().getVersion(); String pluginVersion = plugin.getDescription().getVersion();
if (pluginVersion.equals(webData.getTagName())) return; if (!pluginVersions.get(plugin.getName()).updateAvailable) return;
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
@ -41,61 +43,133 @@ public class T2CupdateAPI {
} }
public static void sendUpdateMsg(String prefix, T2CupdateWebData webData, String discord, Plugin plugin, Player player) { 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(); String pluginVersion = plugin.getDescription().getVersion();
if (publicVersion.equals("§4No public version found!")) { if (!pluginVersions.get(plugin.getName()).updateAvailable) {
return; return;
} }
String st = "[prefix]<br>" + String st = "[prefix]<br>" +
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <gold>A new</gold> [value]<gold>version was found!</gold></hover></click><br>" + "<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <gold>A new</gold> [value] <gold>version was" +
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <red>[plv]</red> <gray>-></gray> <green>[puv]</green></hover></click><br>" + " found!</gold></hover></click><br>" +
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <red>[plv]</red> <gray>-></gray> " +
"<green>[puv]</green></hover></click><br>" +
"<click:open_url:'[dc]'><hover:show_text:'<yellow>[dc]</yellow>'>[prefix] <gold>You can find more information on Discord.</gold></hover></click><br>" + "<click:open_url:'[dc]'><hover:show_text:'<yellow>[dc]</yellow>'>[prefix] <gold>You can find more information on Discord.</gold></hover></click><br>" +
"[prefix] <blue><hover:show_text:'<red>Click for more information</red>'><click:run_command:'/t2c updateinfo " + plugin.getName() + "'>Update information</click></hover></blue><br>" +
"[prefix]"; "[prefix]";
String value = "";
String value;
if (webData.isPreRelease()) { if (webData.isPreRelease()) {
value = "<light_purple>Pre-Release </light_purple>"; value = UpdateType.PRERELEASE.text;
if (publicVersion.toLowerCase().contains("dev")) { if (publicVersion.toLowerCase().contains("dev")) {
value = "<dark_red>DEV </dark_red>"; value = UpdateType.DEVELOPMENT.text;
} }
if (publicVersion.toLowerCase().contains("beta")) { if (publicVersion.toLowerCase().contains("beta")) {
value = "<green>BETA </green>"; value = UpdateType.BETA.text;
} }
if (publicVersion.toLowerCase().contains("snapshot")) { if (publicVersion.toLowerCase().contains("snapshot")) {
value = "<yellow>SNAPSHOT </yellow>"; value = UpdateType.SNAPSHOT.text;
} }
} } else value = UpdateType.STABLE.text;
T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", webData.getUpdateUrl()) T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", webData.getUpdateUrl())
.replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord)); .replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord));
} }
public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin) { 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 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 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 s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion;
String s3 = "§6You can download it here: §e" + webData.getUpdateUrl(); String s3 = "§6You can download it here: §e" + webData.getUpdateUrl();
String s4 = "§6You can find more information on Discord: §e" + discord; 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 = "<br>" + h + "<br>" + s1 + "<br>" + s2 + "<br>" + s3 + "<br>" + s4 + "<br>" + h; String text = "<br>" + h + "<br>" + s1 + "<br>" + s2 + "<br>" + s3 + "<br>" + s4 + "<br>" + h;
T2Csend.console(text); 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 = "<br><dark_red>║</dark_red> <yellow>Plugin:</yellow> <color:#5eff89>" + pluginName + "</color>";
String pluginVersionString = "<br><dark_red>║</dark_red> <yellow>Your version:</yellow> <color:#5eff89>" + pluginVersion + "</color>";
String updateInfoString = "<br><dark_red>║</dark_red> <color:#308aff>[value]:</color>";
String updateTitleString = "<br><dark_red>║</dark_red> <yellow>Title:</yellow> <color:#5eff89>" + updateTitle + "</color>";
String updateVersionString = "<br><dark_red>║</dark_red> <yellow>Version:</yellow> <color:#5eff89>" + updateVersion + "</color>";
String updateAtString = "<br><dark_red>║</dark_red> <yellow>Update at:</yellow> <color:#5eff89>" + updateAt + "</color>";
String updateTypeString = "<br><dark_red>║</dark_red> <yellow>Update type:</yellow> <color:#5eff89>" + updateType + "</color>";
String updateButton;
if (player) {
// updateButton = "<br><dark_red>║</dark_red> <color:#5eff89><hover:show_text:'<gold>" + updateUpdate + "</gold>'><click:open_url:'" + updateUpdate +"'>Download</click></hover></color>";
updateButton = "<br><dark_red>║</dark_red> <color:#5eff89><hover:show_text:'<gold>" + updateUpdate + "</gold>'><click:open_url:'" + updateUpdate + "'>Download</click></hover></color> <dark_gray>|</dark_gray> <blue><hover:show_text:'" + updateDescription + "'>Update Description</hover></blue>";
} else updateButton = "<br><dark_red>║</dark_red> <color:#5eff89>Download:</color> <gold>" + updateUpdate + "</gold>";
String text;
text = "<dark_red>╔══════════════════════</dark_red>";
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 + "<br><dark_gray>This plugin does not have the new update checker yet, so there is no exact update / " +
"version information available!</dark_gray>";
text = text + "<br><dark_red>╚══════════════════════</dark_red>";
return text;
}
public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
@ -105,10 +179,10 @@ 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 false, !plugin.getDescription().getVersion().equals(update_version)
); );
pluginVersions.put(plugin.getName(), update); pluginVersions.put(plugin.getName(), update);
if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) { if (!pluginVersions.get(plugin.getName()).updateAvailable) {
if (!update.load) { if (!update.load) {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
@ -142,10 +216,11 @@ public class T2CupdateAPI {
plugin.getName(), plugin.getName(),
plugin.getDescription().getVersion(), plugin.getDescription().getVersion(),
webData, webData,
false false,
!plugin.getDescription().getVersion().equals(webData.getVersion())
); );
pluginVersions.put(plugin.getName(), update); pluginVersions.put(plugin.getName(), update);
if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTagName())) { if (!pluginVersions.get(plugin.getName()).updateAvailable) {
if (!update.load) { if (!update.load) {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override

View File

@ -62,7 +62,8 @@ public class T2CupdateChecker {
plugin.getName(), plugin.getName(),
pluginVersion, pluginVersion,
null, null,
load load,
false
); );
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

@ -8,6 +8,8 @@ import org.json.JSONObject;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.function.Consumer; import java.util.function.Consumer;
public class T2CupdateCheckerGit { public class T2CupdateCheckerGit {
@ -41,10 +43,16 @@ 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"); String body = obj.getString("body").replace("\n","<br>").replace("\r","").replace("'","''");
String updateurl = obj.getString("url"); String updateurl = obj.getString("html_url");
boolean prerelease = obj.getBoolean("prerelease"); 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"); JSONArray downloadArray = obj.getJSONArray("assets");
String downloadURL; String downloadURL;
if (downloadArray.isEmpty()) { if (downloadArray.isEmpty()) {
@ -58,7 +66,7 @@ public class T2CupdateCheckerGit {
updateurl = "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); T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, formattedDate, downloadURL, prerelease);
consumer.accept(webData); consumer.accept(webData);
} catch (Exception var10) { } catch (Exception var10) {
Boolean load = false; Boolean load = false;
@ -69,7 +77,8 @@ public class T2CupdateCheckerGit {
plugin.getName(), plugin.getName(),
pluginVersion, pluginVersion,
null, null,
load load,
false
); );
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

@ -7,14 +7,17 @@ public class T2CupdateObject {
public String pluginVersion; public String pluginVersion;
public T2CupdateWebData webData; public T2CupdateWebData webData;
public Boolean load; public Boolean load;
public Boolean updateAvailable;
public T2CupdateObject(String pluginName, public T2CupdateObject(String pluginName,
String pluginVersion, String pluginVersion,
T2CupdateWebData webData, T2CupdateWebData webData,
Boolean load) { Boolean load,
Boolean updateAvailable) {
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;
} }
} }

View File

@ -4,11 +4,11 @@ import lombok.Getter;
public class T2CupdateWebData { public class T2CupdateWebData {
@Getter @Getter
private String updateName; private String updateTitle;
@Getter @Getter
private String tagName; private String version;
@Getter @Getter
private String body; private String updateDescription;
@Getter @Getter
private String updateUrl; private String updateUrl;
@Getter @Getter
@ -18,10 +18,10 @@ public class T2CupdateWebData {
@Getter @Getter
private boolean preRelease; private boolean preRelease;
public T2CupdateWebData(String updateName, String tagName, String body, String updateUrl, String publishedAt, String downloadURL, boolean preRelease) { public T2CupdateWebData(String updateTitle, String version, String updateDescription, String updateUrl, String publishedAt, String downloadURL, boolean preRelease) {
this.updateName = updateName; this.updateTitle = updateTitle;
this.tagName = tagName; this.version = version;
this.body = body; this.updateDescription = updateDescription;
this.updateUrl = updateUrl; this.updateUrl = updateUrl;
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
this.downloadURL = downloadURL; this.downloadURL = downloadURL;

View File

@ -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.plugins.T2CpluginCheck;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import net.t2code.t2codelib.SPIGOT.system.bstats.Metrics; 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.ConfigCreate;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate; 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"); Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");
} }
ReportLogStorage.load();
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin); Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
T2Ctemplate.onLoadFooter(prefix, long_); T2Ctemplate.onLoadFooter(prefix, long_);
load = true; load = true;
@ -105,6 +108,7 @@ public final class T2CodeLibMain extends JavaPlugin {
public void onDisable() { public void onDisable() {
// Plugin shutdown logic // Plugin shutdown logic
if (!load) return; if (!load) return;
ReportLogStorage.save();
if (SelectLibConfig.getInventoriesCloseByServerStop()) { if (SelectLibConfig.getInventoriesCloseByServerStop()) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
player.closeInventory(); player.closeInventory();

View File

@ -0,0 +1,15 @@
package net.t2code.t2codelib.SPIGOT.system;
public enum UpdateType {
PRERELEASE("<light_purple>Pre-Release</light_purple>"),
DEVELOPMENT("<dark_red>DEV</dark_red>"),
BETA("<gold>BETA</gold>"),
SNAPSHOT("<yellow>SNAPSHOT</yellow>"),
STABLE("<dark_green>STABLE</dark_green>");
public String text;
UpdateType(String text) {
this.text = text;
}
}

View File

@ -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.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import net.t2code.t2codelib.SPIGOT.system.CreateReportLog; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateObject;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; 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.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class CmdExecuter implements CommandExecutor, TabCompleter { public class CmdExecuter implements CommandExecutor, TabCompleter {
@ -26,7 +24,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
return false; return false;
} }
if (args.length == 0) { if (args.length == 0) {
T2Ctemplate.sendInfo(sender, T2CodeLibMain.getPlugin(), Util.getSpigotID(), Util.getDiscord(), null, Util.getInfoText()); Commands.info(sender);
return false; return false;
} }
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
@ -35,44 +33,16 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
case "pl": case "pl":
case "version": case "version":
case "ver": 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; return false;
case "reloadconfig": case "reloadconfig":
SelectLibConfig.onSelect(); SelectLibConfig.onSelect();
return false; return false;
case "debug": case "debug":
if (args.length < 2) { Commands.debug(sender,args);
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;
}
return false; return false;
default: default:
@ -86,6 +56,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
put("debug", "t2code.admin"); put("debug", "t2code.admin");
put("info", "t2code.admin"); put("info", "t2code.admin");
put("reloadconfig", "t2code.admin"); put("reloadconfig", "t2code.admin");
put("updateinfo", "t2code.admin");
}}; }};
@Override @Override
@ -103,9 +74,32 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
if (args.length == 2 && args[0].equalsIgnoreCase("debug")) { if (args.length == 2 && args[0].equalsIgnoreCase("debug")) {
if (sender.hasPermission("t2code.admin")) { if (sender.hasPermission("t2code.admin")) {
if (hasPermission(p, arg1.get("debug")) && passend("debug", args[1])) { if (hasPermission(p, arg1.get("debug"))) {
list.add("createReportLog"); if (passend("createReportLog",args[1])) list.add("createReportLog");
list.add("deleteReportLog"); 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<String, T2CupdateObject> 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; return list;

View File

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

View File

@ -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.luckyBox.api.LuckyBoxAPI;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck; 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 net.t2code.t2codelib.Util;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -146,11 +148,14 @@ public class CreateReportLog {
String fileType = obj.getString("fileType"); String fileType = obj.getString("fileType");
Integer fileSize = obj.getInt("size"); Integer fileSize = obj.getInt("size");
zipFile.delete(); zipFile.delete();
directory.delete();
if (sender instanceof Player) { if (sender instanceof Player) {
T2Csend.sender(sender, Util.getPrefix() + "<green>A DebugLog zip has been created. You can download it <click:open_url:'url'><gold>here</gold></click>. Please enter the following key in the ticket: <gold>key</gold></green><br><dark_red>Do not share the download URL with anyone!</dark_red><br><click:run_command:'/t2code debug deleteReportLog key'><green>You can <b>delte </b>yor Debug-File by clicking me.</green></click>".replace("key",fileID).replace("url",downloadURL)); T2Csend.sender(sender, Util.getPrefix() + "<green>A DebugLog zip has been created. You can download it <click:open_url:'url'><gold>here</gold></click>. Please enter the following key in the ticket: <gold>key</gold></green><br><dark_red>Do not share the download URL with anyone!</dark_red><br><click:run_command:'/t2code debug deleteReportLog key'><green>You can <b>delte </b>yor Debug-File by clicking me.</green></click>".replace("key",fileID).replace("url",downloadURL));
System.out.println(Util.getPrefix() + "<green>A DebugLog zip has been created. You can download it <click:open_url:'url'><gold>here</gold></click>. Please enter the following key in the ticket: <gold>key</gold></green><br><dark_red>Do not share the download URL with anyone!</dark_red><br><click:run_command:'/t2code debug deleteReportLog key'><green>You can <b>delte </b>yor Debug-File by clicking me.</green></click>".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)); 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)); } 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 { 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); URL url = new URL("https://debug.t2code.net/delte/" + arg);
HttpURLConnection con = (HttpURLConnection) url.openConnection(); HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET"); con.setRequestMethod("GET");
ReportLogStorage.remove(arg);
} }
} }

View File

@ -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<String> 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");
}
}

View File

@ -16,6 +16,7 @@ public class Util {
public static Integer getSpigotID() { public static Integer getSpigotID() {
return 96388; return 96388;
} }
public static String getGit() { public static String getGit() {
return "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1"; return "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1";
} }
@ -38,7 +39,7 @@ public class Util {
"T2C-LuckyBox", "T2C-LuckyBox",
"WonderBagShop", "WonderBagShop",
"CommandGUI", "CommandGUI",
// "T2C-OPSecurity", // "T2C-OPSecurity",
"OPSecurity", "OPSecurity",
"PaPiTest", "PaPiTest",
"T2C-Alias", "T2C-Alias",