From 7b5f4197136f16d92de72b2c971644a134aa4f4b Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Mon, 24 May 2021 03:14:33 +0200 Subject: [PATCH] Treat the new callbacks like the old one --- .../command/helpers/TabCompleteHelper.java | 2 +- .../java/baritone/api/utils/SettingsUtil.java | 22 ++++++++++++++++--- .../command/ExampleBaritoneControl.java | 2 +- .../baritone/command/defaults/SetCommand.java | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java index 54ae9e8c..e438da30 100644 --- a/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java +++ b/src/api/java/baritone/api/command/helpers/TabCompleteHelper.java @@ -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) ); } diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 48c8ee4d..0e95965f 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -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("^(?[^ ]+) +(?.+)"); // 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) { diff --git a/src/main/java/baritone/command/ExampleBaritoneControl.java b/src/main/java/baritone/command/ExampleBaritoneControl.java index 8d737941..e00b8db7 100644 --- a/src/main/java/baritone/command/ExampleBaritoneControl.java +++ b/src/main/java/baritone/command/ExampleBaritoneControl.java @@ -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())) { diff --git a/src/main/java/baritone/command/defaults/SetCommand.java b/src/main/java/baritone/command/defaults/SetCommand.java index 49064c5c..5ef0b28a 100644 --- a/src/main/java/baritone/command/defaults/SetCommand.java +++ b/src/main/java/baritone/command/defaults/SetCommand.java @@ -64,7 +64,7 @@ public class SetCommand extends Command { args.requireMax(1); List 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());