13.5
Change: - If no new update was found from a plugin, then there is now no more console spam - Support for the old update checker has been removed
This commit is contained in:
parent
1b7918f011
commit
e4c4aee0f7
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>net.t2code</groupId>
|
||||
<artifactId>T2CodeLib</artifactId>
|
||||
<version>13.4</version>
|
||||
<version>13.5</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>T2CodeLib</name>
|
||||
|
@ -1,10 +1,8 @@
|
||||
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;
|
||||
@ -18,7 +16,7 @@ public class T2CupdateAPI {
|
||||
public static HashMap<String, T2CupdateObject> pluginVersions = new HashMap<>();
|
||||
|
||||
public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) {
|
||||
if (! pluginVersions.get(plugin.getName()).updateCheckOnJoin) {
|
||||
if (!pluginVersions.get(plugin.getName()).updateCheckOnJoin) {
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission(perm) && !player.isOp()) {
|
||||
@ -170,82 +168,7 @@ public class T2CupdateAPI {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void onUpdateCheck(Plugin plugin, String prefix, int 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,
|
||||
!plugin.getDescription().getVersion().equals(update_version),
|
||||
true
|
||||
);
|
||||
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, update.webData, plugin);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(plugin, 200L);
|
||||
} else sendUpdateMsg(prefix, discord, update.webData, plugin);
|
||||
} else {
|
||||
if (!update.load) {
|
||||
T2Csend.console(prefix + " §2No update found.");
|
||||
update.load = true;
|
||||
}
|
||||
}
|
||||
}, 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);
|
||||
new T2CupdateCheckerGit((JavaPlugin) plugin, prefix, gitKey, spigotID, discord, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class T2CupdateChecker {
|
||||
private JavaPlugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
public T2CupdateChecker(JavaPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
if (!plugin.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(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;
|
||||
}
|
||||
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,
|
||||
null,
|
||||
load,
|
||||
false,
|
||||
updateCheckOnJoin
|
||||
|
||||
);
|
||||
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
|
||||
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import net.t2code.t2codelib.T2CupdateObject;
|
||||
import net.t2code.t2codelib.T2CupdateWebData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -15,10 +17,55 @@ import java.util.Date;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class T2CupdateCheckerGit {
|
||||
private JavaPlugin plugin;
|
||||
private final JavaPlugin plugin;
|
||||
private T2CupdateObject t2CupdateObject;
|
||||
|
||||
public T2CupdateCheckerGit(JavaPlugin plugin) {
|
||||
|
||||
public T2CupdateCheckerGit(JavaPlugin plugin, String prefix, String gitKey, Integer spigotID, String discord, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
this.plugin = plugin;
|
||||
|
||||
String RepoURL = "https://git.t2code.net/api/v1/repos/" + gitKey + "/releases?limit=1";
|
||||
if (!seePreReleaseUpdates) {
|
||||
RepoURL = RepoURL + "&pre-release=false";
|
||||
}
|
||||
String finalRepoURL = RepoURL;
|
||||
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getVersion((webData) -> {
|
||||
T2CupdateObject update = new T2CupdateObject(
|
||||
plugin.getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
webData,
|
||||
t2CupdateObject != null && t2CupdateObject.load,
|
||||
!plugin.getDescription().getVersion().equals(webData.getVersion()),
|
||||
updateCheckOnJoin
|
||||
);
|
||||
|
||||
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
|
||||
if (T2CupdateAPI.pluginVersions.get(plugin.getName()).updateAvailable) {
|
||||
if (!update.load) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
update.load = true;
|
||||
T2CupdateAPI.sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
}
|
||||
}.runTaskLaterAsynchronously(plugin, 600L);
|
||||
} else T2CupdateAPI.sendUpdateMsg(prefix, discord, webData, plugin);
|
||||
} else {
|
||||
if (!update.load) {
|
||||
T2Csend.console(prefix + " §2No update found.");
|
||||
update.load = true;
|
||||
}
|
||||
}
|
||||
|
||||
t2CupdateObject = update;
|
||||
|
||||
}, plugin.getDescription().getVersion(), spigotID, finalRepoURL, updateCheckOnJoin, seePreReleaseUpdates, timeInterval);
|
||||
}
|
||||
}, 0L, timeInterval * 60 * 20L);
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<T2CupdateWebData> consumer, String pluginVersion, Integer spigotID, String URL, Boolean updateCheckOnJoin, Boolean seePreReleaseUpdates, Integer timeInterval) {
|
||||
|
Loading…
Reference in New Issue
Block a user