[Feature] Update Checker
This commit is contained in:
parent
2ef9e51ef1
commit
69d472d107
21 changed files with 633 additions and 22 deletions
|
@ -26,7 +26,7 @@ public class BiomesConfig extends PathConfig {
|
|||
private static final BiomeAPI.BiomeType[] excludeTypes = {BiomeAPI.BiomeType.NETHER, BiomeAPI.BiomeType.END};
|
||||
|
||||
public BiomesConfig() {
|
||||
super(BCLib.MOD_ID, "biomes", false);
|
||||
super(BCLib.MOD_ID, "biomes", true);
|
||||
for (var type : includeTypes) {
|
||||
keeper.registerEntry(
|
||||
new ConfigKey(type.getName(), "force_include"),
|
||||
|
|
58
src/main/java/org/betterx/bclib/config/CachedConfig.java
Normal file
58
src/main/java/org/betterx/bclib/config/CachedConfig.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package org.betterx.bclib.config;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.networking.VersionChecker;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Base64;
|
||||
|
||||
public class CachedConfig extends NamedPathConfig {
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<String> LAST_CHECK_DATE = ConfigToken.String(
|
||||
"never",
|
||||
"last",
|
||||
"version"
|
||||
);
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<String> LAST_JSON = ConfigToken.String(
|
||||
"",
|
||||
"cached",
|
||||
"version"
|
||||
);
|
||||
|
||||
public CachedConfig() {
|
||||
super(BCLib.MOD_ID, "cache", false, false);
|
||||
}
|
||||
|
||||
public String lastVersionJson() {
|
||||
byte[] decodedBytes = Base64.getUrlDecoder().decode(get(LAST_JSON));
|
||||
return new String(decodedBytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void setLastVersionJson(String json) {
|
||||
set(LAST_JSON, Base64.getUrlEncoder().encodeToString(json.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
public Instant lastCheckDate() {
|
||||
String d = get(LAST_CHECK_DATE);
|
||||
if (d.trim().toLowerCase().equals("never")) {
|
||||
return Instant.now().minus(VersionChecker.WAIT_FOR_DAYS + 1, ChronoUnit.DAYS);
|
||||
}
|
||||
return Instant.parse(d);
|
||||
}
|
||||
|
||||
public void setLastCheckDate() {
|
||||
set(LAST_CHECK_DATE, Instant.now().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges() {
|
||||
synchronized (this) {
|
||||
super.saveChanges();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,11 +31,10 @@ public class ClientConfig extends NamedPathConfig {
|
|||
);
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final DependendConfigToken<Boolean> ACCEPT_MODS = DependendConfigToken.Boolean(
|
||||
false,
|
||||
true,
|
||||
"acceptMods",
|
||||
AutoSync.SYNC_CATEGORY,
|
||||
(config) -> config.get(
|
||||
ENABLED)
|
||||
(config) -> config.get(ENABLED)
|
||||
);
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final DependendConfigToken<Boolean> DISPLAY_MOD_INFO = DependendConfigToken.Boolean(
|
||||
|
@ -72,6 +71,19 @@ public class ClientConfig extends NamedPathConfig {
|
|||
"rendering"
|
||||
);
|
||||
|
||||
public static final ConfigToken<Boolean> SHOW_UPDATE_INFO = ConfigToken.Boolean(
|
||||
true,
|
||||
"showUpdateInfo",
|
||||
"ui"
|
||||
);
|
||||
|
||||
@ConfigUI(leftPadding = 8)
|
||||
public static final ConfigToken<Boolean> NO_DONOR = ConfigToken.Boolean(
|
||||
false,
|
||||
"no_donor",
|
||||
"version"
|
||||
);
|
||||
|
||||
public ClientConfig() {
|
||||
super(BCLib.MOD_ID, "client", false);
|
||||
}
|
||||
|
@ -112,6 +124,14 @@ public class ClientConfig extends NamedPathConfig {
|
|||
return get(CUSTOM_FOG_RENDERING);
|
||||
}
|
||||
|
||||
public boolean showUpdateInfo() {
|
||||
return get(SHOW_UPDATE_INFO);
|
||||
}
|
||||
|
||||
public boolean isDonor() {
|
||||
return !get(NO_DONOR);
|
||||
}
|
||||
|
||||
public float fogDensity() {
|
||||
return get(FOG_DENSITY);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class Configs {
|
|||
|
||||
public static final GeneratorConfig GENERATOR_CONFIG = new GeneratorConfig();
|
||||
public static final MainConfig MAIN_CONFIG = new MainConfig();
|
||||
public static final CachedConfig CACHED_CONFIG = new CachedConfig();
|
||||
|
||||
public static final PathConfig RECIPE_CONFIG = new PathConfig(BCLib.MOD_ID, "recipes");
|
||||
public static final BiomesConfig BIOMES_CONFIG = new BiomesConfig();
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.betterx.bclib.BCLib;
|
|||
|
||||
public class GeneratorConfig extends NamedPathConfig {
|
||||
public GeneratorConfig() {
|
||||
super(BCLib.MOD_ID, "generator", false);
|
||||
super(BCLib.MOD_ID, "generator", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,22 @@ public class MainConfig extends NamedPathConfig {
|
|||
APPLY_PATCHES)
|
||||
);
|
||||
|
||||
|
||||
@ConfigUI(hide = true)
|
||||
public static final ConfigToken<Boolean> DID_SHOW_WELCOME = ConfigToken.Boolean(
|
||||
false,
|
||||
"did_show_welcome",
|
||||
"version"
|
||||
);
|
||||
|
||||
public static final ConfigToken<Boolean> CHECK_VERSIONS = DependendConfigToken.Boolean(
|
||||
true,
|
||||
"check",
|
||||
"version",
|
||||
(config) -> !config.get(DID_SHOW_WELCOME)
|
||||
);
|
||||
|
||||
|
||||
public MainConfig() {
|
||||
super(BCLib.MOD_ID, "main", true, true);
|
||||
}
|
||||
|
@ -29,4 +45,21 @@ public class MainConfig extends NamedPathConfig {
|
|||
public boolean repairBiomes() {
|
||||
return get(REPAIR_BIOMES);
|
||||
}
|
||||
|
||||
public boolean checkVersions() {
|
||||
return get(CHECK_VERSIONS);
|
||||
}
|
||||
|
||||
public boolean didShowWelcomeScreen() {
|
||||
return get(DID_SHOW_WELCOME);
|
||||
}
|
||||
|
||||
public void setDidShowWelcomeScreen() {
|
||||
set(DID_SHOW_WELCOME, true);
|
||||
}
|
||||
|
||||
|
||||
public void setCheckVersions(boolean newValue) {
|
||||
set(CHECK_VERSIONS, newValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@ public class ServerConfig extends NamedPathConfig {
|
|||
true,
|
||||
"offerConfigs",
|
||||
AutoSync.SYNC_CATEGORY,
|
||||
(config) -> config.get(
|
||||
ENABLED)
|
||||
(config) -> config.get(ENABLED)
|
||||
);
|
||||
public static final DependendConfigToken<Boolean> OFFER_FILES = DependendConfigToken.Boolean(
|
||||
true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue