use the meteor built-in updater

(click on the name in title screen credits)
This commit is contained in:
C10udburst
2022-03-22 17:04:24 +01:00
parent fb9586c954
commit 47c46dfcf9
8 changed files with 26 additions and 76 deletions

View File

@@ -52,7 +52,7 @@ processResources {
expand "version": project.version expand "version": project.version
filter { line -> line.replace("@mc_version@", project.minecraft_version) } filter { line -> line.replace("@mc_version@", project.minecraft_version) }
filter { line -> line.replace("@gh_hash@", System.getenv("GITHUB_SHA") ?: "unknown") } filter { line -> line.replace("@gh_hash@", System.getenv("GITHUB_SHA") ?: "") }
} }
} }

View File

@@ -7,6 +7,7 @@ import anticope.rejects.modules.*;
import anticope.rejects.modules.modifier.NoRenderModifier; import anticope.rejects.modules.modifier.NoRenderModifier;
import anticope.rejects.utils.GiveUtils; import anticope.rejects.utils.GiveUtils;
import anticope.rejects.utils.RejectsUtils; import anticope.rejects.utils.RejectsUtils;
import meteordevelopment.meteorclient.addons.GithubRepo;
import meteordevelopment.meteorclient.addons.MeteorAddon; import meteordevelopment.meteorclient.addons.MeteorAddon;
import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.gui.GuiThemes; import meteordevelopment.meteorclient.gui.GuiThemes;
@@ -15,6 +16,7 @@ import meteordevelopment.meteorclient.systems.commands.Commands;
import meteordevelopment.meteorclient.systems.hud.HUD; import meteordevelopment.meteorclient.systems.hud.HUD;
import meteordevelopment.meteorclient.systems.modules.Category; import meteordevelopment.meteorclient.systems.modules.Category;
import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.Modules;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -106,4 +108,26 @@ public class MeteorRejectsAddon extends MeteorAddon {
public void onRegisterCategories() { public void onRegisterCategories() {
Modules.registerCategory(CATEGORY); Modules.registerCategory(CATEGORY);
} }
@Override
public String getWebsite() {
return "https://github.com/AntiCope/meteor-rejects";
}
@Override
public GithubRepo getRepo() {
return new GithubRepo("AntiCope", "meteor-rejects");
}
@Override
public String getCommit() {
String commit = FabricLoader
.getInstance()
.getModContainer("meteor-rejects")
.get().getMetadata()
.getCustomValue("github:sha")
.getAsString();
return commit.isEmpty() ? null : commit;
}
} }

View File

@@ -1,25 +0,0 @@
package anticope.rejects.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.util.math.MatrixStack;
import anticope.rejects.utils.RejectsConfig;
import anticope.rejects.utils.UpdateUtil;
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
@Mixin(value = TitleScreen.class)
public class TitleScreenMixin {
@Inject(method = "render", at = @At("TAIL"))
private void onRender(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
if (RejectsConfig.get().checkForUpdates) {
MeteorExecutor.execute(() -> {
UpdateUtil.checkUpdate();
});
}
}
}

View File

