Archived
0

Chat processor

This commit is contained in:
2018-05-06 14:20:58 +03:00
parent 31f3d21997
commit e83d82923f
4 changed files with 50 additions and 6 deletions

View File

@@ -12,13 +12,13 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j;
import mc.core.*;
import mc.core.chat.ChatProcessor;
import mc.core.chat.ChatStyle;
import mc.core.events.*;
import mc.core.network.CSPacket;
import mc.core.network.proto_125.netty.wrappers.WrapperNetChannel;
import mc.core.network.proto_125.packets.*;
import mc.core.world.World;
import org.slf4j.Marker;
import org.slf4j.helpers.BasicMarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.lang.reflect.Method;
@@ -28,13 +28,14 @@ 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
private PlayerManager playerManager;
@Autowired
private World world;
@Autowired
private ChatProcessor chatProcessor;
@Override
public void channelInactive(ChannelHandlerContext context) throws Exception {
@@ -201,7 +202,9 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
}
private void onChatMessagePacket(Channel channel, ChatMessagePacket packet) {
log.info(CHAT_MARKER, "<{}>: {}", channel.attr(ATTR_PLAYER).get().getName(), ChatStyle.escapeStyle(packet.getMessage()));
playerManager.getBroadcastChannel().writeAndFlush(packet);
chatProcessor.process(
channel.attr(ATTR_PLAYER).get(),
packet.getMessage()
);
}
}