uc
This commit is contained in:
parent
8034d8852a
commit
3bdbaacd64
@ -1,5 +1,6 @@
|
||||
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;
|
||||
@ -8,17 +9,18 @@ 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));
|
||||
bukkitAudiences.sender(sender).sendMessage(replace(msg));
|
||||
}
|
||||
|
||||
public static void sendMiniMessage(String msg) {
|
||||
T2CodeLibMain.adventure().console().sendMessage(replace(msg));
|
||||
bukkitAudiences.console().sendMessage(replace(msg));
|
||||
}
|
||||
|
||||
public static void miniMessage(String msg, Player player) {
|
||||
T2CodeLibMain.adventure().player(player).sendMessage(replace(msg));
|
||||
bukkitAudiences.player(player).sendMessage(replace(msg));
|
||||
}
|
||||
|
||||
protected static Component replace(String text) {
|
||||
|
@ -82,7 +82,7 @@ public class T2Ctemplate {
|
||||
|
||||
public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) {
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getTag_name();
|
||||
String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getTagName();
|
||||
boolean update = !publicVersion.equalsIgnoreCase(pluginVersion);
|
||||
boolean player = sender instanceof Player;
|
||||
|
||||
|
@ -29,19 +29,19 @@ public class T2CupdateAPI {
|
||||
}.runTaskLaterAsynchronously(plugin, 20L);
|
||||
return;
|
||||
}
|
||||
String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name();
|
||||
T2CupdateWebData webData = pluginVersions.get(plugin.getName()).webData;
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
if (pluginVersion.equals(publicVersion)) return;
|
||||
if (pluginVersion.equals(webData.getTagName())) 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()).webData.getTag_name();
|
||||
public static void sendUpdateMsg(String prefix, T2CupdateWebData webData, String discord, Plugin plugin, Player player) {
|
||||
String publicVersion = webData.getTagName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
if (publicVersion.equals("§4No public version found!")) {
|
||||
return;
|
||||
@ -52,7 +52,9 @@ public class T2CupdateAPI {
|
||||
"<click:open_url:'[dc]'><hover:show_text:'<yellow>[dc]</yellow>'>[prefix] <gold>You can find more information on Discord.</gold></hover></click><br>" +
|
||||
"[prefix]";
|
||||
String value = "";
|
||||
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
|
||||
|
||||
if (webData.isPreRelease()) {
|
||||
value = "<light_purple>Pre-Release </light_purple>";
|
||||
if (publicVersion.toLowerCase().contains("dev")) {
|
||||
value = "<dark_red>DEV </dark_red>";
|
||||
}
|
||||
@ -63,19 +65,19 @@ public class T2CupdateAPI {
|
||||
value = "<yellow>SNAPSHOT </yellow>";
|
||||
}
|
||||
}
|
||||
T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", "https://www.spigotmc.org/resources/" + spigotID)
|
||||
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, T2CupdateWebData data, String discord, Plugin plugin) {
|
||||
String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name();
|
||||
public static void sendUpdateMsg(String prefix, String discord, T2CupdateWebData webData, Plugin plugin) {
|
||||
String publicVersion =webData.getTagName();
|
||||
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: §e" + data.getUpdateurl();
|
||||
String s3 = "§6You can download it here: §e" + webData.getUpdateUrl();
|
||||
String s4 = "§6You can find more information on Discord: §e" + discord;
|
||||
if (data.isPrerelease()) {
|
||||
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";
|
||||
@ -93,7 +95,41 @@ public class T2CupdateAPI {
|
||||
T2Csend.console(text);
|
||||
}
|
||||
|
||||
public static void onUpdateCheck(Plugin plugin, String prefix, String discord, String RepoURL) {
|
||||
public static void onUpdateCheck(Plugin plugin, String prefix, Integer spigotID, String discord) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
(new T2CupdateChecker((JavaPlugin) plugin, spigotID)).getVersion((update_version) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
new T2CupdateWebData("OLD", update_version, "", "https://www.spigotmc.org/resources/" + spigotID, "",
|
||||
"https://www.spigotmc.org/resources/" + spigotID, false),
|
||||
false
|
||||
);
|
||||
pluginVersions.put(plugin.getName(), update);
|
||||
if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
|
||||
if (!update.load) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
update.load = true;
|
||||
sendUpdateMsg(prefix, discord, update.webData, plugin);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(plugin, 600L);
|
||||
} else sendUpdateMsg(prefix, discord, update.webData, plugin);
|
||||
} else {
|
||||
if (!update.load) {
|
||||
T2Csend.console(prefix + " §2No update found.");
|
||||
update.load = true;
|
||||
}
|
||||
}
|
||||
}, prefix, plugin.getDescription().getVersion());
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L);
|
||||
}
|
||||
|
||||
public static void onUpdateCheck(Plugin plugin, String prefix, String RepoURL, Integer spigotID, String discord) {
|
||||
if (!RepoURL.contains("?limit=1")) {
|
||||
RepoURL = RepoURL + "?limit=1";
|
||||
}
|
||||
@ -101,7 +137,7 @@ public class T2CupdateAPI {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
(new T2CupdateChecker((JavaPlugin) plugin)).getVersion((webData) -> {
|
||||
(new T2CupdateCheckerGit((JavaPlugin) plugin)).getVersion((webData) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
@ -109,23 +145,23 @@ public class T2CupdateAPI {
|
||||
false
|
||||
);
|
||||
pluginVersions.put(plugin.getName(), update);
|
||||
if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTag_name())) {
|
||||
if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTagName())) {
|
||||
if (!update.load) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
update.load = true;
|
||||
sendUpdateMsg(prefix, webData, discord, plugin);
|
||||
sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(plugin, 600L);
|
||||
} else sendUpdateMsg(prefix, webData, discord, plugin);
|
||||
} else sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
} else {
|
||||
if (!update.load) {
|
||||
T2Csend.console(prefix + " §2No update found.");
|
||||
update.load = true;
|
||||
}
|
||||
}
|
||||
}, prefix, plugin.getDescription().getVersion(), finalRepoURL);
|
||||
}, plugin.getDescription().getVersion(), spigotID, finalRepoURL);
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L);
|
||||
}
|
||||
|
@ -2,63 +2,62 @@ package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class T2CupdateChecker {
|
||||
private JavaPlugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
public T2CupdateChecker(JavaPlugin plugin) {
|
||||
public T2CupdateChecker(JavaPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<T2CupdateWebData> consumer, String Prefix, String pluginVersion, String URL) {
|
||||
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) {
|
||||
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;
|
||||
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());
|
||||
}
|
||||
JSONObject obj = new JSONObject(data);
|
||||
String UpdateName = obj.getString("name");
|
||||
String tag_name = obj.getString("tag_name");
|
||||
String body = obj.getString("body");
|
||||
String updateurl = obj.getString("url");
|
||||
boolean prerelease = obj.getBoolean("prerelease");
|
||||
String published_at = obj.getString("published_at");
|
||||
JSONArray downloadArray = obj.getJSONArray("assets");
|
||||
String downloadURL;
|
||||
if (downloadArray.isEmpty()) {
|
||||
downloadURL = "";
|
||||
} else {
|
||||
downloadURL = downloadArray.getJSONObject(0).getString("browser_download_url");
|
||||
} catch (Throwable var8) {
|
||||
try {
|
||||
scanner.close();
|
||||
} catch (Throwable var7) {
|
||||
var8.addSuppressed(var7);
|
||||
}
|
||||
T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, published_at, downloadURL, prerelease);
|
||||
consumer.accept(webData);
|
||||
} catch (Exception var10) {
|
||||
throw var8;
|
||||
}
|
||||
scanner.close();
|
||||
} catch (Throwable var9) {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Throwable var6) {
|
||||
var9.addSuppressed(var6);
|
||||
}
|
||||
}
|
||||
throw var9;
|
||||
}
|
||||
inputStream.close();
|
||||
} catch (IOException var10) {
|
||||
Boolean load = false;
|
||||
if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())){
|
||||
load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load;
|
||||
}
|
||||
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
pluginVersion,
|
||||
@ -70,5 +69,4 @@ public class T2CupdateChecker {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
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.util.function.Consumer;
|
||||
|
||||
public class T2CupdateCheckerGit {
|
||||
private JavaPlugin plugin;
|
||||
|
||||
public T2CupdateCheckerGit(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String URL) {
|
||||
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");
|
||||
String updateurl = obj.getString("url");
|
||||
boolean prerelease = obj.getBoolean("prerelease");
|
||||
String published_at = obj.getString("published_at");
|
||||
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, published_at, 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
|
||||
);
|
||||
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
|
||||
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -4,28 +4,28 @@ import lombok.Getter;
|
||||
|
||||
public class T2CupdateWebData {
|
||||
@Getter
|
||||
private String UpdateName;
|
||||
private String updateName;
|
||||
@Getter
|
||||
private String tag_name;
|
||||
private String tagName;
|
||||
@Getter
|
||||
private String body;
|
||||
@Getter
|
||||
private String updateurl;
|
||||
private String updateUrl;
|
||||
@Getter
|
||||
private String published_at;
|
||||
private String publishedAt;
|
||||
@Getter
|
||||
private String downloadURL;
|
||||
@Getter
|
||||
private boolean prerelease;
|
||||
private boolean preRelease;
|
||||
|
||||
public T2CupdateWebData(String updateName, String tag_name, String body, String updateurl, String published_at, String downloadURL, boolean prerelease) {
|
||||
UpdateName = updateName;
|
||||
this.tag_name = tag_name;
|
||||
public T2CupdateWebData(String updateName, String tagName, String body, String updateUrl, String publishedAt, String downloadURL, boolean preRelease) {
|
||||
this.updateName = updateName;
|
||||
this.tagName = tagName;
|
||||
this.body = body;
|
||||
this.updateurl = updateurl;
|
||||
this.published_at = published_at;
|
||||
this.updateUrl = updateUrl;
|
||||
this.publishedAt = publishedAt;
|
||||
this.downloadURL = downloadURL;
|
||||
this.prerelease = prerelease;
|
||||
this.preRelease = preRelease;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public final class T2CodeLibMain extends JavaPlugin {
|
||||
plugin = this;
|
||||
autor = plugin.getDescription().getAuthors();
|
||||
version = plugin.getDescription().getVersion();
|
||||
this.adventure = BukkitAudiences.create(this);
|
||||
adventure = BukkitAudiences.create(this);
|
||||
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
||||
String prefix = Util.getPrefix();
|
||||
|
||||
@ -90,7 +90,7 @@ public final class T2CodeLibMain extends JavaPlugin {
|
||||
SelectLibConfig.onSelect();
|
||||
SelectLibMsg.onSelect();
|
||||
|
||||
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getDiscord(), "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1");
|
||||
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), Util.getSpigotID(), Util.getDiscord());
|
||||
Metrics.Bstats(plugin, Util.getBstatsID());
|
||||
if (SelectLibConfig.getBungee()) {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");
|
||||
@ -155,7 +155,7 @@ 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!");
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ public class Util {
|
||||
public static Integer getSpigotID() {
|
||||
return 96388;
|
||||
}
|
||||
public static String getGit() {
|
||||
return "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1";
|
||||
}
|
||||
|
||||
public static Integer getBstatsID() {
|
||||
return 12518;
|
||||
|
Loading…
Reference in New Issue
Block a user