Skip to content

Commit

Permalink
Updated Update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterCheezeCake committed Nov 17, 2024
1 parent 24704c8 commit 29bde20
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class SkyblockTweaks implements ModInitializer {
@Override
public void onInitialize() {

MigrationManager.handleMigrations();
//MigrationManager.handleMigrations();


SBTConfig.HANDLER.load();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/wtf/cheeze/sbt/command/SBTCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.MinecraftVersion;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
Expand Down Expand Up @@ -333,6 +334,19 @@ public static void registerEvents() {
return 1;
}))

.then(literal("sysInfo").executes(context -> {
var source = context.getSource();
source.sendFeedback(Text.literal(PREFIX + " §3System Information"));
source.sendFeedback(getDebugText("Minecraft Version", MinecraftVersion.CURRENT.getName()));
source.sendFeedback(getDebugText("Operating System", System.getProperty("os.name")));
source.sendFeedback(getDebugText("OS Version", System.getProperty("os.version")));
source.sendFeedback(getDebugText("Architecture", System.getProperty("os.arch")));
source.sendFeedback(getDebugText("Java Version", System.getProperty("java.version")));
source.sendFeedback(getDebugText("Java Vendor", System.getProperty("java.vendor")));
return 1;

}))


.then(literal("dumpComponents")
.then(literal("hand")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package wtf.cheeze.sbt.config.migration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wtf.cheeze.sbt.SkyblockTweaks;
import wtf.cheeze.sbt.config.ConfigImpl;
import wtf.cheeze.sbt.config.SBTConfig;
Expand Down Expand Up @@ -50,7 +48,7 @@ public static void handleMigrations() {
}

} catch (Exception e) {
e.printStackTrace();
SkyblockTweaks.LOGGER.error("Failed to handle migrations", e);
}

}
Expand All @@ -61,15 +59,15 @@ public static void handleMigrations() {
*/
@SuppressWarnings("unchecked")
public static <T extends ConfigImpl> void runTransformation(ConfigTransformation<T> transformation) {
SkyblockTweaks.LOGGER.info("Checking config transformation: " + transformation.getClass().getSimpleName());
//SkyblockTweaks.LOGGER.info("Checking config transformation: " + transformation.getClass().getSimpleName());
T currentConfig = (T) SBTConfig.get();
SkyblockTweaks.LOGGER.info("Current config version: " + currentConfig.configVersion);
//SkyblockTweaks.LOGGER.info("Current config version: " + currentConfig.configVersion);
if (!transformation.isApplicable(currentConfig.configVersion)) {
SkyblockTweaks.LOGGER.info("Transformation not applicable for version");
//SkyblockTweaks.LOGGER.info("Transformation not applicable for version");
return;
}
if (!transformation.isApplicable(currentConfig)) {
SkyblockTweaks.LOGGER.info("Transformation not applicable for config");
//SkyblockTweaks.LOGGER.info("Transformation not applicable for config");
return;
}
SkyblockTweaks.LOGGER.info("Running config transformation: " + transformation.getClass().getSimpleName());
Expand Down
1 change: 0 additions & 1 deletion src/main/java/wtf/cheeze/sbt/utils/HTTPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static String get(String uri){
try {
// URL url = new URL(uri);
URL url = new URI(uri).toURL();

var connection = url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 SkyblockTweaks " + SkyblockTweaks.VERSION.getVersionString());
var reader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/wtf/cheeze/sbt/utils/NotificationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.text.Text;
import wtf.cheeze.sbt.SkyblockTweaks;

import java.util.ArrayList;

Expand All @@ -34,7 +35,7 @@ public static void registerEvents() {
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
SkyblockTweaks.LOGGER.error("Notification manager failed to sleep thread", e);
}
client.execute(() -> {
for (Text message : NOTIFICATION_QUEUE) {
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/wtf/cheeze/sbt/utils/NumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package wtf.cheeze.sbt.utils;

import org.jetbrains.annotations.NotNull;

public class NumberUtils {
public static double round(float number, int decimalPlaces) {
return Math.round(number * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces);
Expand Down Expand Up @@ -61,10 +63,20 @@ public static float parseFloatWithKorM(String text) {

public static String formatNumber(int number, String separator) {
String str = Integer.toString(number);
return formatNumber(str, separator);
}

public static String formatNumber(long number, String separator) {
String str = Long.toString(number);
return formatNumber(str, separator);
}


private static String formatNumber(String numString, String separator) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
sb.append(str.charAt(i));
if ((str.length() - i - 1) % 3 == 0 && i != str.length() - 1) {
for (int i = 0; i < numString.length(); i++) {
sb.append(numString.charAt(i));
if ((numString.length() - i - 1) % 3 == 0 && i != numString.length() - 1) {
sb.append(separator);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/wtf/cheeze/sbt/utils/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package wtf.cheeze.sbt.utils;

import net.minecraft.MinecraftVersion;
import wtf.cheeze.sbt.SkyblockTweaks;
import wtf.cheeze.sbt.config.SBTConfig;
import wtf.cheeze.sbt.utils.Version.NotificationStream;
Expand All @@ -41,19 +42,19 @@ public static void checkForUpdates() {
break;
}

internalRun(remote.latestAlpha.get(SkyblockTweaks.mc.getGameVersion()));
internalRun(remote.latestAlpha.get(MinecraftVersion.CURRENT.getName()));
}
case NotificationStream.BETA -> {
if (remote.latestBeta == null) {
break;
}
internalRun(remote.latestBeta.get(SkyblockTweaks.mc.getGameVersion()));
internalRun(remote.latestBeta.get(MinecraftVersion.CURRENT.getName()));
}
case NotificationStream.RELEASE -> {
if (remote.latestRelease == null) {
break;
}
internalRun(remote.latestRelease.get(SkyblockTweaks.mc.getGameVersion()));
internalRun(remote.latestRelease.get(MinecraftVersion.CURRENT.getName()));
}
}
}
Expand All @@ -65,7 +66,10 @@ public static void checkForUpdates() {
}

private static void internalRun(Version.RemoteVersion remoteVersion) {
if (remoteVersion == null) return;
if (remoteVersion == null) {
SkyblockTweaks.LOGGER.warn("Null RemoteVersion");
return;
};
var version = new Version(remoteVersion.versionString);
var comparison = Version.compareVersions(version, SkyblockTweaks.VERSION);
if (comparison == Version.VersionComparison.GREATER) {
Expand Down
82 changes: 42 additions & 40 deletions src/main/java/wtf/cheeze/sbt/utils/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@
public class Version {
public static Pattern PATTERN_RELEASE = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)$");
public static Pattern PATTERN_ALPHA_BETA = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)-(Alpha|Beta)\\.(\\d+)$");
public static enum VersionType {
// Development versions, ideally, a user should never be using these
UNSTABLE,
// Alpha versions, these are the least stable jars that will go out to users, and may have bugs
ALPHA,
// Beta versions, more stable than alpha, but still may have bugs and not ready for full release
BETA,
// Full releases, stable and ideally not released with any known bugs
RELEASE
}

public VersionType STREAM;
public int MAJOR;
Expand Down Expand Up @@ -106,25 +96,6 @@ public String getVersionString() {
}
}

public static class RemoteVersionFile {
public boolean enabled;
public Map<String, RemoteVersion> latestAlpha;
public Map<String, RemoteVersion> latestBeta;
public Map<String, RemoteVersion> latestRelease;
}

public static class RemoteVersion {
public String versionString;
public String modrinthName;
}

public static enum VersionComparison {
EQUAL,
GREATER,
LESS,
FAILURE
}

public static VersionComparison compareVersions(Version a, Version b) {
try {
if (a.STREAM == VersionType.UNSTABLE || b.STREAM == VersionType.UNSTABLE) {
Expand Down Expand Up @@ -163,19 +134,9 @@ public static VersionComparison compareVersions(Version a, Version b) {
}
}

public static enum NotificationStream implements NameableEnum {
ALPHA,
BETA,
RELEASE,
NONE;

@Override
public Text getDisplayName() {
return Text.literal(name());
}
}

public static Option getStreamOption(ConfigImpl defaults, ConfigImpl config) {
public static Option<NotificationStream> getStreamOption(ConfigImpl defaults, ConfigImpl config) {
return Option.<NotificationStream>createBuilder()
.name(General.key("notificationStream"))
.description(General.keyD("notificationStream"))
Expand All @@ -190,4 +151,45 @@ public static Option getStreamOption(ConfigImpl defaults, ConfigImpl config) {
public static String getModrinthLink(String name) {
return "https://modrinth.com/mod/sbt/version/" + name;
}

public enum VersionType {
// Development versions, ideally, a user should never be using these
UNSTABLE,
// Alpha versions, these are the least stable jars that will go out to users, and may have bugs
ALPHA,
// Beta versions, more stable than alpha, but still may have bugs and not ready for full release
BETA,
// Full releases, stable and ideally not released with any known bugs
RELEASE
}
public enum NotificationStream implements NameableEnum {
ALPHA,
BETA,
RELEASE,
NONE;

@Override
public Text getDisplayName() {
return Text.literal(name());
}
}

public enum VersionComparison {
EQUAL,
GREATER,
LESS,
FAILURE
}

public static class RemoteVersionFile {
public boolean enabled;
public Map<String, RemoteVersion> latestAlpha;
public Map<String, RemoteVersion> latestBeta;
public Map<String, RemoteVersion> latestRelease;
}

public static class RemoteVersion {
public String versionString;
public String modrinthName;
}
}
2 changes: 0 additions & 2 deletions src/main/java/wtf/cheeze/sbt/utils/skyblock/QuiverData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import net.minecraft.component.type.LoreComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import wtf.cheeze.sbt.SkyblockTweaks;
import wtf.cheeze.sbt.features.huds.QuiverHUD;

import java.util.regex.Pattern;

Expand Down
2 changes: 1 addition & 1 deletion versions/1.21.3/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fabric_version=0.107.0+1.21.3
modmenu_version=12.0.0-beta.1
yacl_version=3.6.1+1.21.2-fabric
hmapi_version=1.0.1+1.21.2
yarn_mappings=1.21.2+build.1
yarn_mappings=1.21.3+build.2

0 comments on commit 29bde20

Please sign in to comment.