Adapt UpdateCheckerTask to download platform jar
This commit is contained in:
parent
1ea8e24a1e
commit
35593efb0e
2 changed files with 28 additions and 7 deletions
|
|
@ -1,7 +1,11 @@
|
||||||
package net.frankheijden.serverutils.common.entities.http;
|
package net.frankheijden.serverutils.common.entities.http;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin;
|
||||||
|
|
||||||
public class GitHubAsset {
|
public class GitHubAsset {
|
||||||
|
|
||||||
|
|
@ -17,13 +21,30 @@ public class GitHubAsset {
|
||||||
* Creates a new GitHubAsset from given release url.
|
* Creates a new GitHubAsset from given release url.
|
||||||
*/
|
*/
|
||||||
public static GitHubAsset from(JsonObject jsonObject) {
|
public static GitHubAsset from(JsonObject jsonObject) {
|
||||||
|
return from(jsonObject, name -> true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GitHubAsset for given platfrom from given release url.
|
||||||
|
*/
|
||||||
|
public static GitHubAsset from(JsonObject jsonObject, ServerUtilsPlugin.Platform platform) {
|
||||||
|
return from(jsonObject, name -> name.toUpperCase(Locale.ENGLISH).contains(platform.name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GitHubAsset from given release url.
|
||||||
|
*/
|
||||||
|
public static GitHubAsset from(JsonObject jsonObject, Predicate<String> namePredicate) {
|
||||||
JsonArray assets = jsonObject.getAsJsonArray("assets");
|
JsonArray assets = jsonObject.getAsJsonArray("assets");
|
||||||
if (assets != null && assets.size() > 0) {
|
if (assets != null) {
|
||||||
JsonObject assetJson = assets.get(0).getAsJsonObject();
|
for (JsonElement asset : assets) {
|
||||||
return new GitHubAsset(
|
JsonObject assetJson = asset.getAsJsonObject();
|
||||||
assetJson.get("name").getAsString(),
|
|
||||||
assetJson.get("browser_download_url").getAsString()
|
String name = assetJson.get("name").getAsString();
|
||||||
);
|
if (namePredicate.test(name)) {
|
||||||
|
return new GitHubAsset(name, assetJson.get("browser_download_url").getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ public class UpdateCheckerTask<U extends ServerUtilsPlugin<P, ?, ?, ?, ?>, P> im
|
||||||
plugin.getLogger().log(Level.INFO, UPDATE_AVAILABLE, githubVersion);
|
plugin.getLogger().log(Level.INFO, UPDATE_AVAILABLE, githubVersion);
|
||||||
plugin.getLogger().log(Level.INFO, RELEASE_INFO, body);
|
plugin.getLogger().log(Level.INFO, RELEASE_INFO, body);
|
||||||
|
|
||||||
GitHubAsset pluginAsset = GitHubAsset.from(pluginJson);
|
GitHubAsset pluginAsset = GitHubAsset.from(pluginJson, plugin.getPlatform());
|
||||||
if (!download || pluginAsset == null) {
|
if (!download || pluginAsset == null) {
|
||||||
if (sender.isPlayer()) {
|
if (sender.isPlayer()) {
|
||||||
Component component = plugin.getMessagesResource().get(MessageKey.UPDATE_AVAILABLE).toComponent(
|
Component component = plugin.getMessagesResource().get(MessageKey.UPDATE_AVAILABLE).toComponent(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue