Chat message
This commit is contained in:
@@ -15,6 +15,9 @@ import mc.core.*;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.proto_125.netty.wrappers.WrapperNetChannel;
|
||||
import mc.core.network.proto_125.packets.*;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.helpers.BasicMarker;
|
||||
import org.slf4j.helpers.BasicMarkerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -24,6 +27,7 @@ import java.util.Optional;
|
||||
@Slf4j
|
||||
public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
private static final AttributeKey<Player> ATTR_PLAYER = AttributeKey.newInstance("ATTR_PLAYER");
|
||||
private static final Marker CHAT_MARKER = new BasicMarkerFactory().getMarker("Chat");
|
||||
@Autowired
|
||||
private Config config;
|
||||
@Autowired
|
||||
@@ -167,4 +171,9 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
Player player = channel.attr(ATTR_PLAYER).get();
|
||||
player.setFlying(packet.isFlying());
|
||||
}
|
||||
|
||||
public void onChatMessagePacket(Channel channel, ChatMessagePacket packet) {
|
||||
log.info(CHAT_MARKER, "<{}>: {}", channel.attr(ATTR_PLAYER).get().getName(), packet.getMessage());
|
||||
playerManager.getBroadcastChannel().writeAndFlush(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import io.netty.channel.Channel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import mc.core.network.NetChannel;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_125.packets.ChatMessagePacket;
|
||||
import mc.core.network.proto_125.packets.KeepAlivePacket;
|
||||
import mc.core.network.proto_125.packets.PingPacket;
|
||||
import mc.core.network.proto_125.packets.TimeUpdatePacket;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -26,6 +26,11 @@ public class WrapperNetChannel implements NetChannel {
|
||||
channel.writeAndFlush(new TimeUpdatePacket(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChatMessage(String message) {
|
||||
channel.writeAndFlush(new ChatMessagePacket(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAndFlush(SCPacket pkt) {
|
||||
channel.writeAndFlush(pkt);
|
||||
|
||||
Reference in New Issue
Block a user