blob: 877d540dc9d42f7531bcf3400fe8105c4f2931c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package cc.polyfrost.oneconfig.internal.mixin;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent;
import cc.polyfrost.oneconfig.events.event.SendPacketEvent;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S02PacketChat;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = NetHandlerPlayClient.class, priority = Integer.MAX_VALUE)
public class NetHandlerPlayClientMixin {
@Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true)
private void onSendPacket(Packet<?> p_147297_1_, CallbackInfo ci) {
SendPacketEvent event = new SendPacketEvent(p_147297_1_);
EventManager.INSTANCE.post(event);
if (event.isCancelled) {
ci.cancel();
}
}
@Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onClientChat(BLnet/minecraft/util/IChatComponent;)Lnet/minecraft/util/IChatComponent;", remap = false), cancellable = true, remap = true)
private void onClientChat(S02PacketChat packetIn, CallbackInfo ci) {
if (packetIn.getType() == 0) {
ChatReceiveEvent event = new ChatReceiveEvent(packetIn.getChatComponent());
EventManager.INSTANCE.post(event);
if (event.isCancelled) {
ci.cancel();
}
}
}
}
|