Datatype Singletons
This commit is contained in:
@@ -44,7 +44,7 @@ public class BuildCommand extends Command {
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args) throws CommandException {
|
||||
File file = args.getDatatypePost(RelativeFile.class, schematicsDir).getAbsoluteFile();
|
||||
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
|
||||
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
|
||||
file = new File(file.getAbsolutePath() + ".schematic");
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class BuildCommand extends Command {
|
||||
BetterBlockPos buildOrigin;
|
||||
if (args.hasAny()) {
|
||||
args.requireMax(3);
|
||||
buildOrigin = args.getDatatype(RelativeBlockPos.class).apply(origin);
|
||||
buildOrigin = args.getDatatypePost(RelativeBlockPos.INSTANCE, origin);
|
||||
} else {
|
||||
args.requireMax(0);
|
||||
buildOrigin = origin;
|
||||
@@ -70,7 +70,7 @@ public class BuildCommand extends Command {
|
||||
return RelativeFile.tabComplete(args, schematicsDir);
|
||||
} else if (args.has(2)) {
|
||||
args.get();
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.class);
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.INSTANCE);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ClearareaCommand extends Command {
|
||||
BetterBlockPos pos2;
|
||||
if (args.hasAny()) {
|
||||
args.requireMax(3);
|
||||
pos2 = args.getDatatype(RelativeBlockPos.class).apply(pos1);
|
||||
pos2 = args.getDatatypePost(RelativeBlockPos.INSTANCE, pos1);
|
||||
} else {
|
||||
args.requireMax(0);
|
||||
Goal goal = baritone.getCustomGoalProcess().getGoal();
|
||||
@@ -60,7 +60,7 @@ public class ClearareaCommand extends Command {
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.class);
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ExploreCommand extends Command {
|
||||
args.requireMax(0);
|
||||
}
|
||||
GoalXZ goal = args.hasAny()
|
||||
? args.getDatatypePost(RelativeGoalXZ.class, ctx.playerFeet())
|
||||
? args.getDatatypePost(RelativeGoalXZ.INSTANCE, ctx.playerFeet())
|
||||
: new GoalXZ(ctx.playerFeet());
|
||||
baritone.getExploreProcess().explore(goal.getX(), goal.getZ());
|
||||
logDirect(String.format("Exploring from %s", goal.toString()));
|
||||
@@ -52,7 +52,7 @@ public class ExploreCommand extends Command {
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
|
||||
if (args.hasAtMost(2)) {
|
||||
return args.tabCompleteDatatype(RelativeGoalXZ.class);
|
||||
return args.tabCompleteDatatype(RelativeGoalXZ.INSTANCE);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ExploreFilterCommand extends Command {
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args) throws CommandException {
|
||||
args.requireMax(2);
|
||||
File file = args.getDatatypePost(RelativeFile.class, mc.gameDir.getAbsoluteFile().getParentFile());
|
||||
File file = args.getDatatypePost(RelativeFile.INSTANCE, mc.gameDir.getAbsoluteFile().getParentFile());
|
||||
boolean invert = false;
|
||||
if (args.hasAny()) {
|
||||
if (args.getString().equalsIgnoreCase("invert")) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class FindCommand extends Command {
|
||||
protected void executed(String label, ArgConsumer args) throws CommandException {
|
||||
List<Block> toFind = new ArrayList<>();
|
||||
while (args.hasAny()) {
|
||||
toFind.add(args.getDatatypeFor(BlockById.class));
|
||||
toFind.add(args.getDatatypeFor(BlockById.INSTANCE));
|
||||
}
|
||||
BetterBlockPos origin = ctx.playerFeet();
|
||||
toFind.stream()
|
||||
@@ -61,7 +61,7 @@ public class FindCommand extends Command {
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
|
||||
return args.tabCompleteDatatype(BlockById.class);
|
||||
return args.tabCompleteDatatype(BlockById.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,6 @@ public class FollowCommand extends Command {
|
||||
group = null;
|
||||
list = args.getEnum(FollowList.class);
|
||||
while (args.hasAny()) {
|
||||
//noinspection unchecked
|
||||
Object gotten = args.getDatatypeFor(list.datatype);
|
||||
if (gotten instanceof Class) {
|
||||
//noinspection unchecked
|
||||
@@ -98,7 +97,7 @@ public class FollowCommand extends Command {
|
||||
.filterPrefix(args.getString())
|
||||
.stream();
|
||||
} else {
|
||||
Class<? extends IDatatype> followType;
|
||||
IDatatypeFor followType;
|
||||
try {
|
||||
followType = args.getEnum(FollowList.class).datatype;
|
||||
} catch (NullPointerException e) {
|
||||
@@ -145,11 +144,12 @@ public class FollowCommand extends Command {
|
||||
}
|
||||
|
||||
private enum FollowList {
|
||||
ENTITY(EntityClassById.class),
|
||||
PLAYER(NearbyPlayer.class);
|
||||
final Class<? extends IDatatypeFor> datatype;
|
||||
ENTITY(EntityClassById.INSTANCE),
|
||||
PLAYER(NearbyPlayer.INSTANCE);
|
||||
|
||||
FollowList(Class<? extends IDatatypeFor> datatype) {
|
||||
final IDatatypeFor datatype;
|
||||
|
||||
FollowList(IDatatypeFor datatype) {
|
||||
this.datatype = datatype;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GoalCommand extends Command {
|
||||
} else {
|
||||
args.requireMax(3);
|
||||
BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
|
||||
Goal goal = args.getDatatype(RelativeGoal.class).apply(origin);
|
||||
Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
|
||||
goalProcess.setGoal(goal);
|
||||
logDirect(String.format("Goal: %s", goal.toString()));
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class GoalCommand extends Command {
|
||||
} else {
|
||||
if (args.hasAtMost(3)) {
|
||||
while (args.has(2)) {
|
||||
if (args.peekDatatypeOrNull(RelativeCoordinate.class) == null) {
|
||||
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) == null) {
|
||||
break;
|
||||
}
|
||||
args.get();
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package baritone.utils.command.defaults;
|
||||
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.BlockOptionalMeta;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.BlockById;
|
||||
@@ -44,7 +43,7 @@ public class MineCommand extends Command {
|
||||
args.requireMin(1);
|
||||
List<BlockOptionalMeta> boms = new ArrayList<>();
|
||||
while (args.hasAny()) {
|
||||
boms.add(args.getDatatypeFor(ForBlockOptionalMeta.class));
|
||||
boms.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
|
||||
}
|
||||
WorldScanner.INSTANCE.repack(ctx);
|
||||
logDirect(String.format("Mining %s", boms.toString()));
|
||||
@@ -53,7 +52,7 @@ public class MineCommand extends Command {
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args) {
|
||||
return args.tabCompleteDatatype(BlockById.class);
|
||||
return args.tabCompleteDatatype(BlockById.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PathCommand extends Command {
|
||||
Goal goal;
|
||||
if (args.hasAny()) {
|
||||
args.requireMax(3);
|
||||
goal = args.getDatatype(RelativeGoal.class).apply(ctx.playerFeet());
|
||||
goal = args.getDatatypePost(RelativeGoal.INSTANCE, ctx.playerFeet());
|
||||
} else if ((goal = customGoalProcess.getGoal()) == null) {
|
||||
throw new CommandInvalidStateException("No goal");
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class PathCommand extends Command {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args) throws CommandException {
|
||||
if (args.hasAny() && !args.has(4)) {
|
||||
while (args.has(2)) {
|
||||
if (args.peekDatatypeOrNull(RelativeCoordinate.class) == null) {
|
||||
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) == null) {
|
||||
break;
|
||||
}
|
||||
args.get();
|
||||
|
||||
@@ -86,7 +86,7 @@ public class SelCommand extends Command {
|
||||
throw new CommandInvalidStateException("Set pos1 first before using pos2");
|
||||
}
|
||||
BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
|
||||
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.class, playerPos) : playerPos;
|
||||
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
|
||||
args.requireMax(0);
|
||||
if (action == Action.POS1) {
|
||||
pos1 = pos;
|
||||
@@ -117,16 +117,16 @@ public class SelCommand extends Command {
|
||||
} else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) {
|
||||
BlockOptionalMeta type = action == Action.CLEARAREA
|
||||
? new BlockOptionalMeta(Blocks.AIR)
|
||||
: args.getDatatypeFor(ForBlockOptionalMeta.class);
|
||||
: args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
|
||||
BlockOptionalMetaLookup replaces = null;
|
||||
if (action == Action.REPLACE) {
|
||||
args.requireMin(1);
|
||||
List<BlockOptionalMeta> replacesList = new ArrayList<>();
|
||||
replacesList.add(type);
|
||||
while (args.has(2)) {
|
||||
replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.class));
|
||||
replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
|
||||
}
|
||||
type = args.getDatatypeFor(ForBlockOptionalMeta.class);
|
||||
type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
|
||||
replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
|
||||
} else {
|
||||
args.requireMax(0);
|
||||
@@ -166,7 +166,7 @@ public class SelCommand extends Command {
|
||||
if (transformTarget == null) {
|
||||
throw new CommandInvalidStateException("Invalid transform type");
|
||||
}
|
||||
EnumFacing direction = args.getDatatypeFor(ForEnumFacing.class);
|
||||
EnumFacing direction = args.getDatatypeFor(ForEnumFacing.INSTANCE);
|
||||
int blocks = args.getAs(Integer.class);
|
||||
ISelection[] selections = manager.getSelections();
|
||||
if (selections.length < 1) {
|
||||
@@ -199,14 +199,14 @@ public class SelCommand extends Command {
|
||||
if (action != null) {
|
||||
if (action == Action.POS1 || action == Action.POS2) {
|
||||
if (args.hasAtMost(3)) {
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.class);
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.INSTANCE);
|
||||
}
|
||||
} else if (action == Action.SET || action == Action.WALLS || action == Action.CLEARAREA || action == Action.REPLACE) {
|
||||
if (args.hasExactlyOne() || action == Action.REPLACE) {
|
||||
while (args.has(2)) {
|
||||
args.get();
|
||||
}
|
||||
return args.tabCompleteDatatype(ForBlockOptionalMeta.class);
|
||||
return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE);
|
||||
}
|
||||
} else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
|
||||
if (args.hasExactlyOne()) {
|
||||
@@ -218,7 +218,7 @@ public class SelCommand extends Command {
|
||||
} else {
|
||||
TransformTarget target = TransformTarget.getByName(args.getString());
|
||||
if (target != null && args.hasExactlyOne()) {
|
||||
return args.tabCompleteDatatype(ForEnumFacing.class);
|
||||
return args.tabCompleteDatatype(ForEnumFacing.INSTANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ public class WaypointsCommand extends Command {
|
||||
args.get();
|
||||
}
|
||||
IWaypoint[] waypoints = tag != null
|
||||
? ForWaypoints.getWaypointsByTag(tag)
|
||||
: ForWaypoints.getWaypoints();
|
||||
? ForWaypoints.getWaypointsByTag(this.baritone, tag)
|
||||
: ForWaypoints.getWaypoints(this.baritone);
|
||||
if (waypoints.length > 0) {
|
||||
args.requireMax(1);
|
||||
Paginator.paginate(
|
||||
@@ -132,11 +132,11 @@ public class WaypointsCommand extends Command {
|
||||
}
|
||||
String name = args.hasAny() ? args.getString() : "";
|
||||
BetterBlockPos pos = args.hasAny()
|
||||
? args.getDatatypePost(RelativeBlockPos.class, ctx.playerFeet())
|
||||
? args.getDatatypePost(RelativeBlockPos.INSTANCE, ctx.playerFeet())
|
||||
: ctx.playerFeet();
|
||||
args.requireMax(0);
|
||||
IWaypoint waypoint = new Waypoint(name, tag, pos);
|
||||
ForWaypoints.waypoints().addWaypoint(waypoint);
|
||||
ForWaypoints.waypoints(this.baritone).addWaypoint(waypoint);
|
||||
ITextComponent component = new TextComponentString("Waypoint added: ");
|
||||
component.getStyle().setColor(TextFormatting.GRAY);
|
||||
component.appendSibling(toComponent.apply(waypoint, Action.INFO));
|
||||
@@ -144,13 +144,13 @@ public class WaypointsCommand extends Command {
|
||||
} else if (action == Action.CLEAR) {
|
||||
args.requireMax(1);
|
||||
IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
|
||||
IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(tag);
|
||||
IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(this.baritone, tag);
|
||||
for (IWaypoint waypoint : waypoints) {
|
||||
ForWaypoints.waypoints().removeWaypoint(waypoint);
|
||||
ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
|
||||
}
|
||||
logDirect(String.format("Cleared %d waypoints", waypoints.length));
|
||||
} else {
|
||||
IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.class);
|
||||
IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.INSTANCE);
|
||||
IWaypoint waypoint = null;
|
||||
if (args.hasAny() && args.peekString().equals("@")) {
|
||||
args.requireExactly(2);
|
||||
@@ -230,7 +230,7 @@ public class WaypointsCommand extends Command {
|
||||
logDirect(goalComponent);
|
||||
logDirect(backComponent);
|
||||
} else if (action == Action.DELETE) {
|
||||
ForWaypoints.waypoints().removeWaypoint(waypoint);
|
||||
ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
|
||||
logDirect("That waypoint has successfully been deleted");
|
||||
} else if (action == Action.GOAL) {
|
||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
||||
@@ -260,12 +260,12 @@ public class WaypointsCommand extends Command {
|
||||
.filterPrefix(args.getString())
|
||||
.stream();
|
||||
} else {
|
||||
return args.tabCompleteDatatype(ForWaypoints.class);
|
||||
return args.tabCompleteDatatype(ForWaypoints.INSTANCE);
|
||||
}
|
||||
} else if (args.has(3) && action == Action.SAVE) {
|
||||
args.get();
|
||||
args.get();
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.class);
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.INSTANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.utils.command.manager;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.argument.CommandArgument;
|
||||
import baritone.api.utils.command.execution.CommandExecution;
|
||||
@@ -45,6 +46,11 @@ public class CommandManager implements ICommandManager {
|
||||
DefaultCommands.commands(baritone).forEach(this.registry::register);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaritone getBaritone() {
|
||||
return this.baritone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<Command> getRegistry() {
|
||||
return this.registry;
|
||||
|
||||
Reference in New Issue
Block a user