Move outbound chat listener

This commit is contained in:
Draycia committed 2022-07-17 20:22:07 -07:00
1 parent 9875ef1b50
commit c27526dd17
3 files changed
+21 -46

No files matched your search

@@ -1,44 +0,0 @@
/*
* CarbonChat
*
* Copyright (c) 2021 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.fabric.mixin;
import java.util.UUID;
import net.draycia.carbon.fabric.CarbonChatFabric;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(ServerGamePacketListenerImpl.class)
abstract class PacketListenerMixin {
@ModifyVariable(at = @At("HEAD"), index = 1, method = "send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", argsOnly = true)
private Packet<?> sendPacket(final Packet<?> packet) {
if (packet instanceof ClientboundPlayerChatPacket chatPacket) {
final UUID uuid = UUID.nameUUIDFromBytes(chatPacket.message().headerSignature().bytes());
CarbonChatFabric.addMessageSignature(uuid, chatPacket.message().headerSignature());
}
return packet;
}
}
@@ -19,9 +19,15 @@
*/
package net.draycia.carbon.fabric.mixin;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import java.util.UUID;
import net.draycia.carbon.fabric.CarbonChatFabric;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
@@ -31,7 +37,10 @@ import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ServerGamePacketListenerImpl.class)
abstract class ServerGamePacketListenerImplMixin {
@@ -58,4 +67,15 @@ abstract class ServerGamePacketListenerImplMixin {
}
}
@Inject(
method = "send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V",
at = @At("HEAD")
)
private void sendPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericFutureListener, CallbackInfo ci) {
if (packet instanceof ClientboundPlayerChatPacket chatPacket) {
final UUID uuid = UUID.nameUUIDFromBytes(chatPacket.message().headerSignature().bytes());
CarbonChatFabric.addMessageSignature(uuid, chatPacket.message().headerSignature());
}
}
}
@@ -6,8 +6,7 @@
"mixins": [
"ServerGamePacketListenerImplMixin",
"ServerPlayerMixin",
"PlayerListMixin",
"PacketListenerMixin"
"PlayerListMixin"
],
"client": [
],