@@ -1,6 +1,5 @@
package anticope.rejects.utils; package anticope.rejects.utils;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.settings.EnumSetting;
import meteordevelopment.meteorclient.settings.ModuleListSetting; import meteordevelopment.meteorclient.settings.ModuleListSetting;
import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.Setting;
@@ -34,14 +33,6 @@ public class ConfigModifier {
.build() .build()
); );
public final Setting<Boolean> checkForUpdates = sgRejects.add(new BoolSetting.Builder()
.name("check-for-updates")
.description("Show toast on title screen when new update is available.")
.defaultValue(RejectsConfig.get().checkForUpdates)
.onChanged(v -> RejectsConfig.get().checkForUpdates = v)
.build()
);
public static ConfigModifier get() { public static ConfigModifier get() {
if (INSTANCE == null) INSTANCE = new ConfigModifier(); if (INSTANCE == null) INSTANCE = new ConfigModifier();
return INSTANCE; return INSTANCE;

View File

@@ -28,7 +28,6 @@ public class RejectsConfig extends System<RejectsConfig> {
} }
public HttpAllowed httpAllowed = HttpAllowed.Everything; public HttpAllowed httpAllowed = HttpAllowed.Everything;
public boolean checkForUpdates = true;
public Set<String> hiddenModules = new HashSet<String>(); public Set<String> hiddenModules = new HashSet<String>();
public RejectsConfig() { public RejectsConfig() {
@@ -67,7 +66,6 @@ public class RejectsConfig extends System<RejectsConfig> {
public NbtCompound toTag() { public NbtCompound toTag() {
NbtCompound tag = new NbtCompound(); NbtCompound tag = new NbtCompound();
tag.putString("httpAllowed", httpAllowed.toString()); tag.putString("httpAllowed", httpAllowed.toString());
tag.putBoolean("checkForUpdates", checkForUpdates);
NbtList modulesTag = new NbtList(); NbtList modulesTag = new NbtList();
for (String module : hiddenModules) modulesTag.add(NbtString.of(module)); for (String module : hiddenModules) modulesTag.add(NbtString.of(module));
@@ -79,7 +77,6 @@ public class RejectsConfig extends System<RejectsConfig> {
@Override @Override
public RejectsConfig fromTag(NbtCompound tag) { public RejectsConfig fromTag(NbtCompound tag) {
httpAllowed = HttpAllowed.valueOf(tag.getString("httpAllowed")); httpAllowed = HttpAllowed.valueOf(tag.getString("httpAllowed"));
checkForUpdates = !tag.contains("checkForUpdates") || tag.getBoolean("checkForUpdates");
NbtList valueTag = tag.getList("hiddenModules", 8); NbtList valueTag = tag.getList("hiddenModules", 8);
for (NbtElement tagI : valueTag) { for (NbtElement tagI : valueTag) {

View File

@@ -1,36 +0,0 @@
package anticope.rejects.utils;
import com.google.gson.JsonObject;
import net.minecraft.item.Items;
import net.fabricmc.loader.api.FabricLoader;
import anticope.rejects.MeteorRejectsAddon;
import meteordevelopment.meteorclient.utils.network.Http;
import meteordevelopment.meteorclient.utils.render.MeteorToast;
import static meteordevelopment.meteorclient.MeteorClient.mc;
public class UpdateUtil {
private static boolean firstTimeTitleScreen = true;
private static final String TAGNAME = "latest-1.18";
public static void checkUpdate() {
if (!firstTimeTitleScreen) return;
firstTimeTitleScreen = false;
MeteorRejectsAddon.LOG.info("Checking for Meteor Rejects update...");
String gitHash = FabricLoader
.getInstance()
.getModContainer("meteor-rejects")
.get().getMetadata()
.getCustomValue("updater:sha")
.getAsString().trim();
JsonObject tag = Http.get("https://api.github.com/repos/AntiCope/meteor-rejects/git/ref/tags/"+TAGNAME).sendJson(JsonObject.class);
if (tag.get("object").getAsJsonObject().get("sha").getAsString().trim().equals(gitHash)) return;
mc.getToastManager().add(new MeteorToast(Items.BARRIER, "New Rejects update.", "Download it from Github", 8000));
}
}

View File

@@ -32,7 +32,7 @@
], ],
"custom": { "custom": {
"meteor-client:color": "227,0,0", "meteor-client:color": "227,0,0",
"updater:sha": "@gh_hash@" "github:sha": "@gh_hash@"
}, },
"depends": { "depends": {
"java": ">=16", "java": ">=16",

View File

@@ -13,7 +13,6 @@
"LivingEntityRendererMixin", "LivingEntityRendererMixin",
"StructureVoidBlockMixin", "StructureVoidBlockMixin",
"ToastManagerMixin", "ToastManagerMixin",
"TitleScreenMixin",
"LivingEntityMixin", "LivingEntityMixin",
"baritone.MineProcessMixin" "baritone.MineProcessMixin"
], ],