Skip to content

Commit c1016fc

Browse files
committed
fixed OnSendChat not working for commands expect /scripts
1 parent ccac5b8 commit c1016fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import io.github.techstreet.dfscript.event.system.EventManager;
66
import net.minecraft.client.network.ClientPlayerEntity;
77
import net.minecraft.text.Text;
8+
import org.jetbrains.annotations.Nullable;
89
import org.spongepowered.asm.mixin.Mixin;
910
import org.spongepowered.asm.mixin.injection.At;
1011
import org.spongepowered.asm.mixin.injection.Inject;
1112
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1214

1315
@Mixin(ClientPlayerEntity.class)
1416
public class MLocalPlayer {
@@ -22,6 +24,24 @@ private void chat(String message, Text preview, CallbackInfo ci) {
2224
}
2325
}
2426

27+
@Inject(method = "sendCommand", at = @At("HEAD"), cancellable = true)
28+
private void command(String command, CallbackInfoReturnable<Boolean> ci) {
29+
SendChatEvent event = new SendChatEvent(command);
30+
EventManager.getInstance().dispatch(event);
31+
if (event.isCancelled()) {
32+
ci.cancel();
33+
}
34+
}
35+
36+
@Inject(method = "sendCommandInternal", at = @At("HEAD"), cancellable = true)
37+
private void commandInterval(String command, @Nullable Text preview, CallbackInfo ci) {
38+
SendChatEvent event = new SendChatEvent(command);
39+
EventManager.getInstance().dispatch(event);
40+
if (event.isCancelled()) {
41+
ci.cancel();
42+
}
43+
}
44+
2545
@Inject(method = "tick", at = @At("HEAD"))
2646
private void tick(CallbackInfo ci) {
2747
EventManager.getInstance().dispatch(new TickEvent());

0 commit comments

Comments
 (0)