Skip to content

Commit

Permalink
prevent running meteor commands from clickevent
Browse files Browse the repository at this point in the history
Co-Authored-By: Damian <[email protected]>
  • Loading branch information
2 people authored and Wide-Cat committed Feb 11, 2024
1 parent ae0b8aa commit fca65be
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.commands.arguments.CompoundNbtTagArgumentType;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.NbtPathArgumentType;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
MutableText copyButton = Text.literal("NBT");
copyButton.setStyle(copyButton.getStyle()
.withFormatting(Formatting.UNDERLINE)
.withClickEvent(new ClickEvent(
.withClickEvent(new MeteorClickEvent(
ClickEvent.Action.RUN_COMMAND,
this.toString("copy")
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import meteordevelopment.meteorclient.systems.modules.movement.GUIMove;
import meteordevelopment.meteorclient.systems.modules.render.NoRender;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Style;
Expand All @@ -35,7 +36,7 @@ private void onRenderBackground(CallbackInfo info) {

@Inject(method = "handleTextClick", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 1, remap = false), cancellable = true)
private void onRunCommand(Style style, CallbackInfoReturnable<Boolean> cir) {
if (style.getClickEvent().getValue().startsWith(Config.get().prefix.get())) {
if (style.getClickEvent() instanceof MeteorClickEvent clickEvent && clickEvent.getValue().startsWith(Config.get().prefix.get())) {
try {
Commands.dispatch(style.getClickEvent().getValue().substring(Config.get().prefix.get().length()));
cir.setReturnValue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.MeteorIdentifier;
import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.orbit.EventHandler;
Expand Down Expand Up @@ -518,7 +519,7 @@ private MutableText getSendButton(String message) {

sendButton.setStyle(sendButton.getStyle()
.withFormatting(Formatting.DARK_RED)
.withClickEvent(new ClickEvent(
.withClickEvent(new MeteorClickEvent(
ClickEvent.Action.RUN_COMMAND,
Commands.get("say").toString(message)
))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

package meteordevelopment.meteorclient.utils.misc.text;

import net.minecraft.text.ClickEvent;
import net.minecraft.text.Style;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* This class does nothing except ensure that {@link ClickEvent}'s containing Meteor Client commands can only be executed if they come from the client.
* @see meteordevelopment.meteorclient.mixin.ScreenMixin#onRunCommand(Style, CallbackInfoReturnable)
*/
public class MeteorClickEvent extends ClickEvent {
public MeteorClickEvent(Action action, String value) {
super(action, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import meteordevelopment.meteorclient.pathing.BaritoneUtils;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.PostInit;
import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import net.minecraft.util.Pair;
Expand Down Expand Up @@ -248,7 +249,7 @@ public static MutableText formatCoords(Vec3d pos) {
));

if (BaritoneUtils.IS_AVAILABLE) {
style = style.withClickEvent(new ClickEvent(
style = style.withClickEvent(new MeteorClickEvent(
ClickEvent.Action.RUN_COMMAND,
String.format("%sgoto %d %d %d", BaritoneUtils.getPrefix(), (int) pos.x, (int) pos.y, (int) pos.z)
));
Expand Down

0 comments on commit fca65be

Please sign in to comment.