Skip to content

Commit 4ba009c

Browse files
authored
Merge pull request #587 from Multiverse/fix/uuid-parse
Softer error handling of invalid UUID
2 parents 809ed81 + 223e4e3 commit 4ba009c

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/main/java/org/mvplugins/multiverse/inventories/profile/FlatFileProfileDataSource.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.HashMap;
2626
import java.util.List;
2727
import java.util.Map;
28+
import java.util.Objects;
2829
import java.util.Set;
2930
import java.util.UUID;
3031
import java.util.concurrent.CompletableFuture;
@@ -403,7 +404,16 @@ public List<String> listPlayerProfileNames(ContainerType containerType, String c
403404
public List<UUID> listGlobalProfileUUIDs() {
404405
return profileFilesLocator.listGlobalFiles()
405406
.stream()
406-
.map(file -> UUID.fromString(com.google.common.io.Files.getNameWithoutExtension(file.getName())))
407+
.map(file -> {
408+
String fileName = com.google.common.io.Files.getNameWithoutExtension(file.getName());
409+
return Try.of(() -> UUID.fromString(fileName))
410+
.onFailure(throwable -> {
411+
Logging.warning("File name is not a valid UUID: %s", fileName);
412+
Logging.warning(throwable.getMessage());
413+
})
414+
.getOrNull();
415+
})
416+
.filter(Objects::nonNull)
407417
.toList();
408418
}
409419
}

src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerNamesMapper.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.mvplugins.multiverse.external.jakarta.inject.Provider;
1111
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
1212
import org.mvplugins.multiverse.external.vavr.control.Option;
13+
import org.mvplugins.multiverse.external.vavr.control.Try;
1314
import org.mvplugins.multiverse.inventories.MultiverseInventories;
1415
import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey;
1516

@@ -18,7 +19,6 @@
1819
import java.io.FileWriter;
1920
import java.util.List;
2021
import java.util.Map;
21-
import java.util.Objects;
2222
import java.util.UUID;
2323
import java.util.concurrent.CompletableFuture;
2424
import java.util.concurrent.ConcurrentHashMap;
@@ -83,13 +83,17 @@ private void loadFromPlayerNamesFile() {
8383
buildPlayerNamesMap();
8484
return;
8585
}
86-
playerNamesJson.forEach((String uuid, Object name) -> {
87-
UUID playerUUID = UUID.fromString(uuid);
88-
String playerName = String.valueOf(name);
89-
GlobalProfileKey globalProfileKey = GlobalProfileKey.of(playerUUID, playerName);
90-
playerNamesMap.put(playerName, globalProfileKey);
91-
playerUUIDMap.put(playerUUID, globalProfileKey);
92-
});
86+
playerNamesJson.forEach((String uuidStr, Object name) -> Try.of(() -> UUID.fromString(uuidStr))
87+
.onSuccess(uuid -> {
88+
String playerName = String.valueOf(name);
89+
GlobalProfileKey globalProfileKey = GlobalProfileKey.of(uuid, playerName);
90+
playerNamesMap.put(playerName, globalProfileKey);
91+
playerUUIDMap.put(uuid, globalProfileKey);
92+
})
93+
.onFailure(throwable -> {
94+
Logging.warning("Not a valid UUID: %s", uuidStr);
95+
Logging.warning(throwable.getMessage());
96+
}));
9397
} catch (Exception e) {
9498
e.printStackTrace();
9599
}

0 commit comments

Comments
 (0)