Treat the new callbacks like the old one

This commit is contained in:
ZacSharp 2021-05-24 03:14:33 +02:00
parent 522de3d4b7
commit 7b5f419713
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
4 changed files with 22 additions and 6 deletions

View File

@ -253,8 +253,8 @@ public class TabCompleteHelper {
public TabCompleteHelper addSettings() {
return append(
BaritoneAPI.getSettings().allSettings.stream()
.filter(s -> !SettingsUtil.javaOnlySetting(s))
.map(Settings.Setting::getName)
.filter(s -> !s.equalsIgnoreCase("logger"))
.sorted(String.CASE_INSENSITIVE_ORDER)
);
}

View File

@ -50,6 +50,7 @@ public class SettingsUtil {
private static final Path SETTINGS_PATH = getMinecraft().gameDir.toPath().resolve("baritone").resolve("settings.txt");
private static final Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>.+)"); // key and value split by the first space
private static final String[] JAVA_ONLY_SETTINGS = {"logger", "notifier", "toaster"};
private static boolean isComment(String line) {
return line.startsWith("#") || line.startsWith("//");
@ -111,7 +112,7 @@ public class SettingsUtil {
System.out.println("NULL SETTING?" + setting.getName());
continue;
}
if (setting.getName().equals("logger")) {
if (javaOnlySetting(setting)) {
continue; // NO
}
if (setting.value == setting.defaultValue) {
@ -165,13 +166,28 @@ public class SettingsUtil {
}
public static String settingToString(Settings.Setting setting) throws IllegalStateException {
if (setting.getName().equals("logger")) {
return "logger";
if (javaOnlySetting(setting)) {
return setting.getName();
}
return setting.getName() + " " + settingValueToString(setting);
}
/**
* This should always be the same as whether the setting can be parsed from or serialized to a string
*
* @param the setting
* @return true if the setting can not be set or read by the user
*/
public static boolean javaOnlySetting(Settings.Setting setting) {
for (String name : JAVA_ONLY_SETTINGS) { // no JAVA_ONLY_SETTINGS.contains(...) because that would be case sensitive
if (setting.getName().equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
Settings.Setting setting = settings.byLowerName.get(settingName);
if (setting == null) {

View File

@ -124,7 +124,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
} else if (argc.hasExactlyOne()) {
for (Settings.Setting setting : settings.allSettings) {
if (setting.getName().equals("logger")) {
if (SettingsUtil.javaOnlySetting(setting)) {
continue;
}
if (setting.getName().equalsIgnoreCase(pair.getFirst())) {

View File

@ -64,7 +64,7 @@ public class SetCommand extends Command {
args.requireMax(1);
List<? extends Settings.Setting> toPaginate =
(viewModified ? SettingsUtil.modifiedSettings(Baritone.settings()) : Baritone.settings().allSettings).stream()
.filter(s -> !s.getName().equals("logger"))
.filter(s -> !javaOnlySetting(s))
.filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US)))
.sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName()))
.collect(Collectors.toList());