From 91a13ec5f78f0718612e1f6fbc1e69f52a1474b7 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 15 Aug 2024 21:49:13 +0200 Subject: [PATCH] Refactor PaperLevelView mapping to handle empty optionals 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. --- .../net/thenextlvl/worlds/view/PaperLevelView.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/net/thenextlvl/worlds/view/PaperLevelView.java b/plugin/src/main/java/net/thenextlvl/worlds/view/PaperLevelView.java index a8a1795..e4185a9 100644 --- a/plugin/src/main/java/net/thenextlvl/worlds/view/PaperLevelView.java +++ b/plugin/src/main/java/net/thenextlvl/worlds/view/PaperLevelView.java @@ -164,16 +164,14 @@ public Optional 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)); }); }