added update checker toast
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package anticope.rejects.utils;
|
||||
|
||||
import meteordevelopment.meteorclient.settings.BoolSetting;
|
||||
import meteordevelopment.meteorclient.settings.EnumSetting;
|
||||
import meteordevelopment.meteorclient.settings.ModuleListSetting;
|
||||
import meteordevelopment.meteorclient.settings.Setting;
|
||||
@@ -33,6 +34,14 @@ public class ConfigModifier {
|
||||
.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() {
|
||||
if (INSTANCE == null) INSTANCE = new ConfigModifier();
|
||||
return INSTANCE;
|
||||
|
||||
@@ -28,6 +28,7 @@ public class RejectsConfig extends System<RejectsConfig> {
|
||||
}
|
||||
|
||||
public HttpAllowed httpAllowed = HttpAllowed.Everything;
|
||||
public boolean checkForUpdates = true;
|
||||
public Set<String> hiddenModules = new HashSet<String>();
|
||||
|
||||
public RejectsConfig() {
|
||||
@@ -65,6 +66,7 @@ public class RejectsConfig extends System<RejectsConfig> {
|
||||
public NbtCompound toTag() {
|
||||
NbtCompound tag = new NbtCompound();
|
||||
tag.putString("httpAllowed", httpAllowed.toString());
|
||||
tag.putBoolean("checkForUpdates", checkForUpdates);
|
||||
|
||||
NbtList modulesTag = new NbtList();
|
||||
for (String module : hiddenModules) modulesTag.add(NbtString.of(module));
|
||||
@@ -76,6 +78,7 @@ public class RejectsConfig extends System<RejectsConfig> {
|
||||
@Override
|
||||
public RejectsConfig fromTag(NbtCompound tag) {
|
||||
httpAllowed = HttpAllowed.valueOf(tag.getString("httpAllowed"));
|
||||
checkForUpdates = !tag.contains("checkForUpdates") || tag.getBoolean("checkForUpdates");
|
||||
|
||||
NbtList valueTag = tag.getList("hiddenModules", 8);
|
||||
for (NbtElement tagI : valueTag) {
|
||||
|
||||
36
src/main/java/anticope/rejects/utils/UpdateUtil.java
Normal file
36
src/main/java/anticope/rejects/utils/UpdateUtil.java
Normal file
@@ -0,0 +1,36 @@
|
||||
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() == gitHash) return;
|
||||
|
||||
mc.getToastManager().add(new MeteorToast(Items.BARRIER, "New Rejects update.", "Download it from Github", 8000));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class Seeds extends System<Seeds> {
|
||||
try {
|
||||
return Long.parseLong(inSeed);
|
||||
} catch (NumberFormatException e) {
|
||||
return inSeed.hashCode();
|
||||
return inSeed.strip().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user