Chat processor
This commit is contained in:
15
core/src/main/java/mc/core/chat/ChatProcessor.java
Normal file
15
core/src/main/java/mc/core/chat/ChatProcessor.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2018-05-06
|
||||||
|
*/
|
||||||
|
package mc.core.chat;
|
||||||
|
|
||||||
|
import mc.core.Player;
|
||||||
|
import org.slf4j.Marker;
|
||||||
|
import org.slf4j.helpers.BasicMarkerFactory;
|
||||||
|
|
||||||
|
public abstract class ChatProcessor {
|
||||||
|
protected static final Marker CHAT_MARKER = new BasicMarkerFactory().getMarker("Chat");
|
||||||
|
|
||||||
|
public abstract void process(Player player, String message);
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
* DmitriyMX <dimon550@gmail.com>
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
* 2018-04-30
|
* 2018-04-30
|
||||||
*/
|
*/
|
||||||
package mc.core;
|
package mc.core.chat;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
26
core/src/main/java/mc/core/chat/SimpleChatProcessor.java
Normal file
26
core/src/main/java/mc/core/chat/SimpleChatProcessor.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2018-05-06
|
||||||
|
*/
|
||||||
|
package mc.core.chat;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import mc.core.Player;
|
||||||
|
import mc.core.PlayerManager;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class SimpleChatProcessor extends ChatProcessor {
|
||||||
|
@Autowired
|
||||||
|
private PlayerManager playerManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(Player player, String message) {
|
||||||
|
log.info(CHAT_MARKER, "<{}> {}", player.getName(), ChatStyle.escapeStyle(message));
|
||||||
|
playerManager.getBroadcastChannel().sendChatMessage(
|
||||||
|
ChatStyle.GOLD + player.getName()
|
||||||
|
+ ChatStyle.GRAY + ": "
|
||||||
|
+ ChatStyle.WHITE + message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,13 +12,13 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
|||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.*;
|
import mc.core.*;
|
||||||
|
import mc.core.chat.ChatProcessor;
|
||||||
|
import mc.core.chat.ChatStyle;
|
||||||
import mc.core.events.*;
|
import mc.core.events.*;
|
||||||
import mc.core.network.CSPacket;
|
import mc.core.network.CSPacket;
|
||||||
import mc.core.network.proto_125.netty.wrappers.WrapperNetChannel;
|
import mc.core.network.proto_125.netty.wrappers.WrapperNetChannel;
|
||||||
import mc.core.network.proto_125.packets.*;
|
import mc.core.network.proto_125.packets.*;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
import org.slf4j.Marker;
|
|
||||||
import org.slf4j.helpers.BasicMarkerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -28,13 +28,14 @@ import java.util.Optional;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||||
private static final AttributeKey<Player> ATTR_PLAYER = AttributeKey.newInstance("ATTR_PLAYER");
|
private static final AttributeKey<Player> ATTR_PLAYER = AttributeKey.newInstance("ATTR_PLAYER");
|
||||||
private static final Marker CHAT_MARKER = new BasicMarkerFactory().getMarker("Chat");
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Config config;
|
private Config config;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlayerManager playerManager;
|
private PlayerManager playerManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
private World world;
|
private World world;
|
||||||
|
@Autowired
|
||||||
|
private ChatProcessor chatProcessor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext context) throws Exception {
|
public void channelInactive(ChannelHandlerContext context) throws Exception {
|
||||||
@@ -201,7 +202,9 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onChatMessagePacket(Channel channel, ChatMessagePacket packet) {
|
private void onChatMessagePacket(Channel channel, ChatMessagePacket packet) {
|
||||||
log.info(CHAT_MARKER, "<{}>: {}", channel.attr(ATTR_PLAYER).get().getName(), ChatStyle.escapeStyle(packet.getMessage()));
|
chatProcessor.process(
|
||||||
playerManager.getBroadcastChannel().writeAndFlush(packet);
|
channel.attr(ATTR_PLAYER).get(),
|
||||||
|
packet.getMessage()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user