diff --git a/src/main/java/de/teamlapen/vampirism/misc/SettingsProvider.java b/src/main/java/de/teamlapen/vampirism/misc/SettingsProvider.java index 81775cc19..57843fad7 100644 --- a/src/main/java/de/teamlapen/vampirism/misc/SettingsProvider.java +++ b/src/main/java/de/teamlapen/vampirism/misc/SettingsProvider.java @@ -23,6 +23,7 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.time.Duration; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -38,7 +39,7 @@ public class SettingsProvider implements ISettingsProvider { public SettingsProvider(String baseUrl) { this.baseUrl = baseUrl; - this.client = HttpClient.newHttpClient(); + this.client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).executor(Util.nonCriticalIoPool()).build(); } @Override @@ -98,7 +99,7 @@ private Optional> checkSettings(Map settings if (error != null) { LOGGER.error("Failed to retrieve settings from server", error); } - if (VampirismMod.inDev || settings != null) { + if (VampirismMod.inDev || settings == null) { InputStream inputStream = VampirismMod.class.getResourceAsStream("/default_remote_config.json"); if (inputStream != null) { try { @@ -115,16 +116,16 @@ private Optional> checkSupporter(Collection fil if (error != null) { LOGGER.error("Failed to retrieve supporter from server", error); } - if (VampirismMod.inDev || file != null) { - InputStream inputStream = VampirismMod.class.getResourceAsStream("/supporters.json"); - if (inputStream != null) { - try { - List list = GSON.fromJson(new JsonReader(new InputStreamReader(inputStream)), TypeToken.getParameterized(List.class, Supporter.class).getType()); - return Optional.of(list); - } catch (JsonSyntaxException ex) { - LOGGER.error("Failed to retrieve supporter from file", ex); + if (VampirismMod.inDev || file == null) { + InputStream inputStream = VampirismMod.class.getResourceAsStream("/supporters.json"); + if (inputStream != null) { + try { + List list = GSON.fromJson(new JsonReader(new InputStreamReader(inputStream)), TypeToken.getParameterized(List.class, Supporter.class).getType()); + return Optional.of(list); + } catch (JsonSyntaxException ex) { + LOGGER.error("Failed to retrieve supporter from file", ex); + } } - } } return Optional.ofNullable(file); } diff --git a/src/main/java/de/teamlapen/vampirism/util/TelemetryCollector.java b/src/main/java/de/teamlapen/vampirism/util/TelemetryCollector.java index 5f63ce9b6..ceb7069e0 100644 --- a/src/main/java/de/teamlapen/vampirism/util/TelemetryCollector.java +++ b/src/main/java/de/teamlapen/vampirism/util/TelemetryCollector.java @@ -5,8 +5,10 @@ import net.minecraft.DetectedVersion; import net.minecraft.Util; import net.minecraft.client.Minecraft; +import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.LogicalSide; import net.neoforged.fml.ModList; +import net.neoforged.fml.loading.FMLEnvironment; import net.neoforged.fml.util.thread.EffectiveSide; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -35,7 +37,7 @@ public static void execute() { } private static void send() { - try(var http = HttpClient.newBuilder().executor(Util.nonCriticalIoPool()).build()) { + try(var http = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).executor(Util.nonCriticalIoPool()).build()) { StringBuilder builder = new StringBuilder(); builder.append(REFERENCE.SETTINGS_API); builder.append("/telemetry/basic"); @@ -44,12 +46,12 @@ private static void send() { params.put("mod_version", REFERENCE.VERSION.toString()); params.put("mc_version", DetectedVersion.BUILT_IN.getName()); params.put("mod_count", Integer.toString(ModList.get().size())); - params.put("side", (EffectiveSide.get() == LogicalSide.CLIENT ? "client" : "server")); + params.put("side", (FMLEnvironment.dist == Dist.CLIENT ? "client" : "server")); builder.append("?"); builder.append(params.entrySet().stream().map(s -> s.getKey() + "=" + URLEncoder.encode(s.getValue(), StandardCharsets.UTF_8)).collect(Collectors.joining("&"))); - http.sendAsync(HttpRequest.newBuilder().uri(new URI(builder.toString())).timeout(Duration.ofSeconds(5)).build(), HttpResponse.BodyHandlers.ofString()); + http.sendAsync(HttpRequest.newBuilder().uri(new URI(builder.toString())).build(), HttpResponse.BodyHandlers.ofString()); } catch (URISyntaxException e) { LOGGER.error("Failed to send telemetry data", e); }