Chat message
This commit is contained in:
@@ -79,7 +79,9 @@ public class CommanderChatProcessor extends SimpleChatProcessor {
|
||||
String[] args = message.substring(idx).split(" ");
|
||||
commands.get(command).execute(player, args);
|
||||
} else {
|
||||
player.getChannel().sendChatMessage(UNKNOW_COMMAND_MSG.apply("command", command));
|
||||
player.getChannel().sendChatMessage(
|
||||
UNKNOW_COMMAND_MSG.apply("command", command),
|
||||
MessageType.SYSTEM_MESSAGE);
|
||||
}
|
||||
} else {
|
||||
super.process(player, message);
|
||||
|
||||
18
core/src/main/java/mc/core/chat/MessageType.java
Normal file
18
core/src/main/java/mc/core/chat/MessageType.java
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-06-24
|
||||
*/
|
||||
package mc.core.chat;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum MessageType {
|
||||
CHAT_MESSAGE(0), // chat box
|
||||
SYSTEM_MESSAGE(1), // chat box
|
||||
GAME_INFO(2); // above hotbar
|
||||
|
||||
private final int id;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
package mc.core.network;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import mc.core.chat.MessageType;
|
||||
import mc.core.player.Player;
|
||||
import mc.core.text.Text;
|
||||
|
||||
@@ -25,8 +26,8 @@ public class BroadcastNetChannel implements NetChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChatMessage(final Text text) {
|
||||
playerStream.forEach(player -> player.getChannel().sendChatMessage(text));
|
||||
public void sendChatMessage(final Text text, final MessageType type) {
|
||||
playerStream.forEach(player -> player.getChannel().sendChatMessage(text, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,12 +4,16 @@
|
||||
*/
|
||||
package mc.core.network;
|
||||
|
||||
import mc.core.chat.MessageType;
|
||||
import mc.core.text.Text;
|
||||
|
||||
public interface NetChannel {
|
||||
void sendKeepAlive();
|
||||
void sendTimeUpdate(long time, long age);
|
||||
void sendChatMessage(Text text);
|
||||
default void sendChatMessage(Text text) {
|
||||
sendChatMessage(text, MessageType.CHAT_MESSAGE);
|
||||
}
|
||||
void sendChatMessage(Text text, MessageType type);
|
||||
|
||||
void writeAndFlush(SCPacket pkt);
|
||||
void write(SCPacket pkt);
|
||||
|
||||
@@ -47,7 +47,7 @@ public enum State {
|
||||
ImmutableMap.<Integer, Class<? extends CSPacket>>builder()
|
||||
.put(0x00, TeleportConfirmPacket.class)
|
||||
.put(0x01, TabCompletePacket.class)
|
||||
.put(0x02, ChatMessagePacket.class)
|
||||
.put(0x02, ChatMessageClientPacket.class)
|
||||
.put(0x04, ClientSettingsPacket.class)
|
||||
.put(0x09, PluginMessagePacket.class)
|
||||
.put(0x0B, KeepAlivePacket.class)
|
||||
@@ -56,6 +56,7 @@ public enum State {
|
||||
.put(0x1D, AnimationPacket.class)
|
||||
.build(),
|
||||
ImmutableMap.<Class<? extends SCPacket>, Integer>builder()
|
||||
.put(ChatMessageServerPacket.class, 0x0F)
|
||||
.put(PluginMessagePacket.class, 0x18)
|
||||
.put(KeepAlivePacket.class, 0x1F)
|
||||
.put(JoinGamePacket.class, 0x23)
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2.packets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.NetStream;
|
||||
|
||||
public class ChatMessagePacket implements CSPacket {
|
||||
@Getter
|
||||
@ToString
|
||||
public class ChatMessageClientPacket implements CSPacket {
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-06-24
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2.packets;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.chat.MessageType;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
||||
import mc.core.text.Text;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Setter
|
||||
@ToString
|
||||
public class ChatMessageServerPacket implements SCPacket {
|
||||
private Text text;
|
||||
private MessageType type;
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetStream netStream) {
|
||||
netStream.writeString(TextSerializer.serialize(text).toString());
|
||||
netStream.writeByte(type.getId());
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,23 @@
|
||||
package mc.core.network.proto_1_12_2.netty.handlers;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import mc.core.chat.ChatProcessor;
|
||||
import mc.core.network.proto_1_12_2.TeleportManager;
|
||||
import mc.core.network.proto_1_12_2.packets.ChatMessageClientPacket;
|
||||
import mc.core.network.proto_1_12_2.packets.ClientSettingsPacket;
|
||||
import mc.core.network.proto_1_12_2.packets.PlayerPositionAndLookPacket;
|
||||
import mc.core.network.proto_1_12_2.packets.TeleportConfirmPacket;
|
||||
import mc.core.player.Player;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_PLAYER;
|
||||
|
||||
@Component
|
||||
public class PlayHandler extends AbstractStateHandler implements PlayStateHandler {
|
||||
@Autowired
|
||||
private ChatProcessor chatProcessor;
|
||||
|
||||
private TeleportManager teleport = TeleportManager.getInstance();
|
||||
|
||||
@Handler
|
||||
@@ -49,4 +55,12 @@ public class PlayHandler extends AbstractStateHandler implements PlayStateHandle
|
||||
player.getLocation().set(packet.getLocation());
|
||||
player.getLook().set(packet.getLook());
|
||||
}
|
||||
|
||||
@Handler
|
||||
public void onChat(Channel channel, ChatMessageClientPacket packet) {
|
||||
chatProcessor.process(
|
||||
channel.attr(ATTR_PLAYER).get(),
|
||||
packet.getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ package mc.core.network.proto_1_12_2.netty.wrappers;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import mc.core.chat.MessageType;
|
||||
import mc.core.network.NetChannel;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.packets.ChatMessageServerPacket;
|
||||
import mc.core.network.proto_1_12_2.packets.KeepAlivePacket;
|
||||
import mc.core.network.proto_1_12_2.packets.TimeUpdatePacket;
|
||||
import mc.core.text.Text;
|
||||
@@ -30,8 +32,8 @@ public class WrapperNetChannel implements NetChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChatMessage(Text text) {
|
||||
|
||||
public void sendChatMessage(Text text, MessageType type) {
|
||||
writeAndFlush(new ChatMessageServerPacket(text, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user