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
|
|
|
|
|
|
|
import baritone.api.BaritoneAPI;
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* 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 {
|
|
|
|
public static Command pauseCommand;
|
|
|
|
public static Command resumeCommand;
|
|
|
|
public static Command pausedCommand;
|
|
|
|
|
|
|
|
static {
|
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};
|
|
|
|
|
|
|
|
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingControlManager().registerProcess(
|
|
|
|
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
|
2019-09-01 02:08:43 +00:00
|
|
|
public void onLostControl() {}
|
2019-08-30 18:55:25 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public double priority() {
|
|
|
|
return DEFAULT_PRIORITY + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String displayName0() {
|
|
|
|
return "Pause/Resume Commands";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-09-06 10:59:10 +00:00
|
|
|
pauseCommand = new Command("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(
|
|
|
|
"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-09-06 10:59:10 +00:00
|
|
|
resumeCommand = new Command("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(
|
|
|
|
"The resume command tells Baritone to resume whatever it was doing when you last used pause.",
|
|
|
|
"",
|
|
|
|
"Usage:",
|
|
|
|
"> resume"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-06 10:59:10 +00:00
|
|
|
pausedCommand = new Command("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(
|
|
|
|
"The paused command tells you if Baritone is currently paused by use of the pause command.",
|
|
|
|
"",
|
|
|
|
"Usage:",
|
|
|
|
"> paused"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|