mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-26 14:53:14 +00:00
Added ResourcePack update notifier (#260)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
44a4491bfd
commit
371fad33c8
16 files changed
+1198
No files matched your search
@@ -13,10 +13,12 @@ import net.minecraftforge.client.ClientCommandHandler;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater.ResourcePackUpdateEventHandler;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelRegistry;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.postprocessing.shaders.UniversiumShader;
|
||||
import com.gtnewhorizon.gtnhlib.client.tooltip.LoreHandler;
|
||||
import com.gtnewhorizon.gtnhlib.commands.CommandResourcePack;
|
||||
import com.gtnewhorizon.gtnhlib.commands.ItemInHandCommand;
|
||||
import com.gtnewhorizon.gtnhlib.compat.FalseTweaks;
|
||||
import com.gtnewhorizon.gtnhlib.compat.Mods;
|
||||
@@ -63,6 +65,8 @@ public class ClientProxy extends CommonProxy {
|
||||
public void init(FMLInitializationEvent event) {
|
||||
super.init(event);
|
||||
ClientCommandHandler.instance.registerCommand(new ItemInHandCommand());
|
||||
ClientCommandHandler.instance.registerCommand(new CommandResourcePack());
|
||||
FMLCommonHandler.instance().bus().register(new ResourcePackUpdateEventHandler());
|
||||
UniversiumShader.init();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@ public class GTNHLibConfig {
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean enableTranslucentItemRenders;
|
||||
|
||||
@Config.Comment("Enable client-side resource pack update checking for active packs")
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean enableResourcePackUpdateCheck;
|
||||
|
||||
@Config.Comment("If you're not a dev, you don't need this")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.event.ClickEvent;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
final class ChatNotifier {
|
||||
|
||||
private ChatNotifier() {}
|
||||
|
||||
static void sendUpdateMessage(String packName, String installed, String remote, String url) {
|
||||
String header = StatCollector
|
||||
.translateToLocalFormatted("gtnhlib.chat.rpupdater.update_available", packName, remote, installed);
|
||||
ResourcePackUpdateEventHandler.enqueue(() -> {
|
||||
IChatComponent headerComponent = new ChatComponentText(header);
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(headerComponent);
|
||||
|
||||
IChatComponent root = new ChatComponentText("");
|
||||
ChatComponentText clickable = new ChatComponentText(
|
||||
StatCollector.translateToLocal("gtnhlib.chat.rpupdater.click_here"));
|
||||
ChatStyle style = new ChatStyle();
|
||||
style.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
|
||||
clickable.setChatStyle(style);
|
||||
root.appendSibling(clickable);
|
||||
root.appendSibling(
|
||||
new ChatComponentText(StatCollector.translateToLocal("gtnhlib.chat.rpupdater.open_release")));
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(root);
|
||||
});
|
||||
}
|
||||
|
||||
static void sendLineMismatch(String packName, String installedLine, String playerLine) {
|
||||
String message = StatCollector
|
||||
.translateToLocalFormatted("gtnhlib.chat.rpupdater.line_mismatch", packName, installedLine, playerLine);
|
||||
ResourcePackUpdateEventHandler.enqueue(
|
||||
() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(message)));
|
||||
}
|
||||
|
||||
static void sendNoUpdatesFound() {
|
||||
String message = StatCollector.translateToLocal("gtnhlib.chat.rpupdater.no_updates");
|
||||
ResourcePackUpdateEventHandler.enqueue(
|
||||
() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(message)));
|
||||
}
|
||||
|
||||
static void sendCooldownMessage() {
|
||||
String command = "/resourcepack updateCheck force";
|
||||
String message = StatCollector.translateToLocalFormatted("gtnhlib.chat.rpupdater.cooldown", command);
|
||||
ResourcePackUpdateEventHandler.enqueue(
|
||||
() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(message)));
|
||||
}
|
||||
|
||||
static void sendChecking() {
|
||||
String message = StatCollector.translateToLocal("gtnhlib.chat.rpupdater.checking");
|
||||
ResourcePackUpdateEventHandler.enqueue(
|
||||
() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(message)));
|
||||
}
|
||||
|
||||
static void sendAlreadyRunning() {
|
||||
String message = StatCollector.translateToLocal("gtnhlib.chat.rpupdater.already_running");
|
||||
ResourcePackUpdateEventHandler.enqueue(
|
||||
() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(message)));
|
||||
}
|
||||
|
||||
static void sendManualCooldown() {
|
||||
String message = StatCollector.translateToLocal("gtnhlib.chat.rpupdater.manual_cooldown");
|
||||
ResourcePackUpdateEventHandler.enqueue(
|
||||
() -> Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(message)));
|
||||
}
|
||||
}
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
final class GitHubReleaseClient {
|
||||
|
||||
private static final String USER_AGENT = "GTNHLib-RPUpdater";
|
||||
private static final int TIMEOUT_MS = 10_000;
|
||||
private static final String ASSET_NAME = "gtnh-pack-update.json";
|
||||
|
||||
private GitHubReleaseClient() {}
|
||||
|
||||
static Optional<ReleaseMatch> findNewestCompatibleRelease(String owner, String repo, String targetLine)
|
||||
throws IOException {
|
||||
List<ReleaseInfo> releases = fetchReleases(owner, repo);
|
||||
for (ReleaseInfo release : releases) {
|
||||
ReleaseAsset asset = release.findAsset(ASSET_NAME);
|
||||
if (asset == null) {
|
||||
continue;
|
||||
}
|
||||
ReleaseAssetMeta meta = fetchAssetMeta(asset.downloadUrl);
|
||||
if (meta == null) {
|
||||
continue;
|
||||
}
|
||||
if (matchesLine(meta.packGameVersion, targetLine)) {
|
||||
RpUpdaterLog
|
||||
.debug("Found compatible release {} for {}/{} ({})", release.htmlUrl, owner, repo, targetLine);
|
||||
return Optional.of(new ReleaseMatch(meta.packVersion, release.htmlUrl));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static List<ReleaseInfo> fetchReleases(String owner, String repo) throws IOException {
|
||||
String url = "https://api.github.com/repos/" + owner + "/" + repo + "/releases?per_page=20";
|
||||
JsonElement element = readJson(url);
|
||||
if (!element.isJsonArray()) {
|
||||
throw new IOException("Unexpected releases response");
|
||||
}
|
||||
JsonArray array = element.getAsJsonArray();
|
||||
List<ReleaseInfo> releases = new ArrayList<>();
|
||||
for (JsonElement releaseElement : array) {
|
||||
if (!releaseElement.isJsonObject()) {
|
||||
continue;
|
||||
}
|
||||
JsonObject releaseObj = releaseElement.getAsJsonObject();
|
||||
String htmlUrl = readOptionalString(releaseObj, "html_url");
|
||||
if (htmlUrl == null) {
|
||||
continue;
|
||||
}
|
||||
List<ReleaseAsset> assets = new ArrayList<>();
|
||||
if (releaseObj.has("assets") && releaseObj.get("assets").isJsonArray()) {
|
||||
for (JsonElement assetElement : releaseObj.getAsJsonArray("assets")) {
|
||||
if (!assetElement.isJsonObject()) {
|
||||
continue;
|
||||
}
|
||||
JsonObject assetObj = assetElement.getAsJsonObject();
|
||||
String name = readOptionalString(assetObj, "name");
|
||||
String downloadUrl = readOptionalString(assetObj, "browser_download_url");
|
||||
if (name != null && downloadUrl != null) {
|
||||
assets.add(new ReleaseAsset(name, downloadUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
releases.add(new ReleaseInfo(htmlUrl, assets));
|
||||
}
|
||||
return releases;
|
||||
}
|
||||
|
||||
private static ReleaseAssetMeta fetchAssetMeta(String downloadUrl) throws IOException {
|
||||
JsonElement element = readJson(downloadUrl);
|
||||
if (!element.isJsonObject()) {
|
||||
throw new IOException("Unexpected asset response");
|
||||
}
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
int schema = readOptionalInt(obj, "schema", -1);
|
||||
if (schema != 1) {
|
||||
RpUpdaterLog.warn("Unsupported asset schema {} at {}", schema, downloadUrl);
|
||||
return null;
|
||||
}
|
||||
String packGameVersion = readOptionalString(obj, "pack_game_version");
|
||||
String packVersion = readOptionalString(obj, "pack_version");
|
||||
if (packGameVersion == null || packVersion == null) {
|
||||
RpUpdaterLog.warn("Missing fields in asset metadata at {}", downloadUrl);
|
||||
return null;
|
||||
}
|
||||
return new ReleaseAssetMeta(packGameVersion, packVersion);
|
||||
}
|
||||
|
||||
private static JsonElement readJson(String url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setRequestProperty("User-Agent", USER_AGENT);
|
||||
connection.setRequestProperty("Accept", "application/vnd.github+json");
|
||||
connection.setConnectTimeout(TIMEOUT_MS);
|
||||
connection.setReadTimeout(TIMEOUT_MS);
|
||||
int code = connection.getResponseCode();
|
||||
if (code < 200 || code >= 300) {
|
||||
throw new IOException("HTTP " + code + " for " + url);
|
||||
}
|
||||
try (InputStream stream = connection.getInputStream()) {
|
||||
return new JsonParser().parse(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private static String readOptionalString(JsonObject obj, String field) {
|
||||
if (!obj.has(field) || obj.get(field).isJsonNull()) {
|
||||
return null;
|
||||
}
|
||||
return obj.get(field).getAsString();
|
||||
}
|
||||
|
||||
private static int readOptionalInt(JsonObject obj, String field, int def) {
|
||||
if (!obj.has(field) || obj.get(field).isJsonNull()) {
|
||||
return def;
|
||||
}
|
||||
return obj.get(field).getAsInt();
|
||||
}
|
||||
|
||||
private static boolean matchesLine(String field, String targetLine) {
|
||||
if (field == null || targetLine == null) {
|
||||
return false;
|
||||
}
|
||||
for (String part : field.split(";")) {
|
||||
String trimmed = part.trim();
|
||||
if (!trimmed.isEmpty() && trimmed.equals(targetLine)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final class ReleaseInfo {
|
||||
|
||||
final String htmlUrl;
|
||||
final List<ReleaseAsset> assets;
|
||||
|
||||
ReleaseInfo(String htmlUrl, List<ReleaseAsset> assets) {
|
||||
this.htmlUrl = htmlUrl;
|
||||
this.assets = assets;
|
||||
}
|
||||
|
||||
ReleaseAsset findAsset(String name) {
|
||||
for (ReleaseAsset asset : assets) {
|
||||
if (name.equals(asset.name)) {
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ReleaseAsset {
|
||||
|
||||
final String name;
|
||||
final String downloadUrl;
|
||||
|
||||
ReleaseAsset(String name, String downloadUrl) {
|
||||
this.name = name;
|
||||
this.downloadUrl = downloadUrl;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ReleaseAssetMeta {
|
||||
|
||||
final String packGameVersion;
|
||||
final String packVersion;
|
||||
|
||||
ReleaseAssetMeta(String packGameVersion, String packVersion) {
|
||||
this.packGameVersion = packGameVersion;
|
||||
this.packVersion = packVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
final class PackMcmetaReader {
|
||||
|
||||
private static final String UPDATER_KEY = "gtnh_resource_pack_updater";
|
||||
private static final String SOURCE_TYPE_GITHUB = "github_releases";
|
||||
private static final String[] INPUT_STREAM_METHODS = { "getInputStreamByName", "func_110591_a" };
|
||||
|
||||
private PackMcmetaReader() {}
|
||||
|
||||
static Optional<UpdaterMeta> readUpdaterMeta(IResourcePack pack) {
|
||||
try (InputStream stream = openPackMcmeta(pack)) {
|
||||
if (stream == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
JsonElement rootElement = new JsonParser().parse(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||
if (!rootElement.isJsonObject()) {
|
||||
RpUpdaterLog.warn("pack.mcmeta root is not an object for pack {}", pack.getPackName());
|
||||
return Optional.empty();
|
||||
}
|
||||
JsonObject root = rootElement.getAsJsonObject();
|
||||
if (!root.has(UPDATER_KEY) || !root.get(UPDATER_KEY).isJsonObject()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
JsonObject updater = root.getAsJsonObject(UPDATER_KEY);
|
||||
int schema = readRequiredInt(updater, "schema", pack.getPackName());
|
||||
if (schema != 1) {
|
||||
RpUpdaterLog.warn("Unsupported updater schema {} in pack {}", schema, pack.getPackName());
|
||||
return Optional.empty();
|
||||
}
|
||||
String packName = readRequiredString(updater, "pack_name", pack.getPackName());
|
||||
String packVersion = readRequiredString(updater, "pack_version", pack.getPackName());
|
||||
String packGameVersion = readRequiredString(updater, "pack_game_version", pack.getPackName());
|
||||
if (!updater.has("source") || !updater.get("source").isJsonObject()) {
|
||||
RpUpdaterLog.warn("Missing source object in pack {}", pack.getPackName());
|
||||
return Optional.empty();
|
||||
}
|
||||
JsonObject source = updater.getAsJsonObject("source");
|
||||
String sourceType = readRequiredString(source, "type", pack.getPackName());
|
||||
if (!SOURCE_TYPE_GITHUB.equals(sourceType)) {
|
||||
RpUpdaterLog.warn("Unsupported source type {} in pack {}", sourceType, pack.getPackName());
|
||||
return Optional.empty();
|
||||
}
|
||||
String owner = readRequiredString(source, "owner", pack.getPackName());
|
||||
String repo = readRequiredString(source, "repo", pack.getPackName());
|
||||
return Optional.of(new UpdaterMeta(packName, packVersion, packGameVersion, sourceType, owner, repo));
|
||||
} catch (IOException e) {
|
||||
RpUpdaterLog.warn("Failed reading pack.mcmeta for pack {}: {}", pack.getPackName(), e.toString());
|
||||
return Optional.empty();
|
||||
} catch (RuntimeException e) {
|
||||
RpUpdaterLog.warn("Invalid pack.mcmeta for pack {}: {}", pack.getPackName(), e.toString());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream openPackMcmeta(IResourcePack pack) throws IOException {
|
||||
Method method = findGetInputStreamByName(pack.getClass());
|
||||
if (method == null) {
|
||||
RpUpdaterLog.warn("Unable to read pack.mcmeta for pack {} (no access method)", pack.getPackName());
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (InputStream) method.invoke(pack, "pack.mcmeta");
|
||||
} catch (Exception e) {
|
||||
RpUpdaterLog.warn("Failed opening pack.mcmeta for pack {}: {}", pack.getPackName(), e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Method findGetInputStreamByName(Class<?> type) {
|
||||
Class<?> current = type;
|
||||
while (current != null) {
|
||||
for (String name : INPUT_STREAM_METHODS) {
|
||||
try {
|
||||
Method method = current.getDeclaredMethod(name, String.class);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
// Try other names or fallback scan.
|
||||
}
|
||||
}
|
||||
for (Method method : current.getDeclaredMethods()) {
|
||||
Class<?>[] params = method.getParameterTypes();
|
||||
if (params.length == 1 && params[0] == String.class
|
||||
&& InputStream.class.isAssignableFrom(method.getReturnType())) {
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
}
|
||||
current = current.getSuperclass();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String readRequiredString(JsonObject obj, String field, String packName) {
|
||||
if (!obj.has(field)) {
|
||||
throw new IllegalArgumentException("Missing " + field + " in pack " + packName);
|
||||
}
|
||||
return obj.get(field).getAsString();
|
||||
}
|
||||
|
||||
private static int readRequiredInt(JsonObject obj, String field, String packName) {
|
||||
if (!obj.has(field)) {
|
||||
throw new IllegalArgumentException("Missing " + field + " in pack " + packName);
|
||||
}
|
||||
return obj.get(field).getAsInt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
final class PackVersion implements Comparable<PackVersion> {
|
||||
|
||||
final int major;
|
||||
final int minor;
|
||||
|
||||
private PackVersion(int major, int minor) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
static PackVersion parse(String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("Version is null");
|
||||
}
|
||||
String[] parts = value.trim().split("\\.");
|
||||
if (parts.length != 2) {
|
||||
throw new IllegalArgumentException("Version must be major.minor: " + value);
|
||||
}
|
||||
int major = Integer.parseInt(parts[0]);
|
||||
int minor = Integer.parseInt(parts[1]);
|
||||
if (major < 0 || minor < 0) {
|
||||
throw new IllegalArgumentException("Version must be non-negative: " + value);
|
||||
}
|
||||
return new PackVersion(major, minor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PackVersion other) {
|
||||
int majorCompare = Integer.compare(this.major, other.major);
|
||||
if (majorCompare != 0) {
|
||||
return majorCompare;
|
||||
}
|
||||
return Integer.compare(this.minor, other.minor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
final class ReleaseMatch {
|
||||
|
||||
final String packVersion;
|
||||
final String htmlUrl;
|
||||
|
||||
ReleaseMatch(String packVersion, String htmlUrl) {
|
||||
this.packVersion = packVersion;
|
||||
this.htmlUrl = htmlUrl;
|
||||
}
|
||||
}
|
||||
+361
@@ -0,0 +1,361 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.client.resources.ResourcePackRepository;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLibConfig;
|
||||
|
||||
public final class ResourcePackUpdateChecker {
|
||||
|
||||
private static final long FAILURE_COOLDOWN_MILLIS = 30L * 60L * 1000L;
|
||||
private static final long MANUAL_COOLDOWN_MILLIS = 30L * 1000L;
|
||||
private static boolean hasRunThisSession = false;
|
||||
private static long lastFailureMillis = 0L;
|
||||
private static long lastManualMillis = 0L;
|
||||
private static long lastCheckMillis = 0L;
|
||||
private static final Set<String> mismatchNotified = new HashSet<>();
|
||||
private static final AtomicBoolean checkInProgress = new AtomicBoolean(false);
|
||||
|
||||
private ResourcePackUpdateChecker() {}
|
||||
|
||||
public static void runAutoCheckIfNeeded() {
|
||||
if (hasRunThisSession) {
|
||||
return;
|
||||
}
|
||||
hasRunThisSession = true;
|
||||
if (!GTNHLibConfig.enableResourcePackUpdateCheck) {
|
||||
RpUpdaterLog.debug("Auto-check skipped (disabled in config)");
|
||||
return;
|
||||
}
|
||||
runCheckAsync(false, false);
|
||||
}
|
||||
|
||||
public static CheckResult runManualCheck(boolean force) {
|
||||
if (!force && isManualOnCooldown()) {
|
||||
ChatNotifier.sendManualCooldown();
|
||||
return new CheckResult();
|
||||
}
|
||||
lastManualMillis = System.currentTimeMillis();
|
||||
runCheckAsync(force, true);
|
||||
return new CheckResult();
|
||||
}
|
||||
|
||||
private static void runCheckAsync(boolean force, boolean isManual) {
|
||||
if (!checkInProgress.compareAndSet(false, true)) {
|
||||
RpUpdaterLog.debug("Update check already in progress");
|
||||
if (isManual) {
|
||||
ChatNotifier.sendAlreadyRunning();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (isOnCooldown() && !force) {
|
||||
if (isManual) {
|
||||
ChatNotifier.sendCooldownMessage();
|
||||
}
|
||||
RpUpdaterLog.debug("Check skipped due to cooldown");
|
||||
checkInProgress.set(false);
|
||||
return;
|
||||
}
|
||||
String playerLine = getPlayerLineNormalized();
|
||||
List<IResourcePack> packs = getEnabledPacks();
|
||||
if (isManual) {
|
||||
ChatNotifier.sendChecking();
|
||||
}
|
||||
Thread worker = new Thread(() -> runCheckWorker(packs, playerLine, isManual), "GTNHLib-RPUpdater");
|
||||
worker.setDaemon(true);
|
||||
worker.start();
|
||||
}
|
||||
|
||||
private static void runCheckWorker(List<IResourcePack> packs, String playerLine, boolean isManual) {
|
||||
try {
|
||||
RpUpdaterLog.debug("Starting update check (player line: {})", playerLine);
|
||||
CheckResult result = new CheckResult();
|
||||
List<UpdaterMeta> metas = scanEnabledPacks(packs, result);
|
||||
Map<RepoKey, Optional<ReleaseMatch>> releaseCache = new HashMap<>();
|
||||
for (UpdaterMeta meta : metas) {
|
||||
checkOnePack(meta, playerLine, releaseCache, result);
|
||||
}
|
||||
if (isManual && result.updatesFound == 0) {
|
||||
ChatNotifier.sendNoUpdatesFound();
|
||||
}
|
||||
} finally {
|
||||
lastCheckMillis = System.currentTimeMillis();
|
||||
checkInProgress.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<IResourcePack> getEnabledPacks() {
|
||||
ResourcePackRepository repo = Minecraft.getMinecraft().getResourcePackRepository();
|
||||
List<ResourcePackRepository.Entry> entries = repo.getRepositoryEntries();
|
||||
List<IResourcePack> packs = new ArrayList<>(entries.size());
|
||||
for (ResourcePackRepository.Entry entry : entries) {
|
||||
IResourcePack pack = entry.getResourcePack();
|
||||
if (pack == null) {
|
||||
continue;
|
||||
}
|
||||
packs.add(pack);
|
||||
}
|
||||
return packs;
|
||||
}
|
||||
|
||||
private static List<UpdaterMeta> scanEnabledPacks(List<IResourcePack> packs, CheckResult result) {
|
||||
result.packsScanned = packs.size();
|
||||
List<UpdaterMeta> metas = new ArrayList<>();
|
||||
for (IResourcePack pack : packs) {
|
||||
Optional<UpdaterMeta> meta = PackMcmetaReader.readUpdaterMeta(pack);
|
||||
if (meta.isPresent()) {
|
||||
result.packsWithUpdater++;
|
||||
metas.add(meta.get());
|
||||
RpUpdaterLog.debug("Found updater metadata in pack {}", pack.getPackName());
|
||||
}
|
||||
}
|
||||
RpUpdaterLog.debug("Scanned {} packs ({} with updater metadata)", result.packsScanned, result.packsWithUpdater);
|
||||
return metas;
|
||||
}
|
||||
|
||||
private static void checkOnePack(UpdaterMeta meta, String playerLine, Map<RepoKey, Optional<ReleaseMatch>> cache,
|
||||
CheckResult result) {
|
||||
String installedLine = meta.packGameVersion;
|
||||
List<String> installedLines = parseLineList(installedLine);
|
||||
String targetLine = "unknown".equals(playerLine) ? firstLineOrUnknown(installedLines) : playerLine;
|
||||
if (!"unknown".equals(playerLine) && !containsLine(installedLines, playerLine)
|
||||
&& mismatchNotified.add(meta.packName)) {
|
||||
ChatNotifier.sendLineMismatch(meta.packName, installedLine, playerLine);
|
||||
}
|
||||
Optional<ReleaseMatch> match = getNewestRelease(meta, targetLine, cache, result);
|
||||
if (!match.isPresent()) {
|
||||
RpUpdaterLog.debug("No compatible release for {} on {}", meta.packName, targetLine);
|
||||
return;
|
||||
}
|
||||
ReleaseMatch release = match.get();
|
||||
try {
|
||||
PackVersion installed = PackVersion.parse(meta.packVersion);
|
||||
PackVersion remote = PackVersion.parse(release.packVersion);
|
||||
if (remote.compareTo(installed) > 0) {
|
||||
ChatNotifier.sendUpdateMessage(meta.packName, meta.packVersion, release.packVersion, release.htmlUrl);
|
||||
result.updatesFound++;
|
||||
} else {
|
||||
RpUpdaterLog.debug(
|
||||
"No update for {} (installed {}, remote {})",
|
||||
meta.packName,
|
||||
meta.packVersion,
|
||||
release.packVersion);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
RpUpdaterLog.warn("Invalid pack version for {}: {}", meta.packName, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<ReleaseMatch> getNewestRelease(UpdaterMeta meta, String targetLine,
|
||||
Map<RepoKey, Optional<ReleaseMatch>> cache, CheckResult result) {
|
||||
RepoKey key = new RepoKey(meta.owner, meta.repo, targetLine);
|
||||
if (cache.containsKey(key)) {
|
||||
return cache.get(key);
|
||||
}
|
||||
try {
|
||||
Optional<ReleaseMatch> match = GitHubReleaseClient
|
||||
.findNewestCompatibleRelease(meta.owner, meta.repo, targetLine);
|
||||
cache.put(key, match);
|
||||
return match;
|
||||
} catch (Exception e) {
|
||||
result.hadFailure = true;
|
||||
lastFailureMillis = System.currentTimeMillis();
|
||||
RpUpdaterLog.warn("GitHub request failed for {}/{}: {}", meta.owner, meta.repo, e.toString());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isOnCooldown() {
|
||||
if (lastFailureMillis == 0L) {
|
||||
return false;
|
||||
}
|
||||
return System.currentTimeMillis() - lastFailureMillis < FAILURE_COOLDOWN_MILLIS;
|
||||
}
|
||||
|
||||
private static boolean isManualOnCooldown() {
|
||||
if (lastManualMillis == 0L) {
|
||||
return false;
|
||||
}
|
||||
return System.currentTimeMillis() - lastManualMillis < MANUAL_COOLDOWN_MILLIS;
|
||||
}
|
||||
|
||||
private static List<String> parseLineList(String field) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
if (field == null) {
|
||||
return lines;
|
||||
}
|
||||
for (String part : field.split(";")) {
|
||||
String trimmed = part.trim();
|
||||
if (!trimmed.isEmpty()) {
|
||||
lines.add(trimmed);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private static boolean containsLine(List<String> lines, String target) {
|
||||
if (lines == null || target == null) {
|
||||
return false;
|
||||
}
|
||||
for (String line : lines) {
|
||||
if (line.equals(target)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String firstLineOrUnknown(List<String> lines) {
|
||||
if (lines == null || lines.isEmpty()) {
|
||||
return "unknown";
|
||||
}
|
||||
return lines.get(0);
|
||||
}
|
||||
|
||||
private static String getPlayerLineNormalized() {
|
||||
String version = readModpackVersion();
|
||||
if (version == null) {
|
||||
return "unknown";
|
||||
}
|
||||
if (version.startsWith("2.8")) {
|
||||
return "2.8.X";
|
||||
}
|
||||
if (version.startsWith("2.9")) {
|
||||
return "2.9.X";
|
||||
}
|
||||
if (version.matches("\\d+\\.\\d+\\.X")) {
|
||||
return version;
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
private static String readModpackVersion() { // TODO Get Actual modpack version somehow, because yes
|
||||
try {
|
||||
Class<?> refstrings = Class.forName("com.dreammaster.lib.Refstrings");
|
||||
return (String) refstrings.getField("MODPACKPACK_VERSION").get(null);
|
||||
} catch (Exception e) {
|
||||
RpUpdaterLog.debug("Refstrings not available: {}", e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CheckResult {
|
||||
|
||||
public int packsScanned;
|
||||
public int packsWithUpdater;
|
||||
public int updatesFound;
|
||||
public boolean cooldownBlocked;
|
||||
public boolean hadFailure;
|
||||
}
|
||||
|
||||
public static List<PackSummary> getActivePackSummaries() {
|
||||
List<IResourcePack> packs = getEnabledPacks();
|
||||
List<PackSummary> summaries = new ArrayList<>(packs.size());
|
||||
for (IResourcePack pack : packs) {
|
||||
Optional<UpdaterMeta> meta = PackMcmetaReader.readUpdaterMeta(pack);
|
||||
if (meta.isPresent()) {
|
||||
UpdaterMeta updater = meta.get();
|
||||
summaries.add(
|
||||
new PackSummary(
|
||||
pack.getPackName(),
|
||||
true,
|
||||
updater.packName,
|
||||
updater.packVersion,
|
||||
updater.packGameVersion,
|
||||
updater.owner,
|
||||
updater.repo));
|
||||
} else {
|
||||
summaries.add(new PackSummary(pack.getPackName(), false, null, null, null, null, null));
|
||||
}
|
||||
}
|
||||
return summaries;
|
||||
}
|
||||
|
||||
public static StatusSnapshot getStatusSnapshot() {
|
||||
long now = System.currentTimeMillis();
|
||||
long failureRemaining = Math.max(0L, (lastFailureMillis + FAILURE_COOLDOWN_MILLIS) - now);
|
||||
long manualRemaining = Math.max(0L, (lastManualMillis + MANUAL_COOLDOWN_MILLIS) - now);
|
||||
return new StatusSnapshot(checkInProgress.get(), lastCheckMillis, failureRemaining, manualRemaining);
|
||||
}
|
||||
|
||||
public static final class PackSummary {
|
||||
|
||||
public final String packDisplayName;
|
||||
public final boolean hasUpdater;
|
||||
public final String updaterPackName;
|
||||
public final String packVersion;
|
||||
public final String packGameVersion;
|
||||
public final String owner;
|
||||
public final String repo;
|
||||
|
||||
private PackSummary(String packDisplayName, boolean hasUpdater, String updaterPackName, String packVersion,
|
||||
String packGameVersion, String owner, String repo) {
|
||||
this.packDisplayName = packDisplayName;
|
||||
this.hasUpdater = hasUpdater;
|
||||
this.updaterPackName = updaterPackName;
|
||||
this.packVersion = packVersion;
|
||||
this.packGameVersion = packGameVersion;
|
||||
this.owner = owner;
|
||||
this.repo = repo;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class StatusSnapshot {
|
||||
|
||||
public final boolean running;
|
||||
public final long lastCheckMillis;
|
||||
public final long failureCooldownRemainingMillis;
|
||||
public final long manualCooldownRemainingMillis;
|
||||
|
||||
private StatusSnapshot(boolean running, long lastCheckMillis, long failureCooldownRemainingMillis,
|
||||
long manualCooldownRemainingMillis) {
|
||||
this.running = running;
|
||||
this.lastCheckMillis = lastCheckMillis;
|
||||
this.failureCooldownRemainingMillis = failureCooldownRemainingMillis;
|
||||
this.manualCooldownRemainingMillis = manualCooldownRemainingMillis;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RepoKey {
|
||||
|
||||
private final String owner;
|
||||
private final String repo;
|
||||
private final String targetLine;
|
||||
|
||||
private RepoKey(String owner, String repo, String targetLine) {
|
||||
this.owner = owner;
|
||||
this.repo = repo;
|
||||
this.targetLine = targetLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof RepoKey)) {
|
||||
return false;
|
||||
}
|
||||
RepoKey other = (RepoKey) obj;
|
||||
return owner.equals(other.owner) && repo.equals(other.repo) && targetLine.equals(other.targetLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = owner.hashCode();
|
||||
result = 31 * result + repo.hashCode();
|
||||
result = 31 * result + targetLine.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
|
||||
public final class ResourcePackUpdateEventHandler {
|
||||
|
||||
private static final Queue<Runnable> TASKS = new ConcurrentLinkedQueue<>();
|
||||
private static final int AUTO_RUN_DELAY_TICKS = 100; // 5 seconds
|
||||
|
||||
private boolean pendingAutoRun = false;
|
||||
private int autoRunCountdown = 0;
|
||||
|
||||
static void enqueue(Runnable task) {
|
||||
if (task != null) {
|
||||
TASKS.add(task);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientConnected(FMLNetworkEvent.ClientConnectedToServerEvent event) {
|
||||
pendingAutoRun = true;
|
||||
autoRunCountdown = AUTO_RUN_DELAY_TICKS;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END) {
|
||||
return;
|
||||
}
|
||||
if (!pendingAutoRun) {
|
||||
return;
|
||||
}
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.theWorld == null || mc.thePlayer == null) {
|
||||
return;
|
||||
}
|
||||
if (autoRunCountdown > 0) {
|
||||
autoRunCountdown--;
|
||||
return;
|
||||
}
|
||||
pendingAutoRun = false;
|
||||
ResourcePackUpdateChecker.runAutoCheckIfNeeded();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTickQueue(TickEvent.ClientTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END) {
|
||||
return;
|
||||
}
|
||||
Runnable task;
|
||||
while ((task = TASKS.poll()) != null) {
|
||||
try {
|
||||
task.run();
|
||||
} catch (Exception e) {
|
||||
RpUpdaterLog.warn("Task execution failed: {}", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLib;
|
||||
|
||||
final class RpUpdaterLog {
|
||||
|
||||
private RpUpdaterLog() {}
|
||||
|
||||
static void debug(String message, Object... args) {
|
||||
GTNHLib.LOG.debug("[RPUpdater] " + message, args);
|
||||
}
|
||||
|
||||
static void warn(String message, Object... args) {
|
||||
GTNHLib.LOG.warn("[RPUpdater] " + message, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater;
|
||||
|
||||
final class UpdaterMeta {
|
||||
|
||||
final String packName;
|
||||
final String packVersion;
|
||||
final String packGameVersion;
|
||||
final String sourceType;
|
||||
final String owner;
|
||||
final String repo;
|
||||
|
||||
UpdaterMeta(String packName, String packVersion, String packGameVersion, String sourceType, String owner,
|
||||
String repo) {
|
||||
this.packName = packName;
|
||||
this.packVersion = packVersion;
|
||||
this.packGameVersion = packGameVersion;
|
||||
this.sourceType = sourceType;
|
||||
this.owner = owner;
|
||||
this.repo = repo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.gtnewhorizon.gtnhlib.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLibConfig;
|
||||
import com.gtnewhorizon.gtnhlib.client.ResourcePackUpdater.ResourcePackUpdateChecker;
|
||||
|
||||
public class CommandResourcePack extends GTNHClientCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "resourcepack";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/resourcepack updateCheck [force]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0 || "help".equalsIgnoreCase(args[0])) {
|
||||
printHelp();
|
||||
return;
|
||||
}
|
||||
if ("updateCheck".equalsIgnoreCase(args[0])) {
|
||||
boolean force = args.length > 1 && "force".equalsIgnoreCase(args[1]);
|
||||
if (!GTNHLibConfig.enableResourcePackUpdateCheck && !force) {
|
||||
addChatMessage(StatCollector.translateToLocal("gtnhlib.chat.rpupdater.disabled"));
|
||||
return;
|
||||
}
|
||||
ResourcePackUpdateChecker.runManualCheck(force);
|
||||
return;
|
||||
}
|
||||
if ("list".equalsIgnoreCase(args[0])) {
|
||||
printList();
|
||||
return;
|
||||
}
|
||||
if ("status".equalsIgnoreCase(args[0])) {
|
||||
printStatus();
|
||||
return;
|
||||
}
|
||||
if ("info".equalsIgnoreCase(args[0])) {
|
||||
if (args.length < 2) {
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted(
|
||||
"gtnhlib.chat.rpupdater.info.usage",
|
||||
"/resourcepack info <packName>"));
|
||||
return;
|
||||
}
|
||||
printInfo(args[1]);
|
||||
return;
|
||||
}
|
||||
printHelp();
|
||||
}
|
||||
|
||||
private void printHelp() {
|
||||
addChatMessage(StatCollector.translateToLocal("gtnhlib.chat.rpupdater.commands"));
|
||||
addChatMessage("/resourcepack updateCheck [force]");
|
||||
addChatMessage("/resourcepack list");
|
||||
addChatMessage("/resourcepack status");
|
||||
addChatMessage("/resourcepack info <packName>");
|
||||
addChatMessage("/resourcepack help");
|
||||
}
|
||||
|
||||
private void printList() {
|
||||
List<ResourcePackUpdateChecker.PackSummary> packs = ResourcePackUpdateChecker.getActivePackSummaries();
|
||||
addChatMessage(StatCollector.translateToLocalFormatted("gtnhlib.chat.rpupdater.list.header", packs.size()));
|
||||
for (ResourcePackUpdateChecker.PackSummary pack : packs) {
|
||||
if (pack.hasUpdater) {
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted(
|
||||
"gtnhlib.chat.rpupdater.list.item.updater",
|
||||
pack.packDisplayName,
|
||||
pack.updaterPackName,
|
||||
pack.packVersion,
|
||||
pack.packGameVersion));
|
||||
} else {
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted(
|
||||
"gtnhlib.chat.rpupdater.list.item.none",
|
||||
pack.packDisplayName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printStatus() {
|
||||
ResourcePackUpdateChecker.StatusSnapshot status = ResourcePackUpdateChecker.getStatusSnapshot();
|
||||
addChatMessage(StatCollector.translateToLocal("gtnhlib.chat.rpupdater.status.header"));
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted(
|
||||
"gtnhlib.chat.rpupdater.status.running",
|
||||
status.running ? "yes" : "no"));
|
||||
String lastCheck = status.lastCheckMillis == 0L
|
||||
? StatCollector.translateToLocal("gtnhlib.chat.rpupdater.status.never")
|
||||
: formatSecondsAgo(status.lastCheckMillis);
|
||||
addChatMessage(StatCollector.translateToLocalFormatted("gtnhlib.chat.rpupdater.status.last_check", lastCheck));
|
||||
if (status.failureCooldownRemainingMillis > 0L) {
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted(
|
||||
"gtnhlib.chat.rpupdater.status.cooldown_failure",
|
||||
formatSecondsRemaining(status.failureCooldownRemainingMillis)));
|
||||
}
|
||||
if (status.manualCooldownRemainingMillis > 0L) {
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted(
|
||||
"gtnhlib.chat.rpupdater.status.cooldown_manual",
|
||||
formatSecondsRemaining(status.manualCooldownRemainingMillis)));
|
||||
}
|
||||
}
|
||||
|
||||
private void printInfo(String query) {
|
||||
String needle = query.toLowerCase(Locale.ENGLISH);
|
||||
List<ResourcePackUpdateChecker.PackSummary> packs = ResourcePackUpdateChecker.getActivePackSummaries();
|
||||
List<ResourcePackUpdateChecker.PackSummary> matches = new java.util.ArrayList<>();
|
||||
for (ResourcePackUpdateChecker.PackSummary pack : packs) {
|
||||
String display = pack.packDisplayName.toLowerCase(Locale.ENGLISH);
|
||||
String updater = pack.updaterPackName == null ? "" : pack.updaterPackName.toLowerCase(Locale.ENGLISH);
|
||||
if (display.contains(needle) || updater.contains(needle)) {
|
||||
matches.add(pack);
|
||||
}
|
||||
}
|
||||
if (matches.isEmpty()) {
|
||||
addChatMessage(StatCollector.translateToLocalFormatted("gtnhlib.chat.rpupdater.info.not_found", query));
|
||||
return;
|
||||
}
|
||||
if (matches.size() > 1) {
|
||||
addChatMessage(
|
||||
StatCollector
|
||||
.translateToLocalFormatted("gtnhlib.chat.rpupdater.info.ambiguous", query, matches.size()));
|
||||
return;
|
||||
}
|
||||
ResourcePackUpdateChecker.PackSummary pack = matches.get(0);
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted("gtnhlib.chat.rpupdater.info.header", pack.packDisplayName));
|
||||
if (!pack.hasUpdater) {
|
||||
addChatMessage(StatCollector.translateToLocal("gtnhlib.chat.rpupdater.info.no_updater"));
|
||||
return;
|
||||
}
|
||||
addChatMessage(
|
||||
StatCollector
|
||||
.translateToLocalFormatted("gtnhlib.chat.rpupdater.info.updater_name", pack.updaterPackName));
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted(
|
||||
"gtnhlib.chat.rpupdater.info.version",
|
||||
pack.packVersion,
|
||||
pack.packGameVersion));
|
||||
addChatMessage(
|
||||
StatCollector.translateToLocalFormatted("gtnhlib.chat.rpupdater.info.source", pack.owner, pack.repo));
|
||||
}
|
||||
|
||||
private static String formatSecondsRemaining(long millis) {
|
||||
long seconds = Math.max(0L, millis / 1000L);
|
||||
return seconds + "s";
|
||||
}
|
||||
|
||||
private static String formatSecondsAgo(long millis) {
|
||||
long seconds = Math.max(0L, (System.currentTimeMillis() - millis) / 1000L);
|
||||
return seconds + "s";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return getListOfStringsMatchingLastWord(args, "updateCheck", "list", "status", "info", "help");
|
||||
}
|
||||
if (args.length == 2 && "updateCheck".equalsIgnoreCase(args[0])) {
|
||||
return getListOfStringsMatchingLastWord(args, "force");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user