diff --git a/pom.xml b/pom.xml
index 26bfc0a..e859268 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
net.t2code
T2CodeLib
- 13.3
+ 13.4
jar
T2CodeLib
@@ -94,7 +94,6 @@
https://nexus.bencodez.com/repository/maven-public/
org.projectlombok
@@ -169,14 +174,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/BUNGEE/api/messages/T2CBminiMessage.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBminiMessage.java
new file mode 100644
index 0000000..19398ed
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBminiMessage.java
@@ -0,0 +1,30 @@
+package net.t2code.t2codelib.BUNGEE.api.messages;
+
+
+import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import net.t2code.t2codelib.BUNGEE.system.T2CodeBMain;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
+
+public class T2CBminiMessage {
+ private static final BungeeAudiences bungeeAudiences = T2CodeBMain.getAdventure();
+
+ public static void sendSenderMiniMessage(String msg, CommandSender sender) {
+ bungeeAudiences.sender(sender).sendMessage(replace(msg));
+ }
+
+ public static void sendConsoleMiniMessage(String msg) {
+ bungeeAudiences.console().sendMessage(replace(msg));
+ }
+
+ public static void sendPlayerMiniMessage(String msg, ProxiedPlayer player) {
+ bungeeAudiences.player(player).sendMessage(replace(msg));
+ }
+
+ protected static Component replace(String text) {
+ return MiniMessage.miniMessage().deserialize(T2Creplace.convertColorCode(text));
+ }
+}
diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java
index e909438..a43c87d 100644
--- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java
+++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBsend.java
@@ -5,16 +5,21 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.Title;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
+import net.t2code.t2codelib.BUNGEE.system.T2CodeBMain;
import java.util.logging.Level;
public class T2CBsend {
public static void console(String msg) {
- ProxyServer.getInstance().getConsole().sendMessage(msg);
+ if (T2CodeBMain.getMmIsLoad()) {
+ T2CBminiMessage.sendConsoleMiniMessage(msg);
+ } else ProxyServer.getInstance().getConsole().sendMessage(msg);
}
public static void player(ProxiedPlayer player, String msg) {
- player.sendMessage(msg);
+ if (T2CodeBMain.getMmIsLoad()) {
+ T2CBminiMessage.sendPlayerMiniMessage(msg, player);
+ } else player.sendMessage(msg);
}
public static void title(ProxiedPlayer player, Title msg) {
@@ -22,7 +27,9 @@ public class T2CBsend {
}
public static void sender(CommandSender sender, String msg) {
- sender.sendMessage(msg);
+ if (T2CodeBMain.getMmIsLoad()) {
+ T2CBminiMessage.sendSenderMiniMessage(msg, sender);
+ } else sender.sendMessage(msg);
}
public static void debug(Plugin plugin, String msg) {
@@ -31,15 +38,15 @@ public class T2CBsend {
public static void debug(Plugin plugin, String msg, Integer stage) {
// if (!new File(Main.getPath(), "config.yml").exists()) return;
- if (stage == null) {
- //todo if (plugin.getConfig().getBoolean("Plugin.Debug")){
- // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg);
- // }
- return;
- }
- // todo if (plugin.getConfig().getInt("Plugin.Debug") >= stage) {
- // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg);
- // }
+ // if (stage == null) {
+ // if (plugin.getConfig().getBoolean("Plugin.Debug")) {
+ // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg);
+ // }
+ // return;
+ //}
+ //if (plugin.getConfig().getInt("Plugin.Debug") >= stage) {
+ // ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg);
+ //}
}
public static void debugmsg(Plugin plugin, String msg) {
diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java
index a599df1..09ca8dc 100644
--- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java
+++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/messages/T2CBtemplate.java
@@ -3,6 +3,7 @@ package net.t2code.t2codelib.BUNGEE.api.messages;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Plugin;
import net.t2code.t2codelib.BUNGEE.api.update.T2CBupdateAPI;
+import net.t2code.t2codelib.T2CupdateWebData;
public class T2CBtemplate {
@@ -39,14 +40,14 @@ public class T2CBtemplate {
}
public static void sendInfo(CommandSender sender, Plugin plugin, String prefix, String spigot, String discord, String autor) {
- String publicVersion = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).publicVersion;
+ T2CupdateWebData webData = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).webData;
String pluginVersion = plugin.getDescription().getVersion();
T2CBsend.sender(sender, prefix + "§4======= " + prefix + " §4=======");
T2CBsend.sender(sender, prefix + " §2Autor: §6" + autor);
- if (publicVersion.equalsIgnoreCase(pluginVersion)) {
+ if (webData.getVersion().equalsIgnoreCase(pluginVersion)) {
T2CBsend.sender(sender, prefix + " §2Version: §6" + pluginVersion);
} else {
- T2CBupdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion, sender);
+ T2CBupdateAPI.sendUpdateMsg(prefix, discord, webData, plugin, sender);
}
T2CBsend.sender(sender, prefix + " §2Spigot: §6" + spigot);
T2CBsend.sender(sender, prefix + " §2Discord: §6" + discord);
diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateAPI.java
index fccb1d8..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
@@ -1,113 +1,88 @@
package net.t2code.t2codelib.BUNGEE.api.update;
+import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend;
+import net.t2code.t2codelib.BUNGEE.system.config.T2CBlibConfig;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
+import net.t2code.t2codelib.T2CupdateObject;
+import net.t2code.t2codelib.T2CupdateWebData;
+import net.t2code.t2codelib.UpdateType;
+import org.json.JSONArray;
+import org.json.JSONObject;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
import java.net.URL;
+import java.net.URLConnection;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.HashMap;
-import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
public class T2CBupdateAPI {
- public static HashMap bungeePluginVersins = new HashMap();
+ public static HashMap bungeePluginVersins = new HashMap<>();
+
+ public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin, CommandSender sender) {
+ String publicVersion = webData.getVersion();
+ String pluginVersion = plugin.getDescription().getVersion();
+ String value;
+ if (webData.isPreRelease()) {
+ value = UpdateType.PRERELEASE.text;
+ if (publicVersion.toLowerCase().contains("dev")) {
+ value = UpdateType.DEVELOPMENT.text;
+ }
+ if (publicVersion.toLowerCase().contains("beta")) {
+ value = UpdateType.BETA.text;
+ }
+ if (publicVersion.toLowerCase().contains("snapshot")) {
+ value = UpdateType.SNAPSHOT.text;
+ }
+ } else value = UpdateType.STABLE.text;
+ String h = "
╔══════════════" + prefix + "══════════════";
+ String s1 = "
║ A new [value] version was found!".replace("[value]", value);
+ String s2 = "
║ Your version: " + pluginVersion + " - Current version: " + webData.getVersion() + "";
+ String s3 = "
║ You can download it here: " + webData.getUpdateUrl() + "";
+ String s4 = "
║ You can find more information on Discord: " + discord + "";
+ String f = "
╚══════════════" + prefix + "══════════════";
+ String text = h + s1 + s2 + s3 + s4 + f;
+ if (sender == null) {
+ T2CBsend.console(text);
+ } else T2CBsend.sender(sender, text);
- public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version) {
- T2CBsend.console("§4=========== " + Prefix + " §4===========");
- T2CBsend.console("§6A new version was found!");
- T2CBsend.console("§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version);
- T2CBsend.console("§6You can download it here: §e" + Spigot);
- T2CBsend.console("§6You can find more information on Discord: §e" + Discord);
- T2CBsend.console("§4=========== " + Prefix + " §4===========");
- }
- public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version, CommandSender sender) {
- T2CBsend.sender(sender,"§4=========== " + Prefix + " §4===========");
- T2CBsend.sender(sender,"§6A new version was found!");
- T2CBsend.sender(sender,"§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version);
- T2CBsend.sender(sender,"§6You can download it here: §e" + Spigot);
- T2CBsend.sender(sender,"§6You can find more information on Discord: §e" + Discord);
- T2CBsend.sender(sender,"§4=========== " + Prefix + " §4===========");
}
+
private static Boolean noUpdate = true;
private static String pluginVersion;
- public static void onUpdateCheckTimer(Plugin plugin, String Prefix, String Spigot, String Discord, Integer SpigotID) {
+
+ public static void onUpdateCheckTimer(Plugin plugin, String prefix, String discord, Integer spigotID, String url) {
ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() {
public void run() {
- (new T2CBupdateAPI(plugin, SpigotID)).getVersion((update_version) -> {
+ (new T2CBupdateCheckerGit(plugin, spigotID)).getVersion((webData) -> {
pluginVersion = plugin.getDescription().getVersion();
- T2CBupdateObject update = new T2CBupdateObject(
+ T2CupdateObject update = new T2CupdateObject(
plugin.getDescription().getName(),
- pluginVersion,
- update_version
+ plugin.getDescription().getVersion(),
+ webData,
+ false,
+ !plugin.getDescription().getVersion().equals(webData.getVersion()),
+ true
);
bungeePluginVersins.put(plugin.getDescription().getName(), update);
- if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(update_version)) {
- sendUpdateMsg(Prefix, Spigot, Discord, pluginVersion, update_version);
+ if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(webData.getVersion())) {
+ sendUpdateMsg(prefix, discord, webData, plugin, null);
noUpdate = true;
} else {
if (noUpdate) {
- T2CBsend.console(Prefix + " §2No update found.");
+ T2CBsend.console(prefix + " §2No update found.");
noUpdate = false;
}
}
- },Prefix, pluginVersion);
+ }, pluginVersion, spigotID, url);
}
- }, 0, 20 * 60 * 60L, TimeUnit.SECONDS);
- }
- private Plugin plugin;
- private int resourceId;
-
- public T2CBupdateAPI(Plugin plugin, int resourceId) {
- this.plugin = plugin;
- this.resourceId = resourceId;
- }
-
- public void getVersion(Consumer consumer, String Prefix, String pluginVersion) {
- ProxyServer.getInstance().getScheduler().runAsync(this.plugin, () -> {
- try {
- InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
- try {
- Scanner scanner = new Scanner(inputStream);
-
- try {
- if (scanner.hasNext()) {
- consumer.accept(scanner.next());
- }
- } catch (Throwable var8) {
- try {
- scanner.close();
- } catch (Throwable var7) {
- var8.addSuppressed(var7);
- }
- throw var8;
- }
- scanner.close();
- } catch (Throwable var9) {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (Throwable var6) {
- var9.addSuppressed(var6);
- }
- }
- throw var9;
- }
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (IOException var10) {
- T2CBupdateObject update = new T2CBupdateObject(
- plugin.getDescription().getName(),
- pluginVersion,
- "§4No public version found!"
- );
- bungeePluginVersins.put(plugin.getDescription().getName(), update);
- this.plugin.getLogger().severe(Prefix + "§4 Cannot look for updates: " + var10.getMessage());
- }
- });
+ }, 0, T2CBlibConfig.getUpdateTimer() * 60 * 20L, TimeUnit.SECONDS);
}
}
diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java
new file mode 100644
index 0000000..5e8addc
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateCheckerGit.java
@@ -0,0 +1,98 @@
+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;
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.function.Consumer;
+
+public class T2CBupdateCheckerGit {
+ private Plugin plugin;
+ private int resourceId;
+
+ public T2CBupdateCheckerGit(Plugin plugin, int resourceId) {
+ this.plugin = plugin;
+ this.resourceId = resourceId;
+ }
+
+ public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String gitKey) {
+ String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1";
+ if (!T2CBlibConfig.getSeePreReleaseUpdates()){
+ RepoURL = RepoURL + "&pre-release=false";
+ }
+ String finalRepoURL = RepoURL;
+ BungeeCord.getInstance().getScheduler().runAsync(this.plugin, () -> {
+ try {
+ URL url = new URL(finalRepoURL);
+ URLConnection yc = url.openConnection();
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ yc.getInputStream()));
+ String inputLine;
+ String data = "";
+ while ((inputLine = in.readLine()) != null)
+ data = inputLine;
+ in.close();
+ data = data.substring(1, data.length() - 1);
+ if (data.isEmpty()) {
+ consumer.accept(null);
+ return;
+ }
+ JSONObject obj = new JSONObject(data);
+ String UpdateName = obj.getString("name");
+ String tag_name = obj.getString("tag_name");
+ String body = obj.getString("body").replace("\n", "
").replace("\r", "").replace("'", "''");
+ String updateurl = obj.getString("html_url");
+ boolean prerelease = obj.getBoolean("prerelease");
+
+ String date = obj.getString("published_at");
+ SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
+ Date parsedDate = inputFormat.parse(date);
+ String formattedDate = outputFormat.format(parsedDate);
+
+ JSONArray downloadArray = obj.getJSONArray("assets");
+ String downloadURL;
+ if (downloadArray.isEmpty()) {
+ downloadURL = "https://www.spigotmc.org/resources/" + spigotID;
+ } else {
+ downloadURL = downloadArray.getJSONObject(0).getString("browser_download_url");
+ }
+
+ if (!prerelease) {
+ downloadURL = "https://www.spigotmc.org/resources/" + spigotID;
+ updateurl = "https://www.spigotmc.org/resources/" + spigotID;
+ }
+
+ T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, formattedDate, downloadURL, prerelease);
+ consumer.accept(webData);
+ } catch (Exception var10) {
+ Boolean load = false;
+ if (T2CBupdateAPI.bungeePluginVersins.containsKey(plugin.getDescription().getName())) {
+ load = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).load;
+ }
+ T2CupdateObject update = new T2CupdateObject(
+ plugin.getDescription().getName(),
+ pluginVersion,
+ null,
+ load,
+ false,
+ 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/BUNGEE/api/update/T2CBupdateObject.java b/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateObject.java
deleted file mode 100644
index 114ab3c..0000000
--- a/src/main/java/net/t2code/t2codelib/BUNGEE/api/update/T2CBupdateObject.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package net.t2code.t2codelib.BUNGEE.api.update;
-
-public class T2CBupdateObject {
- public String pluginName;
- public String pluginVersion;
- public String publicVersion;
- public T2CBupdateObject(String pluginName, String pluginVersion, String publicVersion){
- this.pluginName = pluginName;
- this.pluginVersion = pluginVersion;
- this.publicVersion = publicVersion;
- }
-}
diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java
index d3c8a7e..f3398e7 100644
--- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java
+++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CBload.java
@@ -13,7 +13,7 @@ import net.t2code.t2codelib.BUNGEE.system.pluginMessaging.opSecurity.T2CapiOpSec
import java.io.IOException;
public class T2CBload {
- public static void onLoad(Plugin plugin, String prefix, String autor, String version, String spigot, String discord, Integer spigotID, Integer bstatsID) {
+ public static void onLoad(Plugin plugin, String prefix, String autor, String version, String spigot, String discord, Integer spigotID, Integer bstatsID, String url) {
long long_ = System.currentTimeMillis();
T2CBsend.console(prefix + "§4============================= " + prefix + " §4=============================");
T2CBsend.console(prefix + " §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
@@ -33,7 +33,7 @@ public class T2CBload {
throw new RuntimeException(e);
}
- T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, spigot, discord, spigotID);
+ T2CBupdateAPI.onUpdateCheckTimer(plugin, prefix, discord, spigotID,url);
//API
plugin.getProxy().registerChannel("t2c:bcmd");
@@ -48,7 +48,7 @@ public class T2CBload {
plugin.getProxy().registerChannel("t2c:aresp");
plugin.getProxy().getPluginManager().registerListener(plugin, new T2CapiAutoResponse());
}
- if (T2CBlibConfig.getApiAutoResponse()) {
+ if (T2CBlibConfig.getApiOpSecurity()) {
plugin.getProxy().registerChannel("t2c:t2c:opsec");
plugin.getProxy().getPluginManager().registerListener(plugin, new T2CapiOpSecurity());
}
diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java
index 2379741..db5cd3e 100644
--- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java
+++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/T2CodeBMain.java
@@ -1,5 +1,7 @@
package net.t2code.t2codelib.BUNGEE.system;
+import lombok.NonNull;
+import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.plugin.Plugin;
import net.t2code.t2codelib.BUNGEE.api.messages.T2CBsend;
import net.t2code.t2codelib.Util;
@@ -16,6 +18,16 @@ public class T2CodeBMain extends Plugin {
private static String orgVersion;
private static String autor;
+ private static Boolean mmIsLoad = true;
+ private static BungeeAudiences adventure;
+
+ public static BungeeAudiences getAdventure() {
+ if(adventure == null) {
+ throw new IllegalStateException("Cannot retrieve audience provider while plugin is not enabled");
+ }
+ return adventure;
+ }
+
@Override
public void onEnable() {
@@ -23,7 +35,12 @@ public class T2CodeBMain extends Plugin {
plugin = this;
orgVersion = plugin.getDescription().getVersion();
autor = plugin.getDescription().getAuthor();
- T2CBload.onLoad(plugin, Util.getPrefix(), autor, orgVersion, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID());
+ try {
+ adventure = BungeeAudiences.create(this);
+ } catch (Exception e){
+ mmIsLoad = false;
+ }
+ T2CBload.onLoad(plugin, Util.getPrefix(), autor, orgVersion, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID(),Util.getGit());
String[] fv = orgVersion.split("_");
plugin.getDescription().setVersion(fv[0]);
version = plugin.getDescription().getVersion();
@@ -32,6 +49,12 @@ public class T2CodeBMain extends Plugin {
@Override
public void onDisable() {
// Plugin shutdown logic
+ if (mmIsLoad){
+ if(adventure != null) {
+ adventure.close();
+ adventure = null;
+ }
+ }
T2CBsend.console(Util.getPrefix() + "§4============================= " + Util.getPrefix() + " §4=============================");
T2CBsend.console(Util.getPrefix() + " §2Autor: §6" + String.valueOf(plugin.getDescription().getAuthor()).replace("[", "").replace("]", ""));
T2CBsend.console(Util.getPrefix() + " §2Version: §6" + version);
@@ -40,4 +63,7 @@ public class T2CodeBMain extends Plugin {
T2CBsend.console(Util.getPrefix() + " §4Plugin successfully disabled.");
T2CBsend.console(Util.getPrefix() + "§4============================= " + Util.getPrefix() + " §4=============================");
}
+ public static Boolean getMmIsLoad() {
+ return mmIsLoad;
+ }
}
diff --git a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java
index c5f2bbe..1ee83fd 100644
--- a/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java
+++ b/src/main/java/net/t2code/t2codelib/BUNGEE/system/config/T2CBlibConfig.java
@@ -21,6 +21,8 @@ public class T2CBlibConfig {
config.createNewFile();
}
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config);
+ T2CBconfig.set("UpdateCheck.TimerInMin", 60, configuration);
+
T2CBconfig.set("API.CommandGUI.Enable", false, configuration);
T2CBconfig.set("API.AutoResponse.Enable", false, configuration);
T2CBconfig.set("API.OPSecurity.Enable", false, configuration);
@@ -33,15 +35,28 @@ public class T2CBlibConfig {
File config = new File(T2CodeBMain.getPlugin().getDataFolder(), "config.yml");
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config);
+ updateTimer = configuration.getInt("UpdateCheck.TimerInMin");
+ seePreReleaseUpdates = configuration.getBoolean("UpdateCheck.SeePreReleaseUpdates");
+
apiCommandGUIEnable = configuration.getBoolean("API.CommandGUI.Enable");
apiAutoResponse = configuration.getBoolean("API.AutoResponse.Enable");
apiOpSecurity = configuration.getBoolean("API.OPSecurity.Enable");
}
+ private static Integer updateTimer;
+ private static Boolean seePreReleaseUpdates;
private static Boolean apiCommandGUIEnable;
private static Boolean apiAutoResponse;
private static Boolean apiOpSecurity;
+ public static Integer getUpdateTimer() {
+ return updateTimer;
+ }
+
+ public static Boolean getSeePreReleaseUpdates() {
+ return seePreReleaseUpdates;
+ }
+
public static Boolean getApiCommandGUIEnable() {
return apiCommandGUIEnable;
}
diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java
index 9971720..7dbbd17 100644
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2ChoverModule.java
@@ -18,16 +18,16 @@ public class T2ChoverModule {
t2cmodule(msg, player);
return;
}
- T2CminiMessage.miniMessage(msg, player);
+ T2CminiMessage.sendPlayerMiniMessage(msg, player);
}
public static void moduleSender(String msg, CommandSender sender) {
- T2CminiMessage.miniMessage(msg, sender);
+ T2CminiMessage.sendSenderMiniMessage(msg, sender);
}
public static void moduleConsole(String msg) {
- if (T2CodeLibMain.getNmIsLoad()) {
- T2CminiMessage.sendMiniMessage(msg);
+ if (T2CodeLibMain.getMmIsLoad()) {
+ T2CminiMessage.sendConsoleMiniMessage(msg);
return;
}
Bukkit.getConsoleSender().sendMessage(msg);
diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java
index e654ca2..12d8940 100644
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CminiMessage.java
@@ -1,24 +1,25 @@
package net.t2code.t2codelib.SPIGOT.api.messages;
+import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
-import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class T2CminiMessage {
+ private static final BukkitAudiences bukkitAudiences = T2CodeLibMain.getPlugin().getAdventure();
- public static void miniMessage(String msg, CommandSender sender) {
- T2CodeLibMain.adventure().sender(sender).sendMessage(replace(msg));
+ public static void sendSenderMiniMessage(String msg, CommandSender sender) {
+ bukkitAudiences.sender(sender).sendMessage(replace(msg));
}
- public static void sendMiniMessage(String msg) {
- T2CodeLibMain.adventure().console().sendMessage(replace(msg));
+ public static void sendConsoleMiniMessage(String msg) {
+ bukkitAudiences.console().sendMessage(replace(msg));
}
- public static void miniMessage(String msg, Player player) {
- T2CodeLibMain.adventure().player(player).sendMessage(replace(msg));
+ public static void sendPlayerMiniMessage(String msg, Player player) {
+ bukkitAudiences.player(player).sendMessage(replace(msg));
}
protected static Component replace(String text) {
diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java
index 5f9084f..17995c8 100644
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2Ctemplate.java
@@ -1,6 +1,7 @@
package net.t2code.t2codelib.SPIGOT.api.messages;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
+import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -24,31 +25,33 @@ public class T2Ctemplate {
T2Csend.console(prefix + " | | / /| | ");
T2Csend.console(prefix + " | | / /_| |____ ");
T2Csend.console(prefix + " |_| |____|\\_____|");
- T2Csend.console(prefix + " §4 §e------------------");
- T2Csend.console(prefix + " §4 §e| §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
- T2Csend.console(prefix + " §4 §e| §2Version: §6" + version);
- T2Csend.console(prefix + " §4 §e| §2Spigot: §6" + spigot);
- T2Csend.console(prefix + " §4 §e| §2Discord: §6" + discord);
+ T2Csend.console(prefix + " §4 §e╔══════════════════════════");
+ T2Csend.console(prefix + " §4 §e║ §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
+ T2Csend.console(prefix + " §4 §e║ §2Version: §6" + version);
+ T2Csend.console(prefix + " §4 §e║ §2Spigot: §6" + spigot);
+ T2Csend.console(prefix + " §4 §e║ §2Discord: §6" + discord);
if (isPremium != null) {
if (isPremium) {
- T2Csend.console(prefix + " §4 §e| §6Premium: §2true");
- } else T2Csend.console(prefix + " §4 §e| §6Premium: §4false");
+ T2Csend.console(prefix + " §4 §e║ §6Premium: §2true");
+ } else T2Csend.console(prefix + " §4 §e║ §6Premium: §4false");
if (isVerify != null) {
if (isVerify) {
- T2Csend.console(prefix + " §4 §e| §6Verify: §2true");
- } else T2Csend.console(prefix + " §4 §e| §6Verify: §4false");
- } else T2Csend.console(prefix + " §4 §e| §6Verify: §4false");
+ T2Csend.console(prefix + " §4 §e║ §6Verify: §2true");
+ } else T2Csend.console(prefix + " §4 §e║ §6Verify: §4false");
+ } else T2Csend.console(prefix + " §4 §e║ §6Verify: §4false");
}
- T2Csend.console(prefix + " §4 §e-------------------");
+ T2Csend.console(prefix + " §4 §e╚══════════════════════════");
if (version.toLowerCase().contains("dev") || version.toLowerCase().contains("snapshot") || version.toLowerCase().contains("beta")) {
T2Csend.console(prefix + " §eYou are running §4" + version + " §eof " + prefix + "§e! Some features may not be working as expected. Please report all" +
" bugs here: http://dc.t2code.net §4UpdateChecker & bStats may be disabled!");
- T2Csend.console(prefix + " §4 §e-------------------");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ onLoadSeparateStroke(prefix);
+ if (!SelectLibConfig.getT2cTestDevelopment()){
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}
@@ -82,26 +85,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()).publicVersion;
+ 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 +113,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 afb48d6..fdbdc60 100644
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java
@@ -1,8 +1,12 @@
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;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
+import net.t2code.t2codelib.T2CupdateObject;
+import net.t2code.t2codelib.T2CupdateWebData;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@@ -14,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()) {
@@ -29,69 +33,143 @@ public class T2CupdateAPI {
}.runTaskLaterAsynchronously(plugin, 20L);
return;
}
- String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
- String pluginVersion = plugin.getDescription().getVersion();
- if (pluginVersion.equals(publicVersion)) return;
+ T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData;
+ if (!pluginVersions.get(plugin.getName()).updateAvailable) return;
new BukkitRunnable() {
@Override
public void run() {
- sendUpdateMsg(prefix, spigotID, discord, plugin, player);
+ sendUpdateMsg(prefix, webData, discord, plugin, player);
}
}.runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), 200L);
}
- public static void sendUpdateMsg(String prefix, Integer spigotID, String discord, Plugin plugin, Player player) {
- String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
+ public static void sendUpdateMsg(String prefix, T2CupdateWebData webData, String discord, Plugin plugin, Player player) {
+ 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]
" +
- "[dc]'>[prefix] You can find more information on Discord.
" +
+ "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 = "";
- if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
+
+ String value;
+
+ if (webData.isPreRelease()) {
+ //todo if (!SelectLibConfig.getSeePreReleaseUpdates()) return;
+ 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;
}
- }
- T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", "https://www.spigotmc.org/resources/" + spigotID)
+ } 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, Integer spigot, String discord, Plugin plugin) {
- String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
+ public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin) {
+ String publicVersion = webData.getVersion();
String pluginVersion = plugin.getDescription().getVersion();
- String h = "§4=========== " + prefix + " §4===========";
- String s1 = "";
- String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion;
- String s3 = "§6You can download it here: §ehttps://www.spigotmc.org/resources/" + spigot;
- String s4 = "§6You can find more information on Discord: §e" + discord;
- if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
+ String value;
+ if (webData.isPreRelease()) {
+ value = UpdateType.PRERELEASE.text;
if (publicVersion.toLowerCase().contains("dev")) {
- s1 = "§6A new §4DEV§6 version was found!§r";
+ value = UpdateType.DEVELOPMENT.text;
}
if (publicVersion.toLowerCase().contains("beta")) {
- s1 = "§6A new §2BETA§6 version was found!§r";
+ value = UpdateType.BETA.text;
}
if (publicVersion.toLowerCase().contains("snapshot")) {
- s1 = "§6A new §eSNAPSHOT§6 version was found!§r";
+ value = UpdateType.SNAPSHOT.text;
}
- } else {
- s1 = "§6A new version was found!§r";
- }
- String text = "
" + h + "
" + s1 + "
" + s2 + "
" + s3 + "
" + s4 + "
" + h;
+ } else value = UpdateType.STABLE.text;
+ String h = "
╔══════════════" + prefix + "══════════════";
+ String s1 = "
║ A new [value] version was found!".replace("[value]", value);
+ String s2 = "
║ Your version: " + pluginVersion + " - Current version: " + webData.getVersion() + "";
+ String s3 = "
║ You can download it here: " + webData.getUpdateUrl() + "";
+ String s4 = "
║ You can find more information on Discord: " + discord + "";
+ String f = "
╚══════════════" + prefix + "══════════════";
+ String text = h + s1 + s2 + s3 + s4 + f;
T2Csend.console(text);
}
+ public static String updateInfo(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 = "
║ Published on: " + updateAt + "";
+ String updateTypeString = "
║ Version type: " + updateType + "";
+
+ String updateButton;
+ if (player) {
+ 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;
+ 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
@@ -100,28 +178,74 @@ public class T2CupdateAPI {
T2CupdateObject update = new T2CupdateObject(
plugin.getName(),
plugin.getDescription().getVersion(),
- update_version,
- false
+ 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),
+ true
);
pluginVersions.put(plugin.getName(), update);
- if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
+ if (pluginVersions.get(plugin.getName()).updateAvailable) {
if (!update.load) {
new BukkitRunnable() {
@Override
public void run() {
update.load = true;
- sendUpdateMsg(prefix, spigotID, discord, plugin);
+ sendUpdateMsg(prefix, discord, update.webData, plugin);
}
- }.runTaskLaterAsynchronously(plugin, 600L);
- } else sendUpdateMsg(prefix, spigotID, discord, plugin);
+ }.runTaskLaterAsynchronously(plugin, 200L);
+ } else sendUpdateMsg(prefix, discord, update.webData, plugin);
} else {
- if (!update.load){
+ if (!update.load) {
T2Csend.console(prefix + " §2No update found.");
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, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
+ String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1";
+ if (!seePreReleaseUpdates) {
+ RepoURL = RepoURL + "&pre-release=false";
+ }
+ if (!RepoURL.contains("?limit=1")) {
+ RepoURL = RepoURL + "?limit=1";
+ }
+ String finalRepoURL = RepoURL;
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ (new T2CupdateCheckerGit((JavaPlugin) plugin)).getVersion((webData) -> {
+ T2CupdateObject update = new T2CupdateObject(
+ plugin.getName(),
+ plugin.getDescription().getVersion(),
+ webData,
+ false,
+ !plugin.getDescription().getVersion().equals(webData.getVersion()),
+ updateCheckOnJoin
+ );
+ pluginVersions.put(plugin.getName(), update);
+ if (pluginVersions.get(plugin.getName()).updateAvailable) {
+ if (!update.load) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ update.load = true;
+ sendUpdateMsg(prefix, discord, webData, plugin);
+ }
+ }.runTaskLaterAsynchronously(plugin, 600L);
+ } else sendUpdateMsg(prefix, discord, webData, plugin);
+ } else {
+ if (!update.load) {
+ T2Csend.console(prefix + " §2No update found.");
+ update.load = true;
+ }
+ }
+ }, plugin.getDescription().getVersion(), spigotID, finalRepoURL, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
+ }
+ }.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 4cf9c7c..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
@@ -1,5 +1,6 @@
package net.t2code.t2codelib.SPIGOT.api.update;
+import net.t2code.t2codelib.T2CupdateObject;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@@ -18,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;
}
@@ -62,7 +63,10 @@ public class T2CupdateChecker {
plugin.getName(),
pluginVersion,
null,
- load
+ load,
+ 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
new file mode 100644
index 0000000..73ac024
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateCheckerGit.java
@@ -0,0 +1,92 @@
+package net.t2code.t2codelib.SPIGOT.api.update;
+
+import net.t2code.t2codelib.T2CupdateObject;
+import net.t2code.t2codelib.T2CupdateWebData;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.json.JSONArray;
+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 {
+ private JavaPlugin plugin;
+
+ public T2CupdateCheckerGit(JavaPlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ public void getVersion(Consumer consumer, String pluginVersion, Integer spigotID, String URL, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
+ if (!plugin.isEnabled()) {
+ return;
+ }
+ Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
+ try {
+ URL url = new URL(URL);
+ URLConnection yc = url.openConnection();
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ yc.getInputStream()));
+ String inputLine;
+ String data = "";
+ while ((inputLine = in.readLine()) != null)
+ data = inputLine;
+ in.close();
+ data = data.substring(1, data.length() - 1);
+ if (data.isEmpty()) {
+ consumer.accept(null);
+ return;
+ }
+ JSONObject obj = new JSONObject(data);
+ String UpdateName = obj.getString("name");
+ String tag_name = obj.getString("tag_name");
+ String body = obj.getString("body").replace("\n", "
").replace("\r", "").replace("'", "''").replace("**", "");
+ String updateurl = obj.getString("html_url");
+ boolean prerelease = obj.getBoolean("prerelease");
+
+ String date = obj.getString("published_at");
+ SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
+ Date parsedDate = inputFormat.parse(date);
+ String formattedDate = outputFormat.format(parsedDate);
+
+ JSONArray downloadArray = obj.getJSONArray("assets");
+ String downloadURL;
+ if (downloadArray.isEmpty()) {
+ downloadURL = "https://www.spigotmc.org/resources/" + spigotID;
+ } else {
+ downloadURL = downloadArray.getJSONObject(0).getString("browser_download_url");
+ }
+
+ if (!prerelease) {
+ downloadURL = "https://www.spigotmc.org/resources/" + spigotID;
+ updateurl = "https://www.spigotmc.org/resources/" + spigotID;
+ }
+
+ T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, formattedDate, downloadURL, prerelease);
+ consumer.accept(webData);
+ } catch (Exception var10) {
+ Boolean load = false;
+ if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())) {
+ load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load;
+ }
+ T2CupdateObject update = new T2CupdateObject(
+ plugin.getName(),
+ pluginVersion,
+ null,
+ load,
+ 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/T2CupdateObject.java b/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java
deleted file mode 100644
index 5145de9..0000000
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package net.t2code.t2codelib.SPIGOT.api.update;
-
-
-public class T2CupdateObject {
-
- public String pluginName;
- public String pluginVersion;
- public String publicVersion;
- public Boolean load;
-
- public T2CupdateObject(String pluginName,
- String pluginVersion,
- String publicVersion,
- Boolean load) {
- this.pluginName = pluginName;
- this.pluginVersion = pluginVersion;
- this.publicVersion = publicVersion;
- this.load = load;
- }
-}
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 73e0900..f2c8054 100644
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java
@@ -10,12 +10,15 @@ 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;
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
import net.t2code.t2codelib.Util;
import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@@ -30,7 +33,7 @@ public final class T2CodeLibMain extends JavaPlugin {
private static List autor;
private static String version;
- private static Boolean nmIsLoad = true;
+ private static Boolean mmIsLoad = true;
private static Boolean load = false;
@Override
@@ -39,7 +42,11 @@ public final class T2CodeLibMain extends JavaPlugin {
plugin = this;
autor = plugin.getDescription().getAuthors();
version = plugin.getDescription().getVersion();
- this.adventure = BukkitAudiences.create(this);
+ try {
+ adventure = BukkitAudiences.create(this);
+ } catch (Exception e) {
+ mmIsLoad = false;
+ }
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
String prefix = Util.getPrefix();
@@ -56,10 +63,12 @@ public final class T2CodeLibMain extends JavaPlugin {
T2Csend.warning(plugin, "The 1.20.* is a very fresh / new version. If there are any bugs in our plugins, please report them to us via our Discord: http://dc.t2code.net");
T2Csend.console(prefix);
T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ if (!SelectLibConfig.getT2cTestDevelopment()) {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}
T2Csend.console(prefix + " §3Server run on: §6" + T2CmcVersion.getMcVersion() + " / " + T2CmcVersion.getNms());
@@ -90,13 +99,16 @@ public final class T2CodeLibMain extends JavaPlugin {
SelectLibConfig.onSelect();
SelectLibMsg.onSelect();
- T2CupdateAPI.onUpdateCheck(plugin, prefix, 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()){
+ if (SelectLibConfig.getBungee()) {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");
}
+ ReportLogStorage.load();
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
+ checkIsBungee();
T2Ctemplate.onLoadFooter(prefix, long_);
load = true;
}
@@ -105,6 +117,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();
@@ -113,7 +126,7 @@ public final class T2CodeLibMain extends JavaPlugin {
Vault.vaultDisable();
T2Ctemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
- if (nmIsLoad) {
+ if (mmIsLoad) {
if (this.adventure != null) {
this.adventure.close();
this.adventure = null;
@@ -155,14 +168,27 @@ public final class T2CodeLibMain extends JavaPlugin {
private static BukkitAudiences adventure;
- public static BukkitAudiences adventure() {
+ public BukkitAudiences getAdventure() {
if (adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
return adventure;
}
- public static Boolean getNmIsLoad() {
- return nmIsLoad;
+ private static void checkIsBungee() {
+ File config = new File("spigot.yml");
+ YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
+
+ isBungee = yamlConfiguration.getBoolean("settings.bungeecord");
+ }
+
+ private static Boolean isBungee;
+
+ public static Boolean getIsBungee() {
+ return isBungee;
+ }
+
+ public static Boolean getMmIsLoad() {
+ return mmIsLoad;
}
}
diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/CmdExecuter.java
similarity index 65%
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 05672a9..32bcf3a 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,11 +1,9 @@
-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.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;
@@ -15,6 +13,7 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class CmdExecuter implements CommandExecutor, TabCompleter {
@@ -25,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()) {
@@ -34,24 +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;
- }
- if ("createreportlog".equals(args[1].toLowerCase())) {
- Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() {
- @Override
- public void run() {
- CreateReportLog.create(sender);
- }
- });
- } else T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
+ Commands.debug(sender,args);
return false;
default:
@@ -65,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
@@ -82,8 +74,31 @@ 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");
+ 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){
+ if (passend(st,args[2])) list.add(st);
+ }
}
}
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..81c2e25
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/Commands.java
@@ -0,0 +1,80 @@
+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.system.T2CodeLibMain;
+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":
+ 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) {
+ T2Csend.sender(sender, "§4Use: §7/t2code debug deleteReportLog [id]");
+ return;
+ }
+ try {
+ CreateReportLog.delete(args[2], sender);
+ } 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(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 61%
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 a95359b..d5cfc56 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,45 +1,66 @@
-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;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.mime.MultipartEntity;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
+import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
+import org.json.JSONObject;
import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
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) {
+ 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());
File directory = new File(T2CodeLibMain.getPath() + "/DebugLogs");
+ File directoryTemp = new File("T2CDebugLogsTemp");
if (!directory.exists()) {
directory.mkdir();
}
+ if (!directoryTemp.exists()) {
+ directoryTemp.mkdir();
+ }
- File file = new File(T2CodeLibMain.getPath(), "/DebugLogs/T2CodeLog.txt");
+ File file = new File("T2CDebugLogsTemp/T2CodeLog.txt");
PrintWriter pWriter = null;
try {
pWriter = new PrintWriter(new FileWriter(file.getPath()));
String timeStamp = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy").format(Calendar.getInstance().getTime());
- pWriter.println("Created on: " + timeStamp);
+ pWriter.println("Created on: " + timeStamp + " - from: " + sender.getName());
pWriter.println();
pWriter.println("Server Bukkit version: " + T2CmcVersion.getBukkitVersion());
pWriter.println("Server run on: " + T2CmcVersion.getMcVersion());
pWriter.println("Server NMS: " + T2CmcVersion.getNms());
- pWriter.println();
pWriter.println("Online Mode: " + Bukkit.getOnlineMode());
+ pWriter.println("Bungee Mode: " + T2CodeLibMain.getIsBungee());
+ pWriter.println("Server Port: " + Bukkit.getServer().getPort());
+ pWriter.println();
pWriter.println("Worlds: " + Bukkit.getWorlds());
pWriter.println("OP-Player:");
for (OfflinePlayer player : Bukkit.getOperators()) {
@@ -80,7 +101,6 @@ public class CreateReportLog {
pWriter.println("T2C-LuckyBox isV: " + LuckyBoxAPI.isV());
pWriter.println();
}
- pWriter.println();
pWriter.println("OfflinePlayers: ");
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
pWriter.println(" - " + player.getName() + " - " + player.getUniqueId());
@@ -89,8 +109,9 @@ public class CreateReportLog {
pWriter.println("Plugins amount: " + Bukkit.getPluginManager().getPlugins().length);
pWriter.println("Plugins: ");
for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
- pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + pl.getDescription()
- .getAuthors() + " - Website: " + pl.getDescription().getWebsite());
+ pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: "
+ + pl.getDescription().getAuthors() + " - SoftDepend: " + pl.getDescription().getSoftDepend() + " - Depend: " + pl.getDescription().getDepend()
+ + " LoadBefore: " + pl.getDescription().getLoadBefore() + " - Website: " + pl.getDescription().getWebsite());
}
} catch (IOException ioe) {
ioe.printStackTrace();
@@ -101,9 +122,9 @@ public class CreateReportLog {
}
}
- String filePath = T2CodeLibMain.getPath() + "/DebugLogs/T2CodeLog.txt";
+ String filePath = "T2CDebugLogsTemp/T2CodeLog.txt";
String log = "logs/latest.log";
- String zipPath = "plugins/T2CodeLib/DebugLogs/T2CLog-" + timeStampFile + ".zip";
+ String zipPath = "T2CDebugLogsTemp/T2CLog-" + timeStampFile + ".zip";
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipPath))) {
File fileToZip = new File(filePath);
zip.putNextEntry(new ZipEntry(fileToZip.getName()));
@@ -120,11 +141,53 @@ public class CreateReportLog {
e.printStackTrace();
}
file.delete();
- if (sender instanceof Player) {
- T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
- T2Csend.console(Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
- } else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
+ 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");
+
+ FileBody bin = new FileBody(zipFile);
+ MultipartEntity reqEntity = new MultipartEntity();
+ reqEntity.addPart("file", bin);
+ httppost.setEntity(reqEntity);
+ HttpResponse response = httpclient.execute(httppost);
+ HttpEntity resEntity = response.getEntity();
+ String responseString = EntityUtils.toString(resEntity, "UTF-8");
+ JSONObject obj = new JSONObject(responseString);
+ String downloadURL = obj.getString("fileDownloadUri");
+ String fileID = obj.getString("fileID");
+ String fileType = obj.getString("fileType");
+ Integer fileSize = obj.getInt("size");
+ zipFile.delete();
+ directoryTemp.delete();
+ if (sender instanceof Player) {
+ T2Csend.sender(sender, ("[prefix] A DebugLog zip has been created." +
+ "
[prefix] You can download it Download the debug file'>here." +
+ "
[prefix] Please enter the following key in the ticket: Copy to clipboard'>[key]" +
+ "
[prefix] Do not share the download URL with anyone!" +
+ "
Click to delete'>[prefix] You can delte yor Debug-File by clicking me." +
+ "
[prefix] (If you do not delete the debug file, it will be deleted automatically after 14 days!)")
+ .replace("[key]", fileID).replace("[url]", downloadURL).replace("[prefix]",Util.getPrefix()));
+ }
+ T2Csend.console(Util.getPrefix() + (" A DebugLog zip has been created. You can download it here: [url]" +
+ "
Please enter the following key in the ticket: [key]." +
+ "
Do not share the download URL with anyone!" +
+ "
(If you do not delete the debug file, it will be deleted automatically after 14 days!)" +
+ "
You can delte yor Debug-File with the following command: /t2code debug deleteReportLog [key].")
+ .replace("[key]", fileID).replace("[url]", downloadURL));
+ ReportLogStorage.add(fileID);
}
private static void pluginToDebug(String pluginName, ZipOutputStream zip) throws IOException {
@@ -190,4 +253,18 @@ public class CreateReportLog {
}
}
}
+
+ public static void delete(String arg, CommandSender sender) throws IOException {
+ URL url = new URL("https://debug.t2code.net/delete/" + arg);
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.setRequestMethod("GET");
+ int response = con.getResponseCode();
+ if (response == 200) {
+ ReportLogStorage.remove(arg);
+ T2Csend.sender(sender, "Deleted report: " + arg);
+ } else {
+ T2Csend.sender(sender, "Error while deleting report: " + arg);
+ }
+ con.disconnect();
+ }
}
diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java
new file mode 100644
index 0000000..55df04a
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/cmd/ReportLogStorage.java
@@ -0,0 +1,42 @@
+package net.t2code.t2codelib.SPIGOT.system.cmd;
+
+import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ReportLogStorage {
+ public static List list = new ArrayList<>();
+
+ protected static File config = new File(T2CodeLibMain.getPath(), "/DebugLogs/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 == null) 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/SPIGOT/system/config/config/ConfigCreate.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java
index 6cb30b2..4b20482 100644
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/ConfigCreate.java
@@ -24,6 +24,7 @@ public class ConfigCreate {
T2Cconfig.set("Plugin.UpdateCheck.OnJoin", true, yamlConfiguration);
T2Cconfig.set("Plugin.UpdateCheck.TimeInterval", 60, yamlConfiguration);
+ T2Cconfig.set("Plugin.UpdateCheck.SeePreReleaseUpdates", true, yamlConfiguration);
T2Cconfig.set("Plugin.language", "english", yamlConfiguration);
T2Cconfig.set("BungeeCord.Enable", false, yamlConfiguration);
diff --git a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java
index f1bb07b..5ac9f9a 100644
--- a/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java
+++ b/src/main/java/net/t2code/t2codelib/SPIGOT/system/config/config/SelectLibConfig.java
@@ -7,29 +7,34 @@ import java.io.File;
public class SelectLibConfig {
- private static Boolean UpdateCheckOnJoin;
- private static Boolean t2cTestDevelopment;
- private static Integer UpdateCheckTimeInterval;
- private static Boolean Debug;
+ private static Boolean updateCheckOnJoin;
+ private static Boolean t2cTestDevelopment = false;
+ private static Integer updateCheckTimeInterval;
+ private static Boolean seePreReleaseUpdates;
+ private static Boolean debug;
private static String language;
private static Boolean bungee;
- private static Boolean InventoriesCloseByServerStop;
+ private static Boolean inventoriesCloseByServerStop;
public static void onSelect() {
File config = new File(T2CodeLibMain.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
- UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin");
- t2cTestDevelopment = yamlConfiguration.getBoolean("t2cTestDevelopment");
- UpdateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval");
- Debug = yamlConfiguration.getBoolean("Plugin.Debug");
+ if (yamlConfiguration.contains("t2cTestDevelopment")){
+ t2cTestDevelopment = yamlConfiguration.getBoolean("t2cTestDevelopment");
+ }
+
+ updateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin");
+ updateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval");
+ seePreReleaseUpdates = yamlConfiguration.getBoolean("Plugin.UpdateCheck.SeePreReleaseUpdates");
+ debug = yamlConfiguration.getBoolean("Plugin.Debug");
language = yamlConfiguration.getString("Plugin.language");
bungee = yamlConfiguration.getBoolean("BungeeCord.Enable");
- InventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop");
+ inventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop");
}
public static Boolean getUpdateCheckOnJoin() {
- return UpdateCheckOnJoin;
+ return updateCheckOnJoin;
}
public static Boolean getT2cTestDevelopment() {
@@ -37,11 +42,15 @@ public class SelectLibConfig {
}
public static Integer getUpdateCheckTimeInterval() {
- return UpdateCheckTimeInterval;
+ return updateCheckTimeInterval;
+ }
+
+ public static Boolean getSeePreReleaseUpdates() {
+ return seePreReleaseUpdates;
}
public static Boolean getDebug() {
- return Debug;
+ return debug;
}
public static String getLanguage() {
@@ -53,7 +62,7 @@ public class SelectLibConfig {
}
public static Boolean getInventoriesCloseByServerStop() {
- return InventoriesCloseByServerStop;
+ return inventoriesCloseByServerStop;
}
}
diff --git a/src/main/java/net/t2code/t2codelib/T2CupdateObject.java b/src/main/java/net/t2code/t2codelib/T2CupdateObject.java
new file mode 100644
index 0000000..d70e3b4
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/T2CupdateObject.java
@@ -0,0 +1,26 @@
+package net.t2code.t2codelib;
+
+
+public class T2CupdateObject {
+
+ public String pluginName;
+ public String pluginVersion;
+ 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 updateCheckOnJoin) {
+ this.pluginName = pluginName;
+ this.pluginVersion = pluginVersion;
+ this.webData = webData;
+ this.load = load;
+ this.updateAvailable = updateAvailable;
+ this.updateCheckOnJoin = updateCheckOnJoin;
+ }
+}
diff --git a/src/main/java/net/t2code/t2codelib/T2CupdateWebData.java b/src/main/java/net/t2code/t2codelib/T2CupdateWebData.java
new file mode 100644
index 0000000..f523d81
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/T2CupdateWebData.java
@@ -0,0 +1,31 @@
+package net.t2code.t2codelib;
+
+import lombok.Getter;
+
+public class T2CupdateWebData {
+ @Getter
+ private String updateTitle;
+ @Getter
+ private String version;
+ @Getter
+ private String updateDescription;
+ @Getter
+ private String updateUrl;
+ @Getter
+ private String publishedAt;
+ @Getter
+ private String downloadURL;
+ @Getter
+ private boolean preRelease;
+
+ 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;
+ this.preRelease = preRelease;
+ }
+}
+
diff --git a/src/main/java/net/t2code/t2codelib/UpdateType.java b/src/main/java/net/t2code/t2codelib/UpdateType.java
new file mode 100644
index 0000000..b7b897e
--- /dev/null
+++ b/src/main/java/net/t2code/t2codelib/UpdateType.java
@@ -0,0 +1,15 @@
+package net.t2code.t2codelib;
+
+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/Util.java b/src/main/java/net/t2code/t2codelib/Util.java
index 72b0d99..f149e52 100644
--- a/src/main/java/net/t2code/t2codelib/Util.java
+++ b/src/main/java/net/t2code/t2codelib/Util.java
@@ -10,13 +10,17 @@ public class Util {
}
public static String getPrefix() {
- return "§8[§4T2Code§5Lib§8]";
+ return "[T2CodeLib]";
}
public static Integer getSpigotID() {
return 96388;
}
+ public static String getGit() {
+ return "JaTiTV/T2CodeLib";
+ }
+
public static Integer getBstatsID() {
return 12518;
}
@@ -31,11 +35,11 @@ public class Util {
public static List getT2cPlugins() {
return Arrays.asList(
- //"T2CodeLib",
+ "T2CodeLib",
"T2C-LuckyBox",
"WonderBagShop",
"CommandGUI",
- "T2C-OPSecurity",
+ // "T2C-OPSecurity",
"OPSecurity",
"PaPiTest",
"T2C-Alias",