diff --git a/src/client/java/pl/lordtricker/ltrynek/client/command/ClientCommandRegistration.java b/src/client/java/pl/lordtricker/ltrynek/client/command/ClientCommandRegistration.java index ff2e5b7..c6b8ae5 100644 --- a/src/client/java/pl/lordtricker/ltrynek/client/command/ClientCommandRegistration.java +++ b/src/client/java/pl/lordtricker/ltrynek/client/command/ClientCommandRegistration.java @@ -115,6 +115,9 @@ private static void registerLtrynekCommand( "profile", activeProfile )); ctx.getSource().sendFeedback(ColorUtils.translateColorCodes(msg)); + + // Auto-save config after adding item + autoSaveConfig(); } catch (NumberFormatException e) { ctx.getSource().sendError(Text.literal("Invalid price format: " + maxPriceStr)); } @@ -137,6 +140,9 @@ private static void registerLtrynekCommand( "profile", activeProfile )); ctx.getSource().sendFeedback(ColorUtils.translateColorCodes(msg)); + + // Auto-save config after removing item + autoSaveConfig(); return 1; }) ) @@ -227,9 +233,7 @@ private static void registerLtrynekCommand( .then(ClientCommandManager.literal("config") .then(ClientCommandManager.literal("save") .executes(ctx -> { - syncMemoryToConfig(); - - ConfigLoader.saveConfig(LtrynekClient.serversConfig); + autoSaveConfig(); String msg = Messages.get("command.config.save.success"); ctx.getSource().sendFeedback(ColorUtils.translateColorCodes(msg)); @@ -268,7 +272,11 @@ private static void syncMemoryToConfig() { ServerEntry se = findServerEntryByProfile(profileName); if (se == null) { - continue; + se = new ServerEntry(); + se.profileName = profileName; + LtrynekClient.serversConfig.servers.add(se); + } else { + se.prices.clear(); } for (Map.Entry itemEntry : items.entrySet()) { @@ -283,6 +291,14 @@ private static void syncMemoryToConfig() { } } + /** + * Synchronizes and saves configuration to disk. + */ + private static void autoSaveConfig() { + syncMemoryToConfig(); + ConfigLoader.saveConfig(LtrynekClient.serversConfig); + } + /** * Czyƛci i na nowo inicjalizuje ClientPriceListManager z LtrynekClient.serversConfig. */