diff --git a/build.gradle b/build.gradle index e136383..4b6ce94 100644 --- a/build.gradle +++ b/build.gradle @@ -30,8 +30,15 @@ dependencies { } processResources { + def propertyMap = [ + "version": project.version, + "mc_version": project.minecraft_version, + "commit": project.findProperty("commit") ?: "" + ] + + inputs.properties(propertyMap) filesMatching("fabric.mod.json") { - expand "version": project.version, "mc_version": project.minecraft_version + expand(propertyMap) } } diff --git a/src/main/java/dev/stardust/Stardust.java b/src/main/java/dev/stardust/Stardust.java index 0f527d0..9d3ce44 100644 --- a/src/main/java/dev/stardust/Stardust.java +++ b/src/main/java/dev/stardust/Stardust.java @@ -5,6 +5,9 @@ import dev.stardust.commands.*; import com.mojang.logging.LogUtils; import dev.stardust.util.StardustUtil; +import net.fabricmc.loader.api.FabricLoader; +import meteordevelopment.meteorclient.MeteorClient; +import net.fabricmc.loader.api.metadata.CustomValue; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.addons.GithubRepo; import meteordevelopment.meteorclient.commands.Commands; @@ -47,7 +50,6 @@ public void onInitialize() { Modules.get().add(new StashBrander()); Modules.get().add(new SignatureSign()); Modules.get().add(new SignHistorian()); - Modules.get().add(new UpdateNotifier()); Modules.get().add(new AutoDyeShulkers()); Modules.get().add(new AutoDrawDistance()); @@ -90,5 +92,15 @@ public void onRegisterCategories() { @Override public String getWebsite() { return "https://github.com/0xTas/stardust"; } @Override - public GithubRepo getRepo() { return new GithubRepo("0xTas", "Stardust"); } + public GithubRepo getRepo() { return new GithubRepo("0xTas", "Stardust", "1.20.4"); } + @Override + public String getCommit() { + CustomValue commit = FabricLoader.getInstance() + .getModContainer("stardust") + .orElseThrow() + .getMetadata() + .getCustomValue(MeteorClient.MOD_ID + ":commit"); + + return commit == null ? null : commit.getAsString(); + } } diff --git a/src/main/java/dev/stardust/modules/UpdateNotifier.java b/src/main/java/dev/stardust/modules/UpdateNotifier.java deleted file mode 100644 index 4a2966d..0000000 --- a/src/main/java/dev/stardust/modules/UpdateNotifier.java +++ /dev/null @@ -1,124 +0,0 @@ -package dev.stardust.modules; - -import java.net.URL; -import java.util.Map; -import java.util.List; -import java.util.Optional; -import net.minecraft.text.*; -import dev.stardust.Stardust; -import javax.annotation.Nullable; -import java.net.HttpURLConnection; -import dev.stardust.util.StardustUtil; -import java.net.MalformedURLException; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; -import meteordevelopment.orbit.EventHandler; -import meteordevelopment.meteorclient.MeteorClient; -import meteordevelopment.meteorclient.settings.Setting; -import meteordevelopment.meteorclient.settings.BoolSetting; -import meteordevelopment.meteorclient.systems.modules.Module; -import meteordevelopment.meteorclient.events.game.GameJoinedEvent; -import meteordevelopment.meteorclient.utils.network.MeteorExecutor; - - -/** - * @author Tas [0xTas] - **/ -public class UpdateNotifier extends Module { - public UpdateNotifier() { - super(Stardust.CATEGORY, "UpdateNotifier", "Notifies you in chat when a new version of Stardust is available."); - - if (!this.isActive()) { // only way of making the module "enabled by default". - MeteorClient.EVENT_BUS.subscribe(this); - } - } - - private final Setting notify = settings.getDefaultGroup().add( - new BoolSetting.Builder() - .name("Enable Notifications") - .description("Disable this to disable update notifications.") - .defaultValue(true) - .build() - ); - - private boolean notified = false; - private final String releaseUrl = "https://github.com/0xTas/stardust/releases/latest"; - - - @Nullable - public String fetchNewestVersionNumber() { - HttpURLConnection req; - try { - req = (HttpURLConnection) new URL(this.releaseUrl).openConnection(); - } catch (MalformedURLException err) { - Stardust.LOG.error("[Stardust] Failed to open http connection. Why:\n" + err); - return null; - } catch (Exception err) { - Stardust.LOG.error("[Stardust] Update Notifier failed to make a connection - "+err); - return null; - } - - req.setInstanceFollowRedirects(false); - try { - req.connect(); - }catch (Exception err) { - Stardust.LOG.error("[Stardust] Update Notifier failed to make a connection - "+err); - return null; - } - - Map> headerFields = req.getHeaderFields(); - if (headerFields.containsKey("Location")) { - List field = headerFields.get("Location"); - if (field.isEmpty()) { - Stardust.LOG.warn("[Stardust] Update Notifier failed to parse a response from Github."); - return null; - } else { - return field.get(0).substring(field.get(0).lastIndexOf("v")+1); - } - } - - return null; - } - - public void notifyUpdate(String newVersion) { - if (this.notified) return; - this.notified = true; - MeteorExecutor.execute(() -> { - try { - Thread.sleep(7000); - if (mc.player != null) { - Text txt = Text.of( - "§8<"+ StardustUtil.rCC() - +"§o✨§r§8> §7A new version of "+StardustUtil.rCC() - +"§oStardust §r§8(§o§2"+newVersion+"§r§8) §7is available." - ); - - Style style = Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("§7§oClick to open the Github page."))) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, releaseUrl)); - - MutableText notifyMessage = txt.copyContentOnly().setStyle(style); - mc.player.sendMessage(notifyMessage); - - } - } catch (Exception err) { - Stardust.LOG.warn("[Stardust] Update Notifier MeteorExecutor task was interrupted! Why:\n" + err); - } - }); - } - - - @EventHandler - private void onJoinGameEvent(GameJoinedEvent event) { - if (!this.notify.get() || this.notified) return; - - Optional mod = FabricLoader.getInstance().getModContainer("stardust"); - if (mod.isEmpty()) return; - - String version = mod.get().getMetadata().getVersion().getFriendlyString(); - String newVersion = fetchNewestVersionNumber(); - - if (newVersion == null) return; - if (version.trim().equals(newVersion.trim())) return; - notifyUpdate(newVersion); - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9627c5b..35e7c05 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,7 +21,8 @@ "stardust.mixins.json" ], "custom": { - "meteor-client:color": "147,233,190" + "meteor-client:color": "147,233,190", + "meteor-client:commit": "27691f9711223086cb2783b2b004c48f4c96214d" }, "depends": { "java": ">=17",