|
2 | 2 |
|
3 | 3 | import com.mojang.blaze3d.systems.RenderSystem; |
4 | 4 | import io.github.techstreet.dfscript.DFScript; |
5 | | -import io.github.techstreet.dfscript.event.BuildModeEvent; |
6 | | -import io.github.techstreet.dfscript.event.DevModeEvent; |
7 | | -import io.github.techstreet.dfscript.event.PlayModeEvent; |
8 | | -import io.github.techstreet.dfscript.event.ReceiveChatEvent; |
9 | | -import io.github.techstreet.dfscript.event.RecieveSoundEvent; |
10 | | -import io.github.techstreet.dfscript.event.ServerJoinEvent; |
11 | | -import io.github.techstreet.dfscript.event.ServerLeaveEvent; |
| 5 | +import io.github.techstreet.dfscript.event.*; |
12 | 6 | import io.github.techstreet.dfscript.event.system.EventManager; |
13 | 7 | import io.github.techstreet.dfscript.util.hypercube.HypercubeRank; |
14 | 8 | import io.github.techstreet.dfscript.util.hypercube.HypercubeUtil; |
15 | 9 | import java.net.InetSocketAddress; |
16 | 10 | import net.minecraft.client.network.ClientPlayNetworkHandler; |
17 | 11 | import net.minecraft.network.ClientConnection; |
18 | 12 | import net.minecraft.network.packet.s2c.play.*; |
| 13 | +import net.minecraft.text.Text; |
19 | 14 | import org.spongepowered.asm.mixin.Mixin; |
20 | 15 | import org.spongepowered.asm.mixin.injection.At; |
21 | 16 | import org.spongepowered.asm.mixin.injection.Inject; |
22 | 17 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
23 | 19 |
|
24 | 20 | @Mixin(ClientPlayNetworkHandler.class) |
25 | 21 | public class MClientPlayNetworkHandler { |
@@ -90,6 +86,25 @@ private void onDisconnect(DisconnectS2CPacket packet, CallbackInfo ci) { |
90 | 86 | EventManager.getInstance().dispatch(event); |
91 | 87 | } |
92 | 88 |
|
| 89 | + @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) |
| 90 | + private void chat(String content, CallbackInfo ci) { |
| 91 | + SendChatEvent event = new SendChatEvent(content); |
| 92 | + EventManager.getInstance().dispatch(event); |
| 93 | + if (event.isCancelled()) { |
| 94 | + ci.cancel(); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + @Inject(method = "sendCommand(Ljava/lang/String;)Z", at = @At("HEAD"), cancellable = true) |
| 99 | + private void command(String command, CallbackInfoReturnable<Boolean> ci) { |
| 100 | + if(command.startsWith("scripts")) return; |
| 101 | + SendChatEvent event = new SendChatEvent("/"+command); |
| 102 | + EventManager.getInstance().dispatch(event); |
| 103 | + if (event.isCancelled()) { |
| 104 | + ci.cancel(); |
| 105 | + } |
| 106 | + } |
| 107 | + |
93 | 108 | /*@Inject(method = "onPlaySound", at = @At("HEAD"), cancellable = true) |
94 | 109 | private void onPlaySound(PlaySoundS2CPacket packet, CallbackInfo ci) { |
95 | 110 | RecieveSoundEvent event = new RecieveSoundEvent(packet); |
|
0 commit comments