Skip to content

Commit

Permalink
v1.3.2. Small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Corosauce committed Dec 2, 2023
1 parent d9b9448 commit a6118f9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/java/com/corosus/coroutil/command/CommandCoroConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void register(final CommandDispatcher<CommandSourceStack> dispatch
return literal("get").then(Commands.argument("file_name", StringArgumentType.word()).suggests((p_136339_, p_136340_) -> SharedSuggestionProvider.suggest(getConfigs(), p_136340_))
.then(Commands.argument("setting_name", StringArgumentType.word()).suggests((p_136339_, p_136340_) -> SharedSuggestionProvider.suggest(getConfigSettings(StringArgumentType.getString(p_136339_, "file_name")), p_136340_))
.executes(c -> {
String fileName = StringArgumentType.getString(c, "file_name").replace("--", "\\");
String fileName = fileToConfig(StringArgumentType.getString(c, "file_name"));
String configName = ConfigMod.lookupFilePathToConfig.get(fileName).configID;
String settingName = StringArgumentType.getString(c, "setting_name");
Object obj = ConfigMod.getField(configName, settingName);
Expand All @@ -75,14 +75,18 @@ public static void register(final CommandDispatcher<CommandSourceStack> dispatch
.then(Commands.argument("setting_name", StringArgumentType.word()).suggests((p_136339_, p_136340_) -> SharedSuggestionProvider.suggest(getConfigSettings(StringArgumentType.getString(p_136339_, "file_name")), p_136340_))
.then(Commands.argument("value", StringArgumentType.string())
.executes(c -> {
String fileName = StringArgumentType.getString(c, "file_name").replace("--", "\\");
String fileName = fileToConfig(StringArgumentType.getString(c, "file_name"));
String configName = ConfigMod.lookupFilePathToConfig.get(fileName).configID;
String settingName = StringArgumentType.getString(c, "setting_name");
String value = StringArgumentType.getString(c, "value");
ConfigMod.updateField(configName, settingName, value);
Object obj = ConfigMod.getField(configName, settingName);
ConfigMod.forceSaveAllFilesFromRuntimeSettings();
c.getSource().sendSuccess(() -> Component.literal("Set " + settingName + " to " + obj + " in " + fileName), true);
boolean result = ConfigMod.updateField(configName, settingName, value);
if (result) {
Object obj = ConfigMod.getField(configName, settingName);
ConfigMod.forceSaveAllFilesFromRuntimeSettings();
c.getSource().sendSuccess(() -> Component.literal("Set " + settingName + " to " + obj + " in " + fileName), true);
} else {
c.getSource().sendSuccess(() -> Component.literal("Invalid setting to use for " + settingName), true);
}
return Command.SINGLE_SUCCESS;
}))));
}
Expand All @@ -92,11 +96,11 @@ public static String getCommandName() {
}

public static Iterable<String> getConfigs() {
return ConfigMod.lookupRegistryNameToConfig.values().stream().map((e) -> e.saveFilePath.replace("\\", "--") + ".toml").toList();
return ConfigMod.lookupFilePathToConfig.keySet().stream().map((e) -> e.replace("\\", "--")).toList();
}

public static Iterable<String> getConfigSettings(String config_name) {
ModConfigData modConfigData = ConfigMod.lookupFilePathToConfig.get(config_name.replace("--", "\\"));
ModConfigData modConfigData = ConfigMod.lookupFilePathToConfig.get(fileToConfig(config_name));
if (modConfigData != null) {
List<String> joinedList = new ArrayList<>();
joinedList.addAll(modConfigData.valsString.keySet());
Expand All @@ -109,4 +113,8 @@ public static Iterable<String> getConfigSettings(String config_name) {
return List.of("<-- invalid config name");
}
}

public static String fileToConfig(String str) {
return str.replace("--", "\\");
}
}

0 comments on commit a6118f9

Please sign in to comment.