diff --git a/common/src/main/java/fi/fabianadrian/proxychat/common/ProxyChat.java b/common/src/main/java/fi/fabianadrian/proxychat/common/ProxyChat.java index 2a79e42..f409ad6 100644 --- a/common/src/main/java/fi/fabianadrian/proxychat/common/ProxyChat.java +++ b/common/src/main/java/fi/fabianadrian/proxychat/common/ProxyChat.java @@ -111,7 +111,7 @@ public void handleDisconnect(UUID uuid) { } public void shutdown() { - this.nameService.save(); + } public UserManager userManager() { diff --git a/common/src/main/java/fi/fabianadrian/proxychat/common/service/NameService.java b/common/src/main/java/fi/fabianadrian/proxychat/common/service/NameService.java index 1d5f9f0..628dddf 100644 --- a/common/src/main/java/fi/fabianadrian/proxychat/common/service/NameService.java +++ b/common/src/main/java/fi/fabianadrian/proxychat/common/service/NameService.java @@ -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 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); } @@ -44,6 +44,7 @@ public Optional resolve(UUID uuid) { public void update(User user) { this.nameMap.put(user.uuid(), user.name()); + save(); } public void save() {