From 381998c35c048e4284771d74137e6db5147c716a Mon Sep 17 00:00:00 2001 From: Paint_Ninja Date: Fri, 19 Apr 2024 21:39:23 +0100 Subject: [PATCH] Fix early window crash when parsing some forms of options.txt (#9933) --- .../fml/earlydisplay/DisplayWindow.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fmlearlydisplay/src/main/java/net/minecraftforge/fml/earlydisplay/DisplayWindow.java b/fmlearlydisplay/src/main/java/net/minecraftforge/fml/earlydisplay/DisplayWindow.java index 1f6004b4fd..06d33b6d3c 100644 --- a/fmlearlydisplay/src/main/java/net/minecraftforge/fml/earlydisplay/DisplayWindow.java +++ b/fmlearlydisplay/src/main/java/net/minecraftforge/fml/earlydisplay/DisplayWindow.java @@ -29,7 +29,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.URI; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -76,7 +76,7 @@ public class DisplayWindow implements ImmediateWindowProvider { private static final Logger LOGGER = LoggerFactory.getLogger("EARLYDISPLAY"); private final AtomicBoolean animationTimerTrigger = new AtomicBoolean(true); - private ColourScheme colourScheme; + private ColourScheme colourScheme = ColourScheme.RED; private ElementShader elementShader; private RenderElement.DisplayContext context; @@ -135,13 +135,17 @@ public class DisplayWindow implements ImmediateWindowProvider { this.colourScheme = ColourScheme.BLACK; } else { try { - var optionLines = Files.readAllLines(FMLPaths.GAMEDIR.get().resolve(Paths.get("options.txt"))); - var options = optionLines.stream().map(l -> l.split(":")).filter(a -> a.length == 2).collect(Collectors.toMap(a -> a[0], a -> a[1])); - var colourScheme = Boolean.parseBoolean(options.getOrDefault("darkMojangStudiosBackground", "false")); - this.colourScheme = colourScheme ? ColourScheme.BLACK : ColourScheme.RED; - } catch (IOException ioe) { - // No options - this.colourScheme = ColourScheme.RED; // default to red colourscheme + // check the options file for the colour scheme + var optionLines = Files.readAllLines(FMLPaths.GAMEDIR.get().resolve(Path.of("options.txt"))); + var keyName = "darkMojangStudiosBackground:"; + for (String line : optionLines) { + if (line.startsWith(keyName)) { + this.colourScheme = line.startsWith("true", keyName.length()) ? ColourScheme.BLACK : ColourScheme.RED; + break; + } + } + } catch (IOException e) { + this.colourScheme = ColourScheme.RED; // fallback to red colourScheme } } this.maximized = parsed.has(maximizedopt) || FMLConfig.getBoolConfigValue(FMLConfig.ConfigValue.EARLY_WINDOW_MAXIMIZED);