FORCE_COMMAND_PREFIX should be exposed to the API

This commit is contained in:
Brady 2019-09-26 18:59:29 -05:00
parent 2f480fcec2
commit 0b39b3e7b4
No known key found for this signature in database
GPG Key ID: 73A788379A197567
6 changed files with 49 additions and 19 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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.
* <p>
* 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.
* <p>
* 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());
}

View File

@ -23,7 +23,6 @@ import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalTwoBlocks; import baritone.api.pathing.goals.GoalTwoBlocks;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Helper; import baritone.api.utils.Helper;
import baritone.utils.command.BaritoneChatControl;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -45,6 +44,7 @@ import java.nio.IntBuffer;
import java.util.Collections; import java.util.Collections;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class GuiClick extends GuiScreen { public class GuiClick extends GuiScreen {
@ -88,7 +88,7 @@ public class GuiClick extends GuiScreen {
.setColor(TextFormatting.WHITE) .setColor(TextFormatting.WHITE)
.setClickEvent(new ClickEvent( .setClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND, ClickEvent.Action.RUN_COMMAND,
BaritoneChatControl.FORCE_COMMAND_PREFIX + "help sel" FORCE_COMMAND_PREFIX + "help sel"
)); ));
Helper.HELPER.logDirect(component); Helper.HELPER.logDirect(component);
clickStart = null; clickStart = null;

View File

@ -44,27 +44,15 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.UUID;
import java.util.stream.Stream; import java.util.stream.Stream;
import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
public class BaritoneChatControl implements Helper, AbstractGameEventListener { public class BaritoneChatControl implements Helper, AbstractGameEventListener {
private static final Settings settings = BaritoneAPI.getSettings(); private static final Settings settings = BaritoneAPI.getSettings();
private final ICommandManager manager; 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.
* <p>
* 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.
* <p>
* 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) { public BaritoneChatControl(IBaritone baritone) {
this.manager = baritone.getCommandManager(); this.manager = baritone.getCommandManager();
baritone.getGameEventHandler().registerEventListener(this); baritone.getGameEventHandler().registerEventListener(this);

View File

@ -35,7 +35,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; 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 { public class HelpCommand extends Command {

View File

@ -41,7 +41,7 @@ import java.util.stream.Stream;
import static baritone.api.utils.SettingsUtil.settingTypeToString; import static baritone.api.utils.SettingsUtil.settingTypeToString;
import static baritone.api.utils.SettingsUtil.settingValueToString; 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 { public class SetCommand extends Command {

View File

@ -43,7 +43,7 @@ import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; 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 { public class WaypointsCommand extends Command {