No more passing Settings to execute and tabComplete

This commit is contained in:
Brady 2019-09-21 02:07:10 -05:00
parent b7eaae88a8
commit ea4f34cb0f
No known key found for this signature in database
GPG Key ID: 73A788379A197567
36 changed files with 91 additions and 93 deletions

View File

@ -35,6 +35,7 @@ public abstract class Command implements Helper {
protected IBaritone baritone; protected IBaritone baritone;
protected IPlayerContext ctx; protected IPlayerContext ctx;
/** /**
* The names of this command. This is what you put after the command prefix. * The names of this command. This is what you put after the command prefix.
*/ */
@ -63,7 +64,7 @@ public abstract class Command implements Helper {
* @param execution The command execution to execute this command with * @param execution The command execution to execute this command with
*/ */
public void execute(CommandExecution execution) throws CommandException { public void execute(CommandExecution execution) throws CommandException {
executed(execution.label, execution.args, execution.settings); executed(execution.label, execution.args);
} }
/** /**
@ -74,7 +75,7 @@ public abstract class Command implements Helper {
*/ */
public Stream<String> tabComplete(CommandExecution execution) { public Stream<String> tabComplete(CommandExecution execution) {
try { try {
return tabCompleted(execution.label, execution.args, execution.settings); return tabCompleted(execution.label, execution.args);
} catch (Throwable t) { } catch (Throwable t) {
return Stream.empty(); return Stream.empty();
} }
@ -83,13 +84,13 @@ public abstract class Command implements Helper {
/** /**
* Called when this command is executed. * Called when this command is executed.
*/ */
protected abstract void executed(String label, ArgConsumer args, Settings settings) throws CommandException; protected abstract void executed(String label, ArgConsumer args) throws CommandException;
/** /**
* Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions * Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
* list. * list.
*/ */
protected abstract Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException; protected abstract Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException;
/** /**
* @return A <b>single-line</b> string containing a short description of this command's purpose. * @return A <b>single-line</b> string containing a short description of this command's purpose.

View File

@ -36,18 +36,16 @@ public class CommandExecution {
* The command itself * The command itself
*/ */
private final Command command; private final Command command;
/** /**
* The name this command was called with * The name this command was called with
*/ */
public final String label; public final String label;
/** /**
* The arg consumer * The arg consumer
*/ */
public final ArgConsumer args; public final ArgConsumer args;
/**
* The Baritone settings
*/
public final Settings settings = BaritoneAPI.getSettings();
public CommandExecution(Command command, String label, ArgConsumer args) { public CommandExecution(Command command, String label, ArgConsumer args) {
this.command = command; this.command = command;

View File

@ -36,7 +36,7 @@ public class AxisCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
Goal goal = new GoalAxis(); Goal goal = new GoalAxis();
baritone.getCustomGoalProcess().setGoal(goal); baritone.getCustomGoalProcess().setGoal(goal);
@ -44,7 +44,7 @@ public class AxisCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -36,7 +36,7 @@ public class BlacklistCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
IGetToBlockProcess proc = baritone.getGetToBlockProcess(); IGetToBlockProcess proc = baritone.getGetToBlockProcess();
if (!proc.isActive()) { if (!proc.isActive()) {
@ -50,7 +50,7 @@ public class BlacklistCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -43,7 +43,7 @@ public class BuildCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
File file = args.getDatatypePost(RelativeFile.class, schematicsDir).getAbsoluteFile(); File file = args.getDatatypePost(RelativeFile.class, schematicsDir).getAbsoluteFile();
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) { if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
file = new File(file.getAbsolutePath() + ".schematic"); file = new File(file.getAbsolutePath() + ".schematic");
@ -65,7 +65,7 @@ public class BuildCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
return RelativeFile.tabComplete(args, schematicsDir); return RelativeFile.tabComplete(args, schematicsDir);
} else if (args.has(2)) { } else if (args.has(2)) {

View File

@ -34,14 +34,14 @@ public class CancelCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
baritone.getPathingBehavior().cancelEverything(); baritone.getPathingBehavior().cancelEverything();
logDirect("ok canceled"); logDirect("ok canceled");
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -42,7 +42,7 @@ public class ChestsCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
Set<Map.Entry<BlockPos, IRememberedInventory>> entries = Set<Map.Entry<BlockPos, IRememberedInventory>> entries =
ctx.worldData().getContainerMemory().getRememberedInventories().entrySet(); ctx.worldData().getContainerMemory().getRememberedInventories().entrySet();
@ -63,7 +63,7 @@ public class ChestsCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -39,7 +39,7 @@ public class ClearareaCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
BetterBlockPos pos1 = ctx.playerFeet(); BetterBlockPos pos1 = ctx.playerFeet();
BetterBlockPos pos2; BetterBlockPos pos2;
if (args.hasAny()) { if (args.hasAny()) {
@ -59,7 +59,7 @@ public class ClearareaCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return args.tabCompleteDatatype(RelativeBlockPos.class); return args.tabCompleteDatatype(RelativeBlockPos.class);
} }

View File

@ -34,14 +34,14 @@ public class ClickCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
baritone.openClick(); baritone.openClick();
logDirect("aight dude"); logDirect("aight dude");
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -38,7 +38,7 @@ public class ComeCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
Entity entity = mc.getRenderViewEntity(); Entity entity = mc.getRenderViewEntity();
if (entity == null) { if (entity == null) {
@ -49,7 +49,7 @@ public class ComeCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -45,12 +45,12 @@ public class CommandAlias extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) { protected void executed(String label, ArgConsumer args) {
CommandManager.execute(String.format("%s %s", target, args.rawRest())); CommandManager.execute(String.format("%s %s", target, args.rawRest()));
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return CommandManager.tabComplete(String.format("%s %s", target, args.rawRest())); return CommandManager.tabComplete(String.format("%s %s", target, args.rawRest()));
} }

View File

@ -36,7 +36,7 @@ public class ExploreCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
if (args.hasAny()) { if (args.hasAny()) {
args.requireExactly(2); args.requireExactly(2);
} else { } else {
@ -50,7 +50,7 @@ public class ExploreCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
if (args.hasAtMost(2)) { if (args.hasAtMost(2)) {
return args.tabCompleteDatatype(RelativeGoalXZ.class); return args.tabCompleteDatatype(RelativeGoalXZ.class);
} }

View File

@ -40,7 +40,7 @@ public class ExploreFilterCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(2); args.requireMax(2);
File file = args.getDatatypePost(RelativeFile.class, mc.gameDir.getAbsoluteFile().getParentFile()); File file = args.getDatatypePost(RelativeFile.class, mc.gameDir.getAbsoluteFile().getParentFile());
boolean invert = false; boolean invert = false;
@ -64,7 +64,7 @@ public class ExploreFilterCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
return RelativeFile.tabComplete(args, RelativeFile.gameDir()); return RelativeFile.tabComplete(args, RelativeFile.gameDir());
} }

View File

@ -34,14 +34,14 @@ public class FarmCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
baritone.getFarmProcess().farm(); baritone.getFarmProcess().farm();
logDirect("Farming"); logDirect("Farming");
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -38,7 +38,7 @@ public class FindCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
List<Block> toFind = new ArrayList<>(); List<Block> toFind = new ArrayList<>();
while (args.hasAny()) { while (args.hasAny()) {
toFind.add(args.getDatatypeFor(BlockById.class)); toFind.add(args.getDatatypeFor(BlockById.class));
@ -60,7 +60,7 @@ public class FindCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return args.tabCompleteDatatype(BlockById.class); return args.tabCompleteDatatype(BlockById.class);
} }

View File

@ -44,7 +44,7 @@ public class FollowCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMin(1); args.requireMin(1);
FollowGroup group; FollowGroup group;
FollowList list; FollowList list;
@ -91,7 +91,7 @@ public class FollowCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
return new TabCompleteHelper() return new TabCompleteHelper()
.append(FollowGroup.class) .append(FollowGroup.class)

View File

@ -35,7 +35,7 @@ public class ForceCancelCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
IPathingBehavior pathingBehavior = baritone.getPathingBehavior(); IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
pathingBehavior.cancelEverything(); pathingBehavior.cancelEverything();
@ -44,7 +44,7 @@ public class ForceCancelCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -34,14 +34,14 @@ public class GcCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
System.gc(); System.gc();
logDirect("ok called System.gc()"); logDirect("ok called System.gc()");
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -40,7 +40,7 @@ public class GoalCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess(); ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess();
if (args.hasAny() && Arrays.asList("reset", "clear", "none").contains(args.peekString())) { if (args.hasAny() && Arrays.asList("reset", "clear", "none").contains(args.peekString())) {
args.requireMax(1); args.requireMax(1);
@ -60,7 +60,7 @@ public class GoalCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
TabCompleteHelper helper = new TabCompleteHelper(); TabCompleteHelper helper = new TabCompleteHelper();
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
helper.append(Stream.of("reset", "clear", "none", "~")); helper.append(Stream.of("reset", "clear", "none", "~"));

View File

@ -47,7 +47,7 @@ public class HelpCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(1); args.requireMax(1);
if (!args.hasAny() || args.is(Integer.class)) { if (!args.hasAny() || args.is(Integer.class)) {
Paginator.paginate( Paginator.paginate(
@ -100,7 +100,7 @@ public class HelpCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
return new TabCompleteHelper().addCommands().filterPrefix(args.getString()).stream(); return new TabCompleteHelper().addCommands().filterPrefix(args.getString()).stream();
} }

View File

@ -38,7 +38,7 @@ public class InvertCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
Goal goal; Goal goal;
@ -55,7 +55,7 @@ public class InvertCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -39,7 +39,7 @@ public class MineCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
int quantity = args.getAsOrDefault(Integer.class, 0); int quantity = args.getAsOrDefault(Integer.class, 0);
args.requireMin(1); args.requireMin(1);
List<BlockOptionalMeta> boms = new ArrayList<>(); List<BlockOptionalMeta> boms = new ArrayList<>();
@ -52,7 +52,7 @@ public class MineCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return args.tabCompleteDatatype(BlockById.class); return args.tabCompleteDatatype(BlockById.class);
} }

View File

@ -41,7 +41,7 @@ public class PathCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
Goal goal; Goal goal;
if (args.hasAny()) { if (args.hasAny()) {
@ -57,7 +57,7 @@ public class PathCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasAny() && !args.has(4)) { if (args.hasAny() && !args.has(4)) {
while (args.has(2)) { while (args.has(2)) {
if (args.peekDatatypeOrNull(RelativeCoordinate.class) == null) { if (args.peekDatatypeOrNull(RelativeCoordinate.class) == null) {

View File

@ -40,13 +40,11 @@ import java.util.stream.Stream;
*/ */
public class PauseResumeCommands { public class PauseResumeCommands {
private final IBaritone baritone;
Command pauseCommand; Command pauseCommand;
Command resumeCommand; Command resumeCommand;
Command pausedCommand; Command pausedCommand;
public PauseResumeCommands(IBaritone baritone) { public PauseResumeCommands(IBaritone baritone) {
this.baritone = baritone;
// array for mutability, non-field so reflection can't touch it // array for mutability, non-field so reflection can't touch it
final boolean[] paused = {false}; final boolean[] paused = {false};
baritone.getPathingControlManager().registerProcess( baritone.getPathingControlManager().registerProcess(
@ -82,7 +80,7 @@ public class PauseResumeCommands {
); );
pauseCommand = new Command(baritone, "pause") { pauseCommand = new Command(baritone, "pause") {
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
if (paused[0]) { if (paused[0]) {
throw new CommandInvalidStateException("Already paused"); throw new CommandInvalidStateException("Already paused");
@ -92,7 +90,7 @@ public class PauseResumeCommands {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }
@ -115,7 +113,7 @@ public class PauseResumeCommands {
}; };
resumeCommand = new Command(baritone, "resume") { resumeCommand = new Command(baritone, "resume") {
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
if (!paused[0]) { if (!paused[0]) {
throw new CommandInvalidStateException("Not paused"); throw new CommandInvalidStateException("Not paused");
@ -125,7 +123,7 @@ public class PauseResumeCommands {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }
@ -146,13 +144,13 @@ public class PauseResumeCommands {
}; };
pausedCommand = new Command(baritone, "paused") { pausedCommand = new Command(baritone, "paused") {
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not ")); logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not "));
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -38,7 +38,7 @@ public class ProcCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
IPathingControlManager pathingControlManager = baritone.getPathingControlManager(); IPathingControlManager pathingControlManager = baritone.getPathingControlManager();
IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null); IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null);
@ -63,7 +63,7 @@ public class ProcCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -34,14 +34,14 @@ public class ReloadAllCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
ctx.worldData().getCachedWorld().reloadAllFromDisk(); ctx.worldData().getCachedWorld().reloadAllFromDisk();
logDirect("Reloaded"); logDirect("Reloaded");
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -35,7 +35,7 @@ public class RenderCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
BetterBlockPos origin = ctx.playerFeet(); BetterBlockPos origin = ctx.playerFeet();
int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16; int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16;
@ -51,7 +51,7 @@ public class RenderCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -35,13 +35,13 @@ public class RepackCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx))); logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx)));
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -34,14 +34,14 @@ public class SaveAllCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
ctx.worldData().getCachedWorld().save(); ctx.worldData().getCachedWorld().save();
logDirect("Saved"); logDirect("Saved");
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -34,13 +34,13 @@ public class SchematicaCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
baritone.getBuilderProcess().buildOpenSchematic(); baritone.getBuilderProcess().buildOpenSchematic();
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -76,7 +76,7 @@ public class SelCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
Action action = Action.getByName(args.getString()); Action action = Action.getByName(args.getString());
if (action == null) { if (action == null) {
throw new CommandInvalidTypeException(args.consumed(), "an action"); throw new CommandInvalidTypeException(args.consumed(), "an action");
@ -187,7 +187,7 @@ public class SelCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
return new TabCompleteHelper() return new TabCompleteHelper()
.append(Action.getAllNames()) .append(Action.getAllNames())

View File

@ -17,6 +17,7 @@
package baritone.utils.command.defaults; package baritone.utils.command.defaults;
import baritone.Baritone;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.Settings; import baritone.api.Settings;
import baritone.api.utils.SettingsUtil; import baritone.api.utils.SettingsUtil;
@ -49,10 +50,10 @@ public class SetCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
String arg = args.hasAny() ? args.getString().toLowerCase(Locale.US) : "list"; String arg = args.hasAny() ? args.getString().toLowerCase(Locale.US) : "list";
if (Arrays.asList("s", "save").contains(arg)) { if (Arrays.asList("s", "save").contains(arg)) {
SettingsUtil.save(settings); SettingsUtil.save(Baritone.settings());
logDirect("Settings saved"); logDirect("Settings saved");
return; return;
} }
@ -63,7 +64,7 @@ public class SetCommand extends Command {
String search = args.hasAny() && args.peekAsOrNull(Integer.class) == null ? args.getString() : ""; String search = args.hasAny() && args.peekAsOrNull(Integer.class) == null ? args.getString() : "";
args.requireMax(1); args.requireMax(1);
List<? extends Settings.Setting> toPaginate = List<? extends Settings.Setting> toPaginate =
(viewModified ? SettingsUtil.modifiedSettings(settings) : settings.allSettings).stream() (viewModified ? SettingsUtil.modifiedSettings(Baritone.settings()) : Baritone.settings().allSettings).stream()
.filter(s -> !s.getName().equals("logger")) .filter(s -> !s.getName().equals("logger"))
.filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US))) .filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US)))
.sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName())) .sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName()))
@ -87,7 +88,7 @@ public class SetCommand extends Command {
hoverComponent.appendText(setting.getName()); hoverComponent.appendText(setting.getName());
hoverComponent.appendText(String.format("\nType: %s", settingTypeToString(setting))); hoverComponent.appendText(String.format("\nType: %s", settingTypeToString(setting)));
hoverComponent.appendText(String.format("\n\nValue:\n%s", settingValueToString(setting))); hoverComponent.appendText(String.format("\n\nValue:\n%s", settingValueToString(setting)));
String commandSuggestion = settings.prefix.value + String.format("set %s ", setting.getName()); String commandSuggestion = Baritone.settings().prefix.value + String.format("set %s ", setting.getName());
ITextComponent component = new TextComponentString(setting.getName()); ITextComponent component = new TextComponentString(setting.getName());
component.getStyle().setColor(TextFormatting.GRAY); component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(typeComponent); component.appendSibling(typeComponent);
@ -110,9 +111,9 @@ public class SetCommand extends Command {
logDirect("ALL settings will be reset. Use the 'set modified' or 'modified' commands to see what will be reset."); logDirect("ALL settings will be reset. Use the 'set modified' or 'modified' commands to see what will be reset.");
logDirect("Specify a setting name instead of 'all' to only reset one setting"); logDirect("Specify a setting name instead of 'all' to only reset one setting");
} else if (args.peekString().equalsIgnoreCase("all")) { } else if (args.peekString().equalsIgnoreCase("all")) {
SettingsUtil.modifiedSettings(settings).forEach(Settings.Setting::reset); SettingsUtil.modifiedSettings(Baritone.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); SettingsUtil.save(Baritone.settings());
return; return;
} }
} }
@ -120,7 +121,7 @@ public class SetCommand extends Command {
args.requireMin(1); args.requireMin(1);
} }
String settingName = doingSomething ? args.getString() : arg; String settingName = doingSomething ? args.getString() : arg;
Settings.Setting<?> setting = settings.allSettings.stream() Settings.Setting<?> setting = Baritone.settings().allSettings.stream()
.filter(s -> s.getName().equalsIgnoreCase(settingName)) .filter(s -> s.getName().equalsIgnoreCase(settingName))
.findFirst() .findFirst()
.orElse(null); .orElse(null);
@ -148,7 +149,7 @@ public class SetCommand extends Command {
} else { } else {
String newValue = args.getString(); String newValue = args.getString();
try { try {
SettingsUtil.parseAndApply(settings, arg, newValue); SettingsUtil.parseAndApply(Baritone.settings(), arg, newValue);
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
throw new CommandInvalidTypeException(args.consumed(), "a valid value", t); throw new CommandInvalidTypeException(args.consumed(), "a valid value", t);
@ -174,18 +175,18 @@ public class SetCommand extends Command {
FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue) FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue)
)); ));
logDirect(oldValueComponent); logDirect(oldValueComponent);
if ((setting.getName().equals("chatControl") && !(Boolean) setting.value && !settings.chatControlAnyway.value) || if ((setting.getName().equals("chatControl") && !(Boolean) setting.value && !Baritone.settings().chatControlAnyway.value) ||
setting.getName().equals("chatControlAnyway") && !(Boolean) setting.value && !settings.chatControl.value) { setting.getName().equals("chatControlAnyway") && !(Boolean) setting.value && !Baritone.settings().chatControl.value) {
logDirect("Warning: Chat commands will no longer work. If you want to revert this change, use prefix control (if enabled) or click the old value listed above.", TextFormatting.RED); logDirect("Warning: Chat commands will no longer work. If you want to revert this change, use prefix control (if enabled) or click the old value listed above.", TextFormatting.RED);
} else if (setting.getName().equals("prefixControl") && !(Boolean) setting.value) { } else if (setting.getName().equals("prefixControl") && !(Boolean) setting.value) {
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); SettingsUtil.save(Baritone.settings());
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasAny()) { if (args.hasAny()) {
String arg = args.getString(); String arg = args.getString();
if (args.hasExactlyOne() && !Arrays.asList("s", "save").contains(args.peekString().toLowerCase(Locale.US))) { if (args.hasExactlyOne() && !Arrays.asList("s", "save").contains(args.peekString().toLowerCase(Locale.US))) {
@ -201,7 +202,7 @@ public class SetCommand extends Command {
.filterPrefix(args.getString()) .filterPrefix(args.getString())
.stream(); .stream();
} }
Settings.Setting setting = settings.byLowerName.get(arg.toLowerCase(Locale.US)); Settings.Setting setting = Baritone.settings().byLowerName.get(arg.toLowerCase(Locale.US));
if (setting != null) { if (setting != null) {
if (setting.getType() == Boolean.class) { if (setting.getType() == Boolean.class) {
TabCompleteHelper helper = new TabCompleteHelper(); TabCompleteHelper helper = new TabCompleteHelper();

View File

@ -35,7 +35,7 @@ public class ThisWayCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireExactly(1); args.requireExactly(1);
GoalXZ goal = GoalXZ.fromDirection( GoalXZ goal = GoalXZ.fromDirection(
ctx.playerFeetAsVec(), ctx.playerFeetAsVec(),
@ -47,7 +47,7 @@ public class ThisWayCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -36,7 +36,7 @@ public class TunnelCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
Goal goal = new GoalStrictDirection( Goal goal = new GoalStrictDirection(
ctx.playerFeet(), ctx.playerFeet(),
@ -47,7 +47,7 @@ public class TunnelCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -35,7 +35,7 @@ public class VersionCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
args.requireMax(0); args.requireMax(0);
String version = getClass().getPackage().getImplementationVersion(); String version = getClass().getPackage().getImplementationVersion();
if (version == null) { if (version == null) {
@ -46,7 +46,7 @@ public class VersionCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) { protected Stream<String> tabCompleted(String label, ArgConsumer args) {
return Stream.empty(); return Stream.empty();
} }

View File

@ -53,7 +53,7 @@ public class WaypointsCommand extends Command {
} }
@Override @Override
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException { protected void executed(String label, ArgConsumer args) throws CommandException {
Action action = args.hasAny() ? Action.getByName(args.getString()) : Action.LIST; Action action = args.hasAny() ? Action.getByName(args.getString()) : Action.LIST;
if (action == null) { if (action == null) {
throw new CommandInvalidTypeException(args.consumed(), "an action"); throw new CommandInvalidTypeException(args.consumed(), "an action");
@ -242,7 +242,7 @@ public class WaypointsCommand extends Command {
} }
@Override @Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException { protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
if (args.hasAny()) { if (args.hasAny()) {
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
return new TabCompleteHelper() return new TabCompleteHelper()