Skip to content

Commit

Permalink
fix NameService
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmakila committed May 6, 2024
1 parent 24e76e9 commit e8dddef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void handleDisconnect(UUID uuid) {
}

public void shutdown() {
this.nameService.save();

}

public UserManager userManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public NameService(ProxyChat proxyChat) {
}

public void reload() {
if (!Files.exists(this.databasePath)) {
this.nameMap.clear();
return;
}

try (BufferedReader reader = Files.newBufferedReader(this.databasePath)) {
this.nameMap = this.gson.fromJson(reader, new TypeToken<>() {});
Map<UUID, String> mapFromJson = this.gson.fromJson(reader, new TypeToken<>() {});
if (mapFromJson == null) {
return;
}

this.nameMap = mapFromJson;
} catch (Exception e) {
this.proxyChat.platform().logger().warn("Failed to load usernames.json", e);
}
Expand All @@ -44,6 +44,7 @@ public Optional<String> resolve(UUID uuid) {

public void update(User user) {
this.nameMap.put(user.uuid(), user.name());
save();
}

public void save() {
Expand Down

0 comments on commit e8dddef

Please sign in to comment.