Use a record NewAndRemovedWorlds instead of generic tuple for clarity

This commit is contained in:
Ben Woo 2024-11-21 09:46:57 +08:00
parent 1eeb265f4e
commit f5b5148f82
3 changed files with 18 additions and 6 deletions

View File

@ -119,8 +119,8 @@ public class WorldManager {
*/
private Try<Void> updateWorldsFromConfig() {
return worldsConfigManager.load().mapTry(result -> {
loadNewWorldConfigs(result._1());
removeWorldsNotInConfigs(result._2());
loadNewWorldConfigs(result.newWorlds());
removeWorldsNotInConfigs(result.removedWorlds());
return null;
});
}

View File

@ -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<WorldConfig> newWorlds, List<String> removedWorlds) {
}

View File

@ -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<Tuple2<List<WorldConfig>, List<String>>> load() {
public Try<NewAndRemovedWorlds> 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<WorldConfig>, List<String>> parseNewAndRemovedWorlds() {
private NewAndRemovedWorlds parseNewAndRemovedWorlds() {
Set<String> allWorldsInConfig = worldsConfig.getKeys(false);
List<WorldConfig> newWorldsAdded = new ArrayList<>();
@ -141,7 +141,7 @@ public final class WorldsConfigManager {
worldConfigMap.remove(s);
}
return new Tuple2<>(newWorldsAdded, worldsRemoved);
return new NewAndRemovedWorlds(newWorldsAdded, worldsRemoved);
}
/**