Save settings...

This commit is contained in:
Logan Darklock 2019-09-01 13:12:06 -07:00
parent 97ce377b9c
commit b96692f2d9
No known key found for this signature in database
GPG Key ID: B8C37CEDE1AC60EA

View File

@ -52,6 +52,13 @@ public class SetCommand extends Command {
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) { protected void executed(String label, ArgConsumer args, Settings settings) {
String arg = args.has() ? args.getString().toLowerCase(Locale.US) : "list"; String arg = args.has() ? args.getString().toLowerCase(Locale.US) : "list";
if (asList("s", "save").contains(arg)) {
SettingsUtil.save(settings);
logDirect("Settings saved");
return;
}
boolean viewModified = asList("m", "mod", "modified").contains(arg); boolean viewModified = asList("m", "mod", "modified").contains(arg);
boolean viewAll = asList("all", "l", "list").contains(arg); boolean viewAll = asList("all", "l", "list").contains(arg);
boolean paginate = viewModified | viewAll; boolean paginate = viewModified | viewAll;
@ -125,6 +132,7 @@ public class SetCommand extends Command {
} else if (args.peekString().equalsIgnoreCase("all")) { } else if (args.peekString().equalsIgnoreCase("all")) {
SettingsUtil.modifiedSettings(settings).forEach(Settings.Setting::reset); SettingsUtil.modifiedSettings(settings).forEach(Settings.Setting::reset);
logDirect("All settings have been reset to their default values"); logDirect("All settings have been reset to their default values");
SettingsUtil.save(settings);
return; return;
} }
@ -205,6 +213,8 @@ public class SetCommand extends Command {
logDirect("Warning: Prefixed commands will no longer work. If you want to revert this change, use chat control (if enabled) or click the old value listed above.", TextFormatting.RED); logDirect("Warning: Prefixed commands will no longer work. If you want to revert this change, use chat control (if enabled) or click the old value listed above.", TextFormatting.RED);
} }
} }
SettingsUtil.save(settings);
} }
@Override @Override
@ -212,7 +222,7 @@ public class SetCommand extends Command {
if (args.has()) { if (args.has()) {
String arg = args.getString(); String arg = args.getString();
if (args.hasExactlyOne()) { if (args.hasExactlyOne() && !asList("s", "save").contains(args.peekString().toLowerCase(Locale.US))) {
if (arg.equalsIgnoreCase("reset")) { if (arg.equalsIgnoreCase("reset")) {
return new TabCompleteHelper() return new TabCompleteHelper()
.addModifiedSettings() .addModifiedSettings()
@ -247,7 +257,7 @@ public class SetCommand extends Command {
return new TabCompleteHelper() return new TabCompleteHelper()
.addSettings() .addSettings()
.sortAlphabetically() .sortAlphabetically()
.prepend("list", "modified", "reset", "toggle") .prepend("list", "modified", "reset", "toggle", "save")
.filterPrefix(arg) .filterPrefix(arg)
.stream(); .stream();
} }
@ -269,7 +279,8 @@ public class SetCommand extends Command {
"> set <setting> <value> - Set the value of a setting", "> set <setting> <value> - Set the value of a setting",
"> set reset all - Reset ALL SETTINGS to their defaults", "> set reset all - Reset ALL SETTINGS to their defaults",
"> set reset <setting> - Reset a setting to its default", "> set reset <setting> - Reset a setting to its default",
"> set toggle <setting> - Toggle a boolean setting" "> set toggle <setting> - Toggle a boolean setting",
"> set save - Save all settings (this is automatic tho)"
); );
} }
} }