77 lines
2.7 KiB
Java
77 lines
2.7 KiB
Java
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());
|
|
}
|
|
});
|
|
}
|
|
}
|