New Bungee Updater
This commit is contained in:
parent
5857e02695
commit
f70767b361
@ -39,7 +39,7 @@ 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;
|
||||
String publicVersion = T2CBupdateAPI.bungeePluginVersins.get(plugin.getDescription().getName()).webData.getVersion();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
T2CBsend.sender(sender, prefix + "§4======= " + prefix + " §4=======");
|
||||
T2CBsend.sender(sender, prefix + " §2Autor: §6" + autor);
|
||||
|
@ -1,20 +1,26 @@
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
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.HashMap;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class T2CBupdateAPI {
|
||||
public static HashMap<String, T2CBupdateObject> bungeePluginVersins = new HashMap<String, T2CBupdateObject>();
|
||||
public static HashMap<String, T2CupdateObject> bungeePluginVersins = new HashMap<>();
|
||||
|
||||
public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version) {
|
||||
T2CBsend.console("§4=========== " + Prefix + " §4===========");
|
||||
@ -24,6 +30,7 @@ public class T2CBupdateAPI {
|
||||
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!");
|
||||
@ -32,21 +39,25 @@ public class T2CBupdateAPI {
|
||||
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 Spigot, String Discord, Integer SpigotID, String url) {
|
||||
ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() {
|
||||
public void run() {
|
||||
(new T2CBupdateAPI(plugin, SpigotID)).getVersion((update_version) -> {
|
||||
pluginVersion = plugin.getDescription().getVersion();
|
||||
T2CBupdateObject update = new T2CBupdateObject(
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getDescription().getName(),
|
||||
pluginVersion,
|
||||
update_version
|
||||
plugin.getDescription().getVersion(),
|
||||
update_version,
|
||||
false,
|
||||
!plugin.getDescription().getVersion().equals(update_version.getVersion())
|
||||
);
|
||||
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(update_version.getVersion())) {
|
||||
sendUpdateMsg(Prefix, Spigot, Discord, pluginVersion, update_version.getVersion());
|
||||
noUpdate = true;
|
||||
} else {
|
||||
if (noUpdate) {
|
||||
@ -54,10 +65,11 @@ public class T2CBupdateAPI {
|
||||
noUpdate = false;
|
||||
}
|
||||
}
|
||||
},Prefix, pluginVersion);
|
||||
}, pluginVersion, SpigotID, url);
|
||||
}
|
||||
}, 0, 20 * 60 * 60L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private Plugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
@ -66,47 +78,66 @@ public class T2CBupdateAPI {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) {
|
||||
ProxyServer.getInstance().getScheduler().runAsync(this.plugin, () -> {
|
||||
public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String URL) {
|
||||
BungeeCord.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);
|
||||
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", "<br>").replace("\r", "").replace("'", "''");
|
||||
String updateurl = obj.getString("html_url");
|
||||
boolean prerelease = obj.getBoolean("prerelease");
|
||||
|
||||
try {
|
||||
if (scanner.hasNext()) {
|
||||
consumer.accept(scanner.next());
|
||||
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");
|
||||
}
|
||||
} catch (Throwable var8) {
|
||||
try {
|
||||
scanner.close();
|
||||
} catch (Throwable var7) {
|
||||
var8.addSuppressed(var7);
|
||||
|
||||
if (!prerelease) {
|
||||
downloadURL = "https://www.spigotmc.org/resources/" + spigotID;
|
||||
updateurl = "https://www.spigotmc.org/resources/" + spigotID;
|
||||
}
|
||||
throw var8;
|
||||
|
||||
T2CupdateWebData webData = new T2CupdateWebData(UpdateName, tag_name, body, updateurl, formattedDate, downloadURL, prerelease);
|
||||
consumer.accept(webData);
|
||||
} catch (Exception var10) {
|
||||
Boolean load = false;
|
||||
if (bungeePluginVersins.containsKey(plugin.getDescription().getName())) {
|
||||
load = bungeePluginVersins.get(plugin.getDescription().getName()).load;
|
||||
}
|
||||
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(
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getDescription().getName(),
|
||||
pluginVersion,
|
||||
"§4No public version found!"
|
||||
null,
|
||||
load,
|
||||
false
|
||||
);
|
||||
bungeePluginVersins.put(plugin.getDescription().getName(), update);
|
||||
this.plugin.getLogger().severe(Prefix + "§4 Cannot look for updates: " + var10.getMessage());
|
||||
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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, spigot, discord, spigotID,url);
|
||||
|
||||
//API
|
||||
plugin.getProxy().registerChannel("t2c:bcmd");
|
||||
|
@ -23,7 +23,7 @@ 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());
|
||||
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();
|
||||
|
@ -4,6 +4,8 @@ import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.SPIGOT.system.UpdateType;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import net.t2code.t2codelib.T2CupdateWebData;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
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;
|
||||
|
@ -2,7 +2,7 @@ package net.t2code.t2codelib.SPIGOT.system.cmd;
|
||||
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
||||
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateObject;
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
@ -3,10 +3,7 @@ package net.t2code.t2codelib.SPIGOT.system.cmd;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
|
||||
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
||||
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateObject;
|
||||
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateWebData;
|
||||
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||
import net.t2code.t2codelib.SPIGOT.system.UpdateType;
|
||||
import net.t2code.t2codelib.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
package net.t2code.t2codelib;
|
||||
|
||||
|
||||
public class T2CupdateObject {
|
@ -1,4 +1,4 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
package net.t2code.t2codelib;
|
||||
|
||||
import lombok.Getter;
|
||||
|
Loading…
Reference in New Issue
Block a user