baritone/src/main/java/baritone/utils/command/defaults/PauseResumeCommands.java

184 lines
6.2 KiB
Java
Raw Normal View History

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-09-04 18:17:36 +00:00
package baritone.utils.command.defaults;
2019-08-30 18:55:25 +00:00
2019-09-19 20:30:40 +00:00
import baritone.api.IBaritone;
2019-08-30 18:55:25 +00:00
import baritone.api.Settings;
import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import java.util.List;
import java.util.stream.Stream;
import static java.util.Arrays.asList;
/**
* 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
*/
public class PauseResumeCommands {
2019-09-19 20:30:40 +00:00
private final IBaritone baritone;
Command pauseCommand;
Command resumeCommand;
Command pausedCommand;
2019-08-30 18:55:25 +00:00
2019-09-19 20:30:40 +00:00
public PauseResumeCommands(IBaritone baritone) {
this.baritone = 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) {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
@Override
public boolean isTemporary() {
return true;
}
@Override
public void onLostControl() {}
@Override
public double priority() {
return DEFAULT_PRIORITY + 1;
}
@Override
public String displayName0() {
return "Pause/Resume Commands";
}
2019-08-30 18:55:25 +00:00
}
);
2019-09-19 20:30:40 +00:00
pauseCommand = new Command(baritone, "pause") {
2019-08-30 18:55:25 +00:00
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
if (paused[0]) {
throw new CommandInvalidStateException("Already paused");
}
paused[0] = true;
logDirect("Paused");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
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() {
return 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
);
}
};
2019-09-19 20:30:40 +00:00
resumeCommand = new Command(baritone, "resume") {
2019-08-30 18:55:25 +00:00
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
if (!paused[0]) {
throw new CommandInvalidStateException("Not paused");
}
paused[0] = false;
logDirect("Resumed");
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
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() {
return 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
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not "));
}
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
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() {
return 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
);
}
};
}
}