Skip to content

Commit

Permalink
Use Optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix-Starlight committed Jan 11, 2024
1 parent c678ebb commit 8c7b7c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8c7b7c4

Please sign in to comment.