diff --git a/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java b/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java index c7a51e0fe..fafe752a7 100644 --- a/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java +++ b/fabric/src/main/java/org/embeddedt/modernfix/platform/fabric/ModernFixPlatformHooksImpl.java @@ -38,13 +38,11 @@ public boolean isDedicatedServer() { return FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER; } - private static String verString; + private static final String verString = FabricLoader.getInstance().getModContainer("modernfix") + .map(mfModContainer -> mfModContainer.getMetadata().getVersion().getFriendlyString()) + .orElse("[unknown]"); public String getVersionString() { - if(verString == null) { - ModContainer mfModContainer = FabricLoader.getInstance().getModContainer("modernfix").get(); - verString = mfModContainer.getMetadata().getVersion().getFriendlyString(); - } return verString; } diff --git a/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java b/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java index fb896bf55..0d4d082d2 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java +++ b/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java @@ -68,17 +68,11 @@ public boolean isDedicatedServer() { return FMLLoader.getDist().isDedicatedServer(); } - private static String verString; + private static final String verString = Optional.ofNullable( + ModernFixMixinPlugin.class.getPackage().getImplementationVersion()) + .orElse("[unknown]"); public String getVersionString() { - if(verString == null) { - try { - verString = ModernFixMixinPlugin.class.getPackage().getImplementationVersion(); - Objects.requireNonNull(verString); - } catch(Throwable e) { - verString = "[unknown]"; - } - } return verString; }