2019-09-04 16:16:36 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Baritone is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-10-06 20:20:42 +00:00
|
|
|
package baritone.command.defaults;
|
2019-08-30 18:55:25 +00:00
|
|
|
|
2019-09-19 20:30:40 +00:00
|
|
|
import baritone.api.IBaritone;
|
2019-10-06 20:20:42 +00:00
|
|
|
import baritone.api.command.Command;
|
2019-12-31 18:45:08 +00:00
|
|
|
import baritone.api.command.argument.IArgConsumer;
|
2019-10-06 20:20:42 +00:00
|
|
|
import baritone.api.command.exception.CommandException;
|
|
|
|
import baritone.api.command.exception.CommandInvalidStateException;
|
2019-12-31 18:45:08 +00:00
|
|
|
import baritone.api.process.IBaritoneProcess;
|
|
|
|
import baritone.api.process.PathingCommand;
|
|
|
|
import baritone.api.process.PathingCommandType;
|
2019-08-30 18:55:25 +00:00
|
|
|
|
2019-09-19 21:38:13 +00:00
|
|
|
import java.util.Arrays;
|
2019-08-30 18:55:25 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains the pause, resume, and paused commands.
|
2019-09-19 19:53:15 +00:00
|
|
|
* <p>
|
2019-08-30 18:55:25 +00:00
|
|
|
* This thing is scoped to hell, private so far you can't even access it using reflection, because you AREN'T SUPPOSED
|
|
|
|
* TO USE THIS to pause and resume Baritone. Make your own process that returns {@link PathingCommandType#REQUEST_PAUSE
|
2019-08-31 01:00:34 +00:00
|
|
|
* REQUEST_PAUSE} as needed.
|
2019-08-30 18:55:25 +00:00
|
|
|
*/
|
2019-12-31 18:45:08 +00:00
|
|
|
public class ExecutionControlCommands {
|
2019-09-19 20:40:46 +00:00
|
|
|
|
2019-09-19 20:30:40 +00:00
|
|
|
Command pauseCommand;
|
|
|
|
Command resumeCommand;
|
|
|
|
Command pausedCommand;
|
2019-12-31 18:16:31 +00:00
|
|
|
Command cancelCommand;
|
2019-08-30 18:55:25 +00:00
|
|
|
|
2019-12-31 18:45:08 +00:00
|
|
|
public ExecutionControlCommands(IBaritone baritone) {
|
2019-08-30 22:38:15 +00:00
|
|
|
// array for mutability, non-field so reflection can't touch it
|
2019-08-30 18:55:25 +00:00
|
|
|
final boolean[] paused = {false};
|
2019-09-19 20:30:40 +00:00
|
|
|
baritone.getPathingControlManager().registerProcess(
|
2019-09-19 19:53:15 +00:00
|
|
|
new IBaritoneProcess() {
|
|
|
|
@Override
|
|
|
|
public boolean isActive() {
|
|
|
|
return paused[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
2022-10-24 20:49:12 +00:00
|
|
|
baritone.getInputOverrideHandler().clearAllKeys();
|
2019-09-19 19:53:15 +00:00
|
|
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isTemporary() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-12-31 18:45:08 +00:00
|
|
|
public void onLostControl() {
|
|
|
|
}
|
2019-09-19 19:53:15 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public double priority() {
|
|
|
|
return DEFAULT_PRIORITY + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String displayName0() {
|
|
|
|
return "Pause/Resume Commands";
|
|
|
|
}
|
2019-08-30 18:55:25 +00:00
|
|
|
}
|
|
|
|
);
|
2022-07-10 05:06:39 +00:00
|
|
|
pauseCommand = new Command(baritone, "pause", "p", "paws") {
|
2019-08-30 18:55:25 +00:00
|
|
|
@Override
|
2019-10-04 13:55:02 +00:00
|
|
|
public void execute(String label, IArgConsumer args) throws CommandException {
|
2019-08-30 18:55:25 +00:00
|
|
|
args.requireMax(0);
|
|
|
|
if (paused[0]) {
|
|
|
|
throw new CommandInvalidStateException("Already paused");
|
|
|
|
}
|
|
|
|
paused[0] = true;
|
|
|
|
logDirect("Paused");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-04 13:55:02 +00:00
|
|
|
public Stream<String> tabComplete(String label, IArgConsumer args) {
|
2019-08-30 18:55:25 +00:00
|
|
|
return Stream.empty();
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:59:10 +00:00
|
|
|
@Override
|
|
|
|
public String getShortDesc() {
|
|
|
|
return "Pauses Baritone until you use resume";
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:55:25 +00:00
|
|
|
@Override
|
|
|
|
public List<String> getLongDesc() {
|
2019-09-19 21:38:13 +00:00
|
|
|
return Arrays.asList(
|
2019-09-19 19:53:15 +00:00
|
|
|
"The pause command tells Baritone to temporarily stop whatever it's doing.",
|
|
|
|
"",
|
|
|
|
"This can be used to pause pathing, building, following, whatever. A single use of the resume command will start it right back up again!",
|
|
|
|
"",
|
|
|
|
"Usage:",
|
|
|
|
"> pause"
|
2019-08-30 18:55:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2022-07-10 05:15:20 +00:00
|
|
|
resumeCommand = new Command(baritone, "resume", "r", "unpause", "unpaws") {
|
2019-08-30 18:55:25 +00:00
|
|
|
@Override
|
2019-10-04 13:55:02 +00:00
|
|
|
public void execute(String label, IArgConsumer args) throws CommandException {
|
2019-08-30 18:55:25 +00:00
|
|
|
args.requireMax(0);
|
2019-10-06 20:24:27 +00:00
|
|
|
baritone.getBuilderProcess().resume();
|
2019-08-30 18:55:25 +00:00
|
|
|
if (!paused[0]) {
|
|
|
|
throw new CommandInvalidStateException("Not paused");
|
|
|
|
}
|
|
|
|
paused[0] = false;
|
|
|
|
logDirect("Resumed");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-04 13:55:02 +00:00
|
|
|
public Stream<String> tabComplete(String label, IArgConsumer args) {
|
2019-08-30 18:55:25 +00:00
|
|
|
return Stream.empty();
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:59:10 +00:00
|
|
|
@Override
|
|
|
|
public String getShortDesc() {
|
|
|
|
return "Resumes Baritone after a pause";
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:55:25 +00:00
|
|
|
@Override
|
|
|
|
public List<String> getLongDesc() {
|
2019-09-19 21:38:13 +00:00
|
|
|
return Arrays.asList(
|
2019-09-19 19:53:15 +00:00
|
|
|
"The resume command tells Baritone to resume whatever it was doing when you last used pause.",
|
|
|
|
"",
|
|
|
|
"Usage:",
|
|
|
|
"> resume"
|
2019-08-30 18:55:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2019-09-19 20:30:40 +00:00
|
|
|
pausedCommand = new Command(baritone, "paused") {
|
2019-08-30 18:55:25 +00:00
|
|
|
@Override
|
2019-10-04 13:55:02 +00:00
|
|
|
public void execute(String label, IArgConsumer args) throws CommandException {
|
2019-08-30 18:55:25 +00:00
|
|
|
args.requireMax(0);
|
|
|
|
logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not "));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-04 13:55:02 +00:00
|
|
|
public Stream<String> tabComplete(String label, IArgConsumer args) {
|
2019-08-30 18:55:25 +00:00
|
|
|
return Stream.empty();
|
|
|
|
}
|
|
|
|
|
2019-09-06 10:59:10 +00:00
|
|
|
@Override
|
|
|
|
public String getShortDesc() {
|
|
|
|
return "Tells you if Baritone is paused";
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:55:25 +00:00
|
|
|
@Override
|
|
|
|
public List<String> getLongDesc() {
|
2019-09-19 21:38:13 +00:00
|
|
|
return Arrays.asList(
|
2019-09-19 19:53:15 +00:00
|
|
|
"The paused command tells you if Baritone is currently paused by use of the pause command.",
|
|
|
|
"",
|
|
|
|
"Usage:",
|
|
|
|
"> paused"
|
2019-08-30 18:55:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2020-07-16 09:45:23 +00:00
|
|
|
cancelCommand = new Command(baritone, "cancel", "c", "stop") {
|
2019-12-31 18:16:31 +00:00
|
|
|
@Override
|
|
|
|
public void execute(String label, IArgConsumer args) throws CommandException {
|
|
|
|
args.requireMax(0);
|
|
|
|
if (paused[0]) {
|
|
|
|
paused[0] = false;
|
|
|
|
}
|
|
|
|
baritone.getPathingBehavior().cancelEverything();
|
|
|
|
logDirect("ok canceled");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Stream<String> tabComplete(String label, IArgConsumer args) {
|
|
|
|
return Stream.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getShortDesc() {
|
|
|
|
return "Cancel what Baritone is currently doing";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getLongDesc() {
|
|
|
|
return Arrays.asList(
|
|
|
|
"The cancel command tells Baritone to stop whatever it's currently doing.",
|
|
|
|
"",
|
|
|
|
"Usage:",
|
|
|
|
"> cancel"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2019-08-30 18:55:25 +00:00
|
|
|
}
|
|
|
|
}
|