Skip to content

Commit 55c41e5

Browse files
authored
fix command handling race condition (#5820)
1 parent a188df2 commit 55c41e5

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayNetworkHandlerMixin.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package meteordevelopment.meteorclient.mixin;
77

8+
import com.llamalad7.mixinextras.sugar.Local;
9+
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
810
import com.mojang.brigadier.exceptions.CommandSyntaxException;
911
import meteordevelopment.meteorclient.MeteorClient;
1012
import meteordevelopment.meteorclient.commands.Commands;
@@ -47,12 +49,6 @@ public abstract class ClientPlayNetworkHandlerMixin extends ClientCommonNetworkH
4749
@Shadow
4850
private ClientWorld world;
4951

50-
@Shadow
51-
public abstract void sendChatMessage(String content);
52-
53-
@Unique
54-
private boolean ignoreChatMessage;
55-
5652
@Unique
5753
private boolean worldNotNull;
5854

@@ -139,18 +135,16 @@ private void onItemPickupAnimation(ItemPickupAnimationS2CPacket packet, Callback
139135
}
140136

141137
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
142-
private void onSendChatMessage(String message, CallbackInfo ci) {
143-
if (ignoreChatMessage) return;
144-
138+
private void onSendChatMessage(String message, CallbackInfo ci, @Local(argsOnly = true) LocalRef<String> messageRef) {
145139
if (!message.startsWith(Config.get().prefix.get()) && !(BaritoneUtils.IS_AVAILABLE && message.startsWith(BaritoneUtils.getPrefix()))) {
146140
SendMessageEvent event = MeteorClient.EVENT_BUS.post(SendMessageEvent.get(message));
147141

148142
if (!event.isCancelled()) {
149-
ignoreChatMessage = true;
150-
sendChatMessage(event.message);
151-
ignoreChatMessage = false;
143+
messageRef.set(event.message);
144+
} else {
145+
ci.cancel();
152146
}
153-
ci.cancel();
147+
154148
return;
155149
}
156150

0 commit comments

Comments
 (0)