[CHANGE] Change hook in point for ChatEvent to fix compat with chat modification mods
This commit is contained in:
@@ -2,8 +2,10 @@ package com.hypherionmc.craterlib.mixin.events;
|
|||||||
|
|
||||||
import com.hypherionmc.craterlib.api.event.server.CraterServerChatEvent;
|
import com.hypherionmc.craterlib.api.event.server.CraterServerChatEvent;
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.chat.PlayerChatMessage;
|
import net.minecraft.network.chat.PlayerChatMessage;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.network.FilteredText;
|
||||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@@ -11,15 +13,19 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(ServerGamePacketListenerImpl.class)
|
@Mixin(value = ServerGamePacketListenerImpl.class, priority = Integer.MIN_VALUE)
|
||||||
public class ServerGamePacketListenerImplMixin {
|
public class ServerGamePacketListenerImplMixin {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public ServerPlayer player;
|
public ServerPlayer player;
|
||||||
|
|
||||||
@Inject(method = "broadcastChatMessage", at = @At("HEAD"), cancellable = true)
|
@Inject(
|
||||||
private void injectChatEvent(PlayerChatMessage chatMessage, CallbackInfo ci) {
|
method = "lambda$handleChat$6",
|
||||||
CraterServerChatEvent event = new CraterServerChatEvent(this.player, chatMessage.decoratedContent().getString(), chatMessage.decoratedContent());
|
at = @At("HEAD"),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
private void injectChatEvent(PlayerChatMessage arg, Component arg2, FilteredText arg3, CallbackInfo ci) {
|
||||||
|
CraterServerChatEvent event = new CraterServerChatEvent(this.player, arg.decoratedContent().getString(), arg.decoratedContent());
|
||||||
CraterEventBus.INSTANCE.postEvent(event);
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
if (event.wasCancelled())
|
if (event.wasCancelled())
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
Reference in New Issue
Block a user