un-poz some Command stuff

This commit is contained in:
Brady 2019-10-04 19:22:15 -05:00
parent 1440e81ea4
commit 29d8ab43f2
No known key found for this signature in database
GPG Key ID: 73A788379A197567
13 changed files with 24 additions and 24 deletions

View File

@ -37,25 +37,21 @@ public abstract class Command implements Helper {
/** /**
* 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.
*/ */
public final List<String> names; protected final List<String> names;
/** /**
* Creates a new Baritone control command. * Creates a new Baritone control command.
* *
* @param names The names of this command. This is what you put after the command prefix. * @param names The names of this command. This is what you put after the command prefix.
*/ */
protected Command(IBaritone baritone, List<String> names) { protected Command(IBaritone baritone, String... names) {
this.names = names.stream() this.names = Collections.unmodifiableList(Stream.of(names)
.map(s -> s.toLowerCase(Locale.US)) .map(s -> s.toLowerCase(Locale.US))
.collect(Collectors.toList()); .collect(Collectors.toList()));
this.baritone = baritone; this.baritone = baritone;
this.ctx = baritone.getPlayerContext(); this.ctx = baritone.getPlayerContext();
} }
protected Command(IBaritone baritone, String name) {
this(baritone, Collections.singletonList(name));
}
/** /**
* Called when this command is executed. * Called when this command is executed.
*/ */
@ -83,4 +79,8 @@ public abstract class Command implements Helper {
public boolean hiddenFromHelp() { public boolean hiddenFromHelp() {
return false; return false;
} }
public final List<String> getNames() {
return this.names;
}
} }

View File

