From 29d8ab43f2b810a1228227db058c48a318cf5abb Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 4 Oct 2019 19:22:15 -0500 Subject: [PATCH] un-poz some Command stuff --- .../java/baritone/api/utils/command/Command.java | 16 ++++++++-------- .../helpers/tabcomplete/TabCompleteHelper.java | 2 +- .../utils/command/defaults/AxisCommand.java | 2 +- .../utils/command/defaults/CancelCommand.java | 2 +- .../utils/command/defaults/CommandAlias.java | 2 +- .../utils/command/defaults/HelpCommand.java | 10 +++++----- .../utils/command/defaults/PathCommand.java | 2 +- .../utils/command/defaults/RepackCommand.java | 2 +- .../utils/command/defaults/SelCommand.java | 2 +- .../utils/command/defaults/SetCommand.java | 2 +- .../utils/command/defaults/ThisWayCommand.java | 2 +- .../utils/command/defaults/WaypointsCommand.java | 2 +- .../utils/command/manager/CommandManager.java | 2 +- 13 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/api/java/baritone/api/utils/command/Command.java b/src/api/java/baritone/api/utils/command/Command.java index ba4ed938..6293fd58 100644 --- a/src/api/java/baritone/api/utils/command/Command.java +++ b/src/api/java/baritone/api/utils/command/Command.java @@ -37,25 +37,21 @@ public abstract class Command implements Helper { /** * The names of this command. This is what you put after the command prefix. */ - public final List names; + protected final List names; /** * Creates a new Baritone control command. * * @param names The names of this command. This is what you put after the command prefix. */ - protected Command(IBaritone baritone, List names) { - this.names = names.stream() + protected Command(IBaritone baritone, String... names) { + this.names = Collections.unmodifiableList(Stream.of(names) .map(s -> s.toLowerCase(Locale.US)) - .collect(Collectors.toList()); + .collect(Collectors.toList())); this.baritone = baritone; this.ctx = baritone.getPlayerContext(); } - protected Command(IBaritone baritone, String name) { - this(baritone, Collections.singletonList(name)); - } - /** * Called when this command is executed. */ @@ -83,4 +79,8 @@ public abstract class Command implements Helper { public boolean hiddenFromHelp() { return false; } + + public final List getNames() { + return this.names; + } } diff --git a/src/api/java/baritone/api/utils/command/helpers/tabcomplete/TabCompleteHelper.java b/src/api/java/baritone/api/utils/command/helpers/tabcomplete/TabCompleteHelper.java index 9be9dfb3..dd14e2bc 100644 --- a/src/api/java/baritone/api/utils/command/helpers/tabcomplete/TabCompleteHelper.java +++ b/src/api/java/baritone/api/utils/command/helpers/tabcomplete/TabCompleteHelper.java @@ -241,7 +241,7 @@ public class TabCompleteHelper { */ public TabCompleteHelper addCommands(ICommandManager manager) { return append(manager.getRegistry().descendingStream() - .flatMap(command -> command.names.stream()) + .flatMap(command -> command.getNames().stream()) .distinct() ); } diff --git a/src/main/java/baritone/utils/command/defaults/AxisCommand.java b/src/main/java/baritone/utils/command/defaults/AxisCommand.java index f67c82e5..e454cfc7 100644 --- a/src/main/java/baritone/utils/command/defaults/AxisCommand.java +++ b/src/main/java/baritone/utils/command/defaults/AxisCommand.java @@ -31,7 +31,7 @@ import java.util.stream.Stream; public class AxisCommand extends Command { public AxisCommand(IBaritone baritone) { - super(baritone, Arrays.asList("axis", "highway")); + super(baritone, "axis", "highway"); } @Override diff --git a/src/main/java/baritone/utils/command/defaults/CancelCommand.java b/src/main/java/baritone/utils/command/defaults/CancelCommand.java index 868da5e0..f3783537 100644 --- a/src/main/java/baritone/utils/command/defaults/CancelCommand.java +++ b/src/main/java/baritone/utils/command/defaults/CancelCommand.java @@ -29,7 +29,7 @@ import java.util.stream.Stream; public class CancelCommand extends Command { public CancelCommand(IBaritone baritone) { - super(baritone, Arrays.asList("cancel", "stop")); + super(baritone, "cancel", "stop"); } @Override diff --git a/src/main/java/baritone/utils/command/defaults/CommandAlias.java b/src/main/java/baritone/utils/command/defaults/CommandAlias.java index 6aa32af1..69d4e0be 100644 --- a/src/main/java/baritone/utils/command/defaults/CommandAlias.java +++ b/src/main/java/baritone/utils/command/defaults/CommandAlias.java @@ -31,7 +31,7 @@ public class CommandAlias extends Command { public final String target; public CommandAlias(IBaritone baritone, List names, String shortDesc, String target) { - super(baritone, names); + super(baritone, names.toArray(new String[0])); this.shortDesc = shortDesc; this.target = target; } diff --git a/src/main/java/baritone/utils/command/defaults/HelpCommand.java b/src/main/java/baritone/utils/command/defaults/HelpCommand.java index 480207f1..039506c1 100644 --- a/src/main/java/baritone/utils/command/defaults/HelpCommand.java +++ b/src/main/java/baritone/utils/command/defaults/HelpCommand.java @@ -40,7 +40,7 @@ import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREF public class HelpCommand extends Command { public HelpCommand(IBaritone baritone) { - super(baritone, Arrays.asList("help", "?")); + super(baritone, "help", "?"); } @Override @@ -55,8 +55,8 @@ public class HelpCommand extends Command { ), () -> logDirect("All Baritone commands (clickable):"), command -> { - String names = String.join("/", command.names); - String name = command.names.get(0); + String names = String.join("/", command.getNames()); + String name = command.getNames().get(0); ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc()); shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY); ITextComponent namesComponent = new TextComponentString(names); @@ -66,7 +66,7 @@ public class HelpCommand extends Command { hoverComponent.appendSibling(namesComponent); hoverComponent.appendText("\n" + command.getShortDesc()); 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); component.getStyle().setColor(TextFormatting.GRAY); component.appendSibling(shortDescComponent); @@ -83,7 +83,7 @@ public class HelpCommand extends Command { if (command == null) { 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(""); command.getLongDesc().forEach(this::logDirect); logDirect(""); diff --git a/src/main/java/baritone/utils/command/defaults/PathCommand.java b/src/main/java/baritone/utils/command/defaults/PathCommand.java index e52a93a4..257556b0 100644 --- a/src/main/java/baritone/utils/command/defaults/PathCommand.java +++ b/src/main/java/baritone/utils/command/defaults/PathCommand.java @@ -36,7 +36,7 @@ import java.util.stream.Stream; public class PathCommand extends Command { public PathCommand(IBaritone baritone) { - super(baritone, Arrays.asList("path", "goto")); + super(baritone, "path", "goto"); } @Override diff --git a/src/main/java/baritone/utils/command/defaults/RepackCommand.java b/src/main/java/baritone/utils/command/defaults/RepackCommand.java index 1f11802a..dcbe4b39 100644 --- a/src/main/java/baritone/utils/command/defaults/RepackCommand.java +++ b/src/main/java/baritone/utils/command/defaults/RepackCommand.java @@ -30,7 +30,7 @@ import java.util.stream.Stream; public class RepackCommand extends Command { public RepackCommand(IBaritone baritone) { - super(baritone, Arrays.asList("repack", "rescan")); + super(baritone, "repack", "rescan"); } @Override diff --git a/src/main/java/baritone/utils/command/defaults/SelCommand.java b/src/main/java/baritone/utils/command/defaults/SelCommand.java index 83fc77e3..b6c38ec0 100644 --- a/src/main/java/baritone/utils/command/defaults/SelCommand.java +++ b/src/main/java/baritone/utils/command/defaults/SelCommand.java @@ -56,7 +56,7 @@ public class SelCommand extends Command { private BetterBlockPos pos1 = null; public SelCommand(IBaritone baritone) { - super(baritone, Arrays.asList("sel", "selection", "s")); + super(baritone, "sel", "selection", "s"); baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() { @Override public void onRenderPass(RenderEvent event) { diff --git a/src/main/java/baritone/utils/command/defaults/SetCommand.java b/src/main/java/baritone/utils/command/defaults/SetCommand.java index be07a7ae..f6aed80a 100644 --- a/src/main/java/baritone/utils/command/defaults/SetCommand.java +++ b/src/main/java/baritone/utils/command/defaults/SetCommand.java @@ -46,7 +46,7 @@ import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREF public class SetCommand extends Command { public SetCommand(IBaritone baritone) { - super(baritone, Arrays.asList("set", "setting", "settings")); + super(baritone, "set", "setting", "settings"); } @Override diff --git a/src/main/java/baritone/utils/command/defaults/ThisWayCommand.java b/src/main/java/baritone/utils/command/defaults/ThisWayCommand.java index bef3a513..4c2f4003 100644 --- a/src/main/java/baritone/utils/command/defaults/ThisWayCommand.java +++ b/src/main/java/baritone/utils/command/defaults/ThisWayCommand.java @@ -30,7 +30,7 @@ import java.util.stream.Stream; public class ThisWayCommand extends Command { public ThisWayCommand(IBaritone baritone) { - super(baritone, Arrays.asList("thisway", "forward")); + super(baritone, "thisway", "forward"); } @Override diff --git a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java b/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java index bda39e2a..7cf41863 100644 --- a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java +++ b/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java @@ -48,7 +48,7 @@ import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREF public class WaypointsCommand extends Command { public WaypointsCommand(IBaritone baritone) { - super(baritone, Arrays.asList("waypoints", "waypoint", "wp")); + super(baritone, "waypoints", "waypoint", "wp"); } @Override diff --git a/src/main/java/baritone/utils/command/manager/CommandManager.java b/src/main/java/baritone/utils/command/manager/CommandManager.java index 290b3852..2e37a7f7 100644 --- a/src/main/java/baritone/utils/command/manager/CommandManager.java +++ b/src/main/java/baritone/utils/command/manager/CommandManager.java @@ -64,7 +64,7 @@ public class CommandManager implements ICommandManager { @Override public Command getCommand(String name) { for (Command command : this.registry.entries) { - if (command.names.contains(name.toLowerCase(Locale.US))) { + if (command.getNames().contains(name.toLowerCase(Locale.US))) { return command; } }