diff --git a/src/main/java/org/mvplugins/multiverse/inventories/profile/FlatFileProfileDataSource.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/FlatFileProfileDataSource.java index 1b20796a..c3ccccc2 100644 --- a/src/main/java/org/mvplugins/multiverse/inventories/profile/FlatFileProfileDataSource.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/FlatFileProfileDataSource.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -403,7 +404,16 @@ public List listPlayerProfileNames(ContainerType containerType, String c public List listGlobalProfileUUIDs() { return profileFilesLocator.listGlobalFiles() .stream() - .map(file -> UUID.fromString(com.google.common.io.Files.getNameWithoutExtension(file.getName()))) + .map(file -> { + String fileName = com.google.common.io.Files.getNameWithoutExtension(file.getName()); + return Try.of(() -> UUID.fromString(fileName)) + .onFailure(throwable -> { + Logging.warning("File name is not a valid UUID: %s", fileName); + Logging.warning(throwable.getMessage()); + }) + .getOrNull(); + }) + .filter(Objects::nonNull) .toList(); } } diff --git a/src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerNamesMapper.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerNamesMapper.java index f6397134..76ab705b 100644 --- a/src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerNamesMapper.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerNamesMapper.java @@ -10,6 +10,7 @@ import org.mvplugins.multiverse.external.jakarta.inject.Provider; import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.external.vavr.control.Option; +import org.mvplugins.multiverse.external.vavr.control.Try; import org.mvplugins.multiverse.inventories.MultiverseInventories; import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey; @@ -18,7 +19,6 @@ import java.io.FileWriter; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -83,13 +83,17 @@ private void loadFromPlayerNamesFile() { buildPlayerNamesMap(); return; } - playerNamesJson.forEach((String uuid, Object name) -> { - UUID playerUUID = UUID.fromString(uuid); - String playerName = String.valueOf(name); - GlobalProfileKey globalProfileKey = GlobalProfileKey.of(playerUUID, playerName); - playerNamesMap.put(playerName, globalProfileKey); - playerUUIDMap.put(playerUUID, globalProfileKey); - }); + playerNamesJson.forEach((String uuidStr, Object name) -> Try.of(() -> UUID.fromString(uuidStr)) + .onSuccess(uuid -> { + String playerName = String.valueOf(name); + GlobalProfileKey globalProfileKey = GlobalProfileKey.of(uuid, playerName); + playerNamesMap.put(playerName, globalProfileKey); + playerUUIDMap.put(uuid, globalProfileKey); + }) + .onFailure(throwable -> { + Logging.warning("Not a valid UUID: %s", uuidStr); + Logging.warning(throwable.getMessage()); + })); } catch (Exception e) { e.printStackTrace(); }