New Updater
This commit is contained in:
parent
14c520722a
commit
8034d8852a
13
pom.xml
13
pom.xml
@ -147,5 +147,18 @@
|
|||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
<version>4.1.2</version>
|
<version>4.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.json/json -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20220924</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -82,7 +82,7 @@ public class T2Ctemplate {
|
|||||||
|
|
||||||
public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) {
|
public static void sendInfo(CommandSender sender, Plugin plugin, int spigotID, String discord, Boolean premiumVerified, String text) {
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).publicVersion;
|
String publicVersion = T2CupdateAPI.pluginVersions.get(plugin.getName()).webData.getTag_name();
|
||||||
boolean update = !publicVersion.equalsIgnoreCase(pluginVersion);
|
boolean update = !publicVersion.equalsIgnoreCase(pluginVersion);
|
||||||
boolean player = sender instanceof Player;
|
boolean player = sender instanceof Player;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class T2CupdateAPI {
|
|||||||
}.runTaskLaterAsynchronously(plugin, 20L);
|
}.runTaskLaterAsynchronously(plugin, 20L);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
|
String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name();
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
if (pluginVersion.equals(publicVersion)) return;
|
if (pluginVersion.equals(publicVersion)) return;
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@ -41,7 +41,7 @@ public class T2CupdateAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendUpdateMsg(String prefix, Integer spigotID, String discord, Plugin plugin, Player player) {
|
public static void sendUpdateMsg(String prefix, Integer spigotID, String discord, Plugin plugin, Player player) {
|
||||||
String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
|
String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name();
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
if (publicVersion.equals("§4No public version found!")) {
|
if (publicVersion.equals("§4No public version found!")) {
|
||||||
return;
|
return;
|
||||||
@ -67,15 +67,16 @@ public class T2CupdateAPI {
|
|||||||
.replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord));
|
.replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendUpdateMsg(String prefix, Integer spigot, String discord, Plugin plugin) {
|
public static void sendUpdateMsg(String prefix, T2CupdateWebData data, String discord, Plugin plugin) {
|
||||||
String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
|
String publicVersion = pluginVersions.get(plugin.getName()).webData.getTag_name();
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
String h = "§4=========== " + prefix + " §4===========";
|
String h = "§4=========== " + prefix + " §4===========";
|
||||||
String s1 = "";
|
String s1 = "";
|
||||||
String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion;
|
String s2 = "§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion;
|
||||||
String s3 = "§6You can download it here: §ehttps://www.spigotmc.org/resources/" + spigot;
|
String s3 = "§6You can download it here: §e" + data.getUpdateurl();
|
||||||
String s4 = "§6You can find more information on Discord: §e" + discord;
|
String s4 = "§6You can find more information on Discord: §e" + discord;
|
||||||
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
|
if (data.isPrerelease()) {
|
||||||
|
s1 = "§6A new §4Pre-Release§6 version was found!§r";
|
||||||
if (publicVersion.toLowerCase().contains("dev")) {
|
if (publicVersion.toLowerCase().contains("dev")) {
|
||||||
s1 = "§6A new §4DEV§6 version was found!§r";
|
s1 = "§6A new §4DEV§6 version was found!§r";
|
||||||
}
|
}
|
||||||
@ -92,35 +93,39 @@ public class T2CupdateAPI {
|
|||||||
T2Csend.console(text);
|
T2Csend.console(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) {
|
public static void onUpdateCheck(Plugin plugin, String prefix, String discord, String RepoURL) {
|
||||||
|
if(!RepoURL.contains("?limit=1")){
|
||||||
|
RepoURL = RepoURL + "?limit=1";
|
||||||
|
}
|
||||||
|
String finalRepoURL = RepoURL;
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
(new T2CupdateChecker((JavaPlugin) plugin, spigotID)).getVersion((update_version) -> {
|
(new T2CupdateChecker((JavaPlugin) plugin)).getVersion((webData) -> {
|
||||||
T2CupdateObject update = new T2CupdateObject(
|
T2CupdateObject update = new T2CupdateObject(
|
||||||
plugin.getName(),
|
plugin.getName(),
|
||||||
plugin.getDescription().getVersion(),
|
plugin.getDescription().getVersion(),
|
||||||
update_version,
|
webData,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
pluginVersions.put(plugin.getName(), update);
|
pluginVersions.put(plugin.getName(), update);
|
||||||
if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
|
if (!plugin.getDescription().getVersion().equalsIgnoreCase(webData.getTag_name())) {
|
||||||
if (!update.load) {
|
if (!update.load) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
update.load = true;
|
update.load = true;
|
||||||
sendUpdateMsg(prefix, spigotID, discord, plugin);
|
sendUpdateMsg(prefix, webData, discord, plugin);
|
||||||
}
|
}
|
||||||
}.runTaskLaterAsynchronously(plugin, 600L);
|
}.runTaskLaterAsynchronously(plugin, 600L);
|
||||||
} else sendUpdateMsg(prefix, spigotID, discord, plugin);
|
} else sendUpdateMsg(prefix, webData, discord, plugin);
|
||||||
} else {
|
} else {
|
||||||
if (!update.load){
|
if (!update.load){
|
||||||
T2Csend.console(prefix + " §2No update found.");
|
T2Csend.console(prefix + " §2No update found.");
|
||||||
update.load = true;
|
update.load = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, prefix, plugin.getDescription().getVersion());
|
}, prefix, plugin.getDescription().getVersion(), finalRepoURL);
|
||||||
}
|
}
|
||||||
}.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L);
|
}.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L);
|
||||||
}
|
}
|
||||||
|
@ -2,62 +2,63 @@ package net.t2code.t2codelib.SPIGOT.api.update;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Scanner;
|
import java.net.URLConnection;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class T2CupdateChecker {
|
public class T2CupdateChecker {
|
||||||
private JavaPlugin plugin;
|
private JavaPlugin plugin;
|
||||||
private int resourceId;
|
|
||||||
|
|
||||||
public T2CupdateChecker(JavaPlugin plugin, int resourceId) {
|
public T2CupdateChecker(JavaPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.resourceId = resourceId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) {
|
public void getVersion(Consumer<T2CupdateWebData> consumer, String Prefix, String pluginVersion, String URL) {
|
||||||
if (!plugin.isEnabled()) {
|
if (!plugin.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
try {
|
try {
|
||||||
InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
|
URL url = new URL(URL);
|
||||||
try {
|
URLConnection yc = url.openConnection();
|
||||||
Scanner scanner = new Scanner(inputStream);
|
BufferedReader in = new BufferedReader(
|
||||||
|
new InputStreamReader(
|
||||||
try {
|
yc.getInputStream()));
|
||||||
if (scanner.hasNext()) {
|
String inputLine;
|
||||||
consumer.accept(scanner.next());
|
String data = "";
|
||||||
}
|
while ((inputLine = in.readLine()) != null)
|
||||||
} catch (Throwable var8) {
|
data = inputLine;
|
||||||
try {
|
in.close();
|
||||||
scanner.close();
|
data = data.substring(1, data.length() - 1);
|
||||||
} catch (Throwable var7) {
|
if (data.isEmpty()) {
|
||||||
var8.addSuppressed(var7);
|
consumer.accept(null);
|
||||||
}
|
return;
|
||||||
throw var8;
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
} catch (Throwable var9) {
|
|
||||||
if (inputStream != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (Throwable var6) {
|
|
||||||
var9.addSuppressed(var6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw var9;
|
|
||||||
}
|
}
|
||||||
inputStream.close();
|
JSONObject obj = new JSONObject(data);
|
||||||
} catch (IOException var10) {
|
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");
|
||||||
|
}
|
||||||
|
T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, published_at, downloadURL, prerelease);
|
||||||
|
consumer.accept(webData);
|
||||||
|
} catch (Exception var10) {
|
||||||
Boolean load = false;
|
Boolean load = false;
|
||||||
if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())){
|
if (T2CupdateAPI.pluginVersions.containsKey(plugin.getName())) {
|
||||||
load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load;
|
load = T2CupdateAPI.pluginVersions.get(plugin.getName()).load;
|
||||||
}
|
}
|
||||||
|
|
||||||
T2CupdateObject update = new T2CupdateObject(
|
T2CupdateObject update = new T2CupdateObject(
|
||||||
plugin.getName(),
|
plugin.getName(),
|
||||||
pluginVersion,
|
pluginVersion,
|
||||||
@ -69,4 +70,5 @@ public class T2CupdateChecker {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,16 @@ public class T2CupdateObject {
|
|||||||
|
|
||||||
public String pluginName;
|
public String pluginName;
|
||||||
public String pluginVersion;
|
public String pluginVersion;
|
||||||
public String publicVersion;
|
public T2CupdateWebData webData;
|
||||||
public String changeLog;
|
|
||||||
public Boolean load;
|
public Boolean load;
|
||||||
|
|
||||||
public T2CupdateObject(String pluginName,
|
public T2CupdateObject(String pluginName,
|
||||||
String pluginVersion,
|
String pluginVersion,
|
||||||
String publicVersion ,
|
T2CupdateWebData webData ,
|
||||||
String changeLog ,
|
|
||||||
Boolean load) {
|
Boolean load) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
this.pluginVersion = pluginVersion;
|
this.pluginVersion = pluginVersion;
|
||||||
this.publicVersion = publicVersion;
|
this.webData = webData;
|
||||||
this.changeLog = changeLog;
|
|
||||||
this.load=load;
|
this.load=load;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class T2CupdateWebData {
|
||||||
|
@Getter
|
||||||
|
private String UpdateName;
|
||||||
|
@Getter
|
||||||
|
private String tag_name;
|
||||||
|
@Getter
|
||||||
|
private String body;
|
||||||
|
@Getter
|
||||||
|
private String updateurl;
|
||||||
|
@Getter
|
||||||
|
private String published_at;
|
||||||
|
@Getter
|
||||||
|
private String downloadURL;
|
||||||
|
@Getter
|
||||||
|
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;
|
||||||
|
this.body = body;
|
||||||
|
this.updateurl = updateurl;
|
||||||
|
this.published_at = published_at;
|
||||||
|
this.downloadURL = downloadURL;
|
||||||
|
this.prerelease = prerelease;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ public final class T2CodeLibMain extends JavaPlugin {
|
|||||||
SelectLibConfig.onSelect();
|
SelectLibConfig.onSelect();
|
||||||
SelectLibMsg.onSelect();
|
SelectLibMsg.onSelect();
|
||||||
|
|
||||||
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getSpigotID(), Util.getDiscord());
|
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getDiscord(), "https://git.t2code.net/api/v1/repos/JaTiTV/T2CodeLib/releases?limit=1");
|
||||||
Metrics.Bstats(plugin, Util.getBstatsID());
|
Metrics.Bstats(plugin, Util.getBstatsID());
|
||||||
if (SelectLibConfig.getBungee()){
|
if (SelectLibConfig.getBungee()){
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");
|
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:bcmd");
|
||||||
|
Loading…
Reference in New Issue
Block a user