Skip to content

Commit b628df6

Browse files
committed
fix with autosave and not loading default items
1 parent 9e68d57 commit b628df6

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.18.2+build.4
88
loader_version=0.16.10
99

1010
# Mod Properties
11-
mod_version=1.5.2-Alpha+1.18.2
11+
mod_version=1.5.3-Alpha+1.18.2
1212
maven_group=pl.lordtricker
1313
archives_base_name=ltrynek
1414

src/client/java/pl/lordtricker/ltrynek/client/command/ClientCommandRegistration.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)