From f5b5148f82ea9c6f740470f891fd256588b16496 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:46:57 +0800 Subject: [PATCH] Use a record NewAndRemovedWorlds instead of generic tuple for clarity --- .../multiverse/core/world/WorldManager.java | 4 ++-- .../core/world/config/NewAndRemovedWorlds.java | 12 ++++++++++++ .../core/world/config/WorldsConfigManager.java | 8 ++++---- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/mvplugins/multiverse/core/world/config/NewAndRemovedWorlds.java diff --git a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java index a94e2f29..de522455 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java @@ -119,8 +119,8 @@ public class WorldManager { */ private Try updateWorldsFromConfig() { return worldsConfigManager.load().mapTry(result -> { - loadNewWorldConfigs(result._1()); - removeWorldsNotInConfigs(result._2()); + loadNewWorldConfigs(result.newWorlds()); + removeWorldsNotInConfigs(result.removedWorlds()); return null; }); } diff --git a/src/main/java/org/mvplugins/multiverse/core/world/config/NewAndRemovedWorlds.java b/src/main/java/org/mvplugins/multiverse/core/world/config/NewAndRemovedWorlds.java new file mode 100644 index 00000000..7f56bdf6 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/world/config/NewAndRemovedWorlds.java @@ -0,0 +1,12 @@ +package org.mvplugins.multiverse.core.world.config; + +import java.util.List; + +/** + * A record containing a list of the new WorldConfigs added and a list of the worlds removed from the config. + * + * @param newWorlds List of the new WorldConfigs added + * @param removedWorlds List of the worlds removed from the config + */ +public record NewAndRemovedWorlds(List newWorlds, List removedWorlds) { +} diff --git a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldsConfigManager.java b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldsConfigManager.java index 2bd1263f..e0cdaf91 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldsConfigManager.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldsConfigManager.java @@ -47,9 +47,9 @@ public final class WorldsConfigManager { /** * Loads the worlds.yml file and creates a WorldConfig for each world in the file if it doesn't already exist. * - * @return A tuple containing a list of the new WorldConfigs added and a list of the worlds removed from the config. + * @return A {@link NewAndRemovedWorlds} record. */ - public Try, List>> load() { + public Try load() { return Try.of(() -> { loadWorldYmlFile(); return parseNewAndRemovedWorlds(); @@ -116,7 +116,7 @@ public final class WorldsConfigManager { * * @return A tuple containing a list of the new WorldConfigs added and a list of the worlds removed from the config. */ - private Tuple2, List> parseNewAndRemovedWorlds() { + private NewAndRemovedWorlds parseNewAndRemovedWorlds() { Set allWorldsInConfig = worldsConfig.getKeys(false); List newWorldsAdded = new ArrayList<>(); @@ -141,7 +141,7 @@ public final class WorldsConfigManager { worldConfigMap.remove(s); } - return new Tuple2<>(newWorldsAdded, worldsRemoved); + return new NewAndRemovedWorlds(newWorldsAdded, worldsRemoved); } /**