Skip to content

Commit

Permalink
Refactor PaperLevelView mapping to handle empty optionals
Browse files Browse the repository at this point in the history
Remove redundant orElse calls and streamline the mapping process by directly handling empty optionals. This enhancement ensures that null values are only applied if all optional fields are empty, improving code readability and efficiency.
  • Loading branch information
NonSwag committed Aug 15, 2024
1 parent 4f0d112 commit 91a13ec
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,14 @@ public Optional<LevelExtras> getExtras(CompoundTag data) {
.map(values -> {
var key = values.optional("worlds:world_key")
.map(Tag::getAsString)
.map(NamespacedKey::fromString)
.orElse(null);
.map(NamespacedKey::fromString);
var generator = values.optional("worlds:generator")
.map(Tag::getAsString)
.map(serialized -> Generator.deserialize(plugin, serialized))
.orElse(null);
.map(serialized -> Generator.deserialize(plugin, serialized));
var enabled = values.optional("worlds:enabled")
.map(Tag::getAsBoolean)
.orElse(false);
return new LevelExtras(key, generator, enabled);
.map(Tag::getAsBoolean);
if (key.isEmpty() && generator.isEmpty() && enabled.isEmpty()) return null;
return new LevelExtras(key.orElse(null), generator.orElse(null), enabled.orElse(false));
});
}

Expand Down

0 comments on commit 91a13ec

Please sign in to comment.