@@ -135,6 +135,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
135135 ));
136136
137137 ctx .getSource ().sendFeedback (ColorUtils .translateColorCodes (msg ));
138+ syncMemoryToConfig ();
138139 return 1 ;
139140 })
140141 )
@@ -155,6 +156,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
155156 "profile" , activeProfile
156157 ));
157158 ctx .getSource ().sendFeedback (ColorUtils .translateColorCodes (msg ));
159+ syncMemoryToConfig ();
158160 return 1 ;
159161 })
160162 )
@@ -251,6 +253,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
251253 LtrynekClient .serversConfig .soundsEnabled = true ;
252254 String msg = Messages .get ("command.sounds.enabled" );
253255 ctx .getSource ().sendFeedback (ColorUtils .translateColorCodes (msg ));
256+ saveAllConfigs (LtrynekClient .serversConfig );
254257 return 1 ;
255258 })
256259 )
@@ -259,6 +262,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
259262 LtrynekClient .serversConfig .soundsEnabled = false ;
260263 String msg = Messages .get ("command.sounds.disabled" );
261264 ctx .getSource ().sendFeedback (ColorUtils .translateColorCodes (msg ));
265+ saveAllConfigs (LtrynekClient .serversConfig );
262266 return 1 ;
263267 })
264268 )
@@ -383,28 +387,29 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
383387 }
384388
385389 private static void syncMemoryToConfig () {
390+ if (LtrynekClient .serversConfig == null || LtrynekClient .serversConfig .servers == null ) {
391+ return ;
392+ }
386393 Map <String , List <PriceEntry >> allProfiles = ClientPriceListManager .getAllProfiles ();
387- for (Map .Entry <String , List <PriceEntry >> profEntry : allProfiles .entrySet ()) {
388- String profileName = profEntry .getKey ();
389- List <PriceEntry > priceEntries = profEntry .getValue ();
390- ServerEntry se = findServerEntryByProfile (profileName );
391- if (se == null ) continue ;
392- for (PriceEntry storedPe : priceEntries ) {
393- boolean exists = se .prices .stream ().anyMatch (pe -> pe .name .equals (storedPe .name ));
394- if (!exists ) {
395- PriceEntry pe = new PriceEntry ();
396- pe .name = storedPe .name ;
397- pe .maxPrice = storedPe .maxPrice ;
398- pe .lore = storedPe .lore ;
399- pe .material = storedPe .material ;
400- pe .enchants = storedPe .enchants ;
401- se .prices .add (pe );
402- }
394+
395+ for (ServerEntry se : LtrynekClient .serversConfig .servers ) {
396+ List <PriceEntry > memList = allProfiles .getOrDefault (se .profileName , List .of ());
397+ se .prices .clear ();
398+ for (PriceEntry src : memList ) {
399+ PriceEntry pe = new PriceEntry ();
400+ pe .name = src .name ;
401+ pe .maxPrice = src .maxPrice ;
402+ pe .lore = src .lore ;
403+ pe .material = src .material ;
404+ pe .enchants = src .enchants ;
405+ se .prices .add (pe );
403406 }
404407 }
408+
405409 saveAllConfigs (LtrynekClient .serversConfig );
406410 }
407411
412+
408413 private static void reinitProfilesFromConfig () {
409414 for (ServerEntry entry : LtrynekClient .serversConfig .servers ) {
410415 ClientPriceListManager .setActiveProfile (entry .profileName );
0 commit comments