@ -241,7 +241,7 @@ public class TabCompleteHelper {
*/ */
public TabCompleteHelper addCommands(ICommandManager manager) { public TabCompleteHelper addCommands(ICommandManager manager) {
return append(manager.getRegistry().descendingStream() return append(manager.getRegistry().descendingStream()
.flatMap(command -> command.names.stream()) .flatMap(command -> command.getNames().stream())
.distinct() .distinct()
); );
} }

View File

@ -31,7 +31,7 @@ import java.util.stream.Stream;
public class AxisCommand extends Command { public class AxisCommand extends Command {
public AxisCommand(IBaritone baritone) { public AxisCommand(IBaritone baritone) {
super(baritone, Arrays.asList("axis", "highway")); super(baritone, "axis", "highway");
} }
@Override @Override

View File

@ -29,7 +29,7 @@ import java.util.stream.Stream;
public class CancelCommand extends Command { public class CancelCommand extends Command {
public CancelCommand(IBaritone baritone) { public CancelCommand(IBaritone baritone) {
super(baritone, Arrays.asList("cancel", "stop")); super(baritone, "cancel", "stop");
} }
@Override @Override

View File

@ -31,7 +31,7 @@ public class CommandAlias extends Command {
public final String target; public final String target;
public CommandAlias(IBaritone baritone, List<String> names, String shortDesc, String target) { public CommandAlias(IBaritone baritone, List<String> names, String shortDesc, String target) {
super(baritone, names); super(baritone, names.toArray(new String[0]));
this.shortDesc = shortDesc; this.shortDesc = shortDesc;
this.target = target; this.target = target;
} }

View File

@ -40,7 +40,7 @@ import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREF
public class HelpCommand extends Command { public class HelpCommand extends Command {
public HelpCommand(IBaritone baritone) { public HelpCommand(IBaritone baritone) {
super(baritone, Arrays.asList("help", "?")); super(baritone, "help", "?");
} }
@Override @Override
@ -55,8 +55,8 @@ public class HelpCommand extends Command {
), ),
() -> logDirect("All Baritone commands (clickable):"), () -> logDirect("All Baritone commands (clickable):"),
command -> { command -> {
String names = String.join("/", command.names); String names = String.join("/", command.getNames());
String name = command.names.get(0); String name = command.getNames().get(0);
ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc()); ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc());
shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY); shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
ITextComponent namesComponent = new TextComponentString(names); ITextComponent namesComponent = new TextComponentString(names);
@ -66,7 +66,7 @@ public class HelpCommand extends Command {
hoverComponent.appendSibling(namesComponent); hoverComponent.appendSibling(namesComponent);
hoverComponent.appendText("\n" + command.getShortDesc()); hoverComponent.appendText("\n" + command.getShortDesc());
hoverComponent.appendText("\n\nClick to view full help"); hoverComponent.appendText("\n\nClick to view full help");
String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.names.get(0)); String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.getNames().get(0));
ITextComponent component = new TextComponentString(name); ITextComponent component = new TextComponentString(name);
component.getStyle().setColor(TextFormatting.GRAY); component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(shortDescComponent); component.appendSibling(shortDescComponent);
@ -83,7 +83,7 @@ public class HelpCommand extends Command {
if (command == null) { if (command == null) {
throw new CommandNotFoundException(commandName); throw new CommandNotFoundException(commandName);
} }
logDirect(String.format("%s - %s", String.join(" / ", command.names), command.getShortDesc())); logDirect(String.format("%s - %s", String.join(" / ", command.getNames()), command.getShortDesc()));
logDirect(""); logDirect("");
command.getLongDesc().forEach(this::logDirect); command.getLongDesc().forEach(this::logDirect);
logDirect(""); logDirect("");

View File

@ -36,7 +36,7 @@ import java.util.stream.Stream;
public class PathCommand extends Command { public class PathCommand extends Command {
public PathCommand(IBaritone baritone) { public PathCommand(IBaritone baritone) {
super(baritone, Arrays.asList("path", "goto")); super(baritone, "path", "goto");
} }
@Override @Override

View File

@ -30,7 +30,7 @@ import java.util.stream.Stream;
public class RepackCommand extends Command { public class RepackCommand extends Command {
public RepackCommand(IBaritone baritone) { public RepackCommand(IBaritone baritone) {
super(baritone, Arrays.asList("repack", "rescan")); super(baritone, "repack", "rescan");
} }
@Override @Override

View File

@ -56,7 +56,7 @@ public class SelCommand extends Command {
private BetterBlockPos pos1 = null; private BetterBlockPos pos1 = null;
public SelCommand(IBaritone baritone) { public SelCommand(IBaritone baritone) {
super(baritone, Arrays.asList("sel", "selection", "s")); super(baritone, "sel", "selection", "s");
baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() { baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() {
@Override @Override
public void onRenderPass(RenderEvent event) { public void onRenderPass(RenderEvent event) {

View File

@ -46,7 +46,7 @@ import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREF
public class SetCommand extends Command { public class SetCommand extends Command {
public SetCommand(IBaritone baritone) { public SetCommand(IBaritone baritone) {
super(baritone, Arrays.asList("set", "setting", "settings")); super(baritone, "set", "setting", "settings");
} }
@Override @Override

View File

@ -30,7 +30,7 @@ import java.util.stream.Stream;
public class ThisWayCommand extends Command { public class ThisWayCommand extends Command {
public ThisWayCommand(IBaritone baritone) { public ThisWayCommand(IBaritone baritone) {
super(baritone, Arrays.asList("thisway", "forward")); super(baritone, "thisway", "forward");
} }
@Override @Override

View File

@ -48,7 +48,7 @@ import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREF
public class WaypointsCommand extends Command { public class WaypointsCommand extends Command {
public WaypointsCommand(IBaritone baritone) { public WaypointsCommand(IBaritone baritone) {
super(baritone, Arrays.asList("waypoints", "waypoint", "wp")); super(baritone, "waypoints", "waypoint", "wp");
} }
@Override @Override

View File

@ -64,7 +64,7 @@ public class CommandManager implements ICommandManager {
@Override @Override
public Command getCommand(String name) { public Command getCommand(String name) {
for (Command command : this.registry.entries) { for (Command command : this.registry.entries) {
if (command.names.contains(name.toLowerCase(Locale.US))) { if (command.getNames().contains(name.toLowerCase(Locale.US))) {
return command; return command;
} }
} }