From 0b39b3e7b4024b430242b9155b0a184a5be97483 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 26 Sep 2019 18:59:29 -0500 Subject: [PATCH] FORCE_COMMAND_PREFIX should be exposed to the API --- .../utils/command/IBaritoneChatControl.java | 42 +++++++++++++++++++ src/main/java/baritone/utils/GuiClick.java | 4 +- .../utils/command/BaritoneChatControl.java | 16 +------ .../utils/command/defaults/HelpCommand.java | 2 +- .../utils/command/defaults/SetCommand.java | 2 +- .../command/defaults/WaypointsCommand.java | 2 +- 6 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 src/api/java/baritone/api/utils/command/IBaritoneChatControl.java diff --git a/src/api/java/baritone/api/utils/command/IBaritoneChatControl.java b/src/api/java/baritone/api/utils/command/IBaritoneChatControl.java new file mode 100644 index 00000000..63b6a445 --- /dev/null +++ b/src/api/java/baritone/api/utils/command/IBaritoneChatControl.java @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +package baritone.api.utils.command; + +import baritone.api.Settings; + +import java.util.UUID; + +/** + * @author Brady + * @since 9/26/2019 + */ +public interface IBaritoneChatControl { + + /** + * In certain cases chat components need to execute commands for you. For example, the paginator automatically runs + * commands when you click the forward and back arrows to show you the previous/next page. + *

+ * If the prefix is changed in the meantime, then the command will go to chat. That's no good. So here's a permanent + * prefix that forces a command to run, regardless of the current prefix, chat/prefix control being enabled, etc. + *

+ * If used right (by both developers and users), it should be impossible to expose a command accidentally to the + * server. As a rule of thumb, if you have a clickable chat component, always use this prefix. If you're suggesting + * a command (a component that puts text into your text box, or something else), use {@link Settings#prefix}. + */ + String FORCE_COMMAND_PREFIX = String.format("<<%s>>", UUID.randomUUID().toString()); +} diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index 20f34fcf..fc97605f 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -23,7 +23,6 @@ import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalTwoBlocks; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.Helper; -import baritone.utils.command.BaritoneChatControl; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.Entity; @@ -45,6 +44,7 @@ import java.nio.IntBuffer; import java.util.Collections; import static org.lwjgl.opengl.GL11.*; +import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class GuiClick extends GuiScreen { @@ -88,7 +88,7 @@ public class GuiClick extends GuiScreen { .setColor(TextFormatting.WHITE) .setClickEvent(new ClickEvent( ClickEvent.Action.RUN_COMMAND, - BaritoneChatControl.FORCE_COMMAND_PREFIX + "help sel" + FORCE_COMMAND_PREFIX + "help sel" )); Helper.HELPER.logDirect(component); clickStart = null; diff --git a/src/main/java/baritone/utils/command/BaritoneChatControl.java b/src/main/java/baritone/utils/command/BaritoneChatControl.java index d62eaebf..352aff1c 100644 --- a/src/main/java/baritone/utils/command/BaritoneChatControl.java +++ b/src/main/java/baritone/utils/command/BaritoneChatControl.java @@ -44,27 +44,15 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.List; import java.util.Locale; -import java.util.UUID; import java.util.stream.Stream; +import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; + public class BaritoneChatControl implements Helper, AbstractGameEventListener { private static final Settings settings = BaritoneAPI.getSettings(); private final ICommandManager manager; - /** - * In certain cases chat components need to execute commands for you. For example, the paginator automatically runs - * commands when you click the forward and back arrows to show you the previous/next page. - *

- * If the prefix is changed in the meantime, then the command will go to chat. That's no good. So here's a permanent - * prefix that forces a command to run, regardless of the current prefix, chat/prefix control being enabled, etc. - *

- * If used right (by both developers and users), it should be impossible to expose a command accidentally to the - * server. As a rule of thumb, if you have a clickable chat component, always use this prefix. If you're suggesting - * a command (a component that puts text into your text box, or something else), use {@link Settings#prefix}. - */ - public static String FORCE_COMMAND_PREFIX = String.format("<<%s>>", UUID.randomUUID().toString()); - public BaritoneChatControl(IBaritone baritone) { this.manager = baritone.getCommandManager(); baritone.getGameEventHandler().registerEventListener(this); diff --git a/src/main/java/baritone/utils/command/defaults/HelpCommand.java b/src/main/java/baritone/utils/command/defaults/HelpCommand.java index 43d9829c..a9d0e104 100644 --- a/src/main/java/baritone/utils/command/defaults/HelpCommand.java +++ b/src/main/java/baritone/utils/command/defaults/HelpCommand.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import static baritone.utils.command.BaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class HelpCommand extends Command { diff --git a/src/main/java/baritone/utils/command/defaults/SetCommand.java b/src/main/java/baritone/utils/command/defaults/SetCommand.java index 822e042a..48c4580f 100644 --- a/src/main/java/baritone/utils/command/defaults/SetCommand.java +++ b/src/main/java/baritone/utils/command/defaults/SetCommand.java @@ -41,7 +41,7 @@ import java.util.stream.Stream; import static baritone.api.utils.SettingsUtil.settingTypeToString; import static baritone.api.utils.SettingsUtil.settingValueToString; -import static baritone.utils.command.BaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class SetCommand extends Command { diff --git a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java b/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java index b205048b..01f5817e 100644 --- a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java +++ b/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java @@ -43,7 +43,7 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Stream; -import static baritone.utils.command.BaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class WaypointsCommand extends Command {