some stuff about the chat parsers
This commit is contained in:
parent
0931739856
commit
efb8e3ad41
3 changed files with 13 additions and 18 deletions
|
@ -9,22 +9,18 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class MinecraftChatParser implements ChatParser {
|
||||
private final Bot bot;
|
||||
|
||||
// ? Is such a mapping necessary?
|
||||
private static final Map<String, String> typeMap = new HashMap<>();
|
||||
private static final List<String> keys = new ArrayList<>();
|
||||
static {
|
||||
typeMap.put("chat.type.text", "minecraft:chat");
|
||||
typeMap.put("chat.type.announcement", "minecraft:say_command");
|
||||
typeMap.put("commands.message.display.incoming", "minecraft:msg_command");
|
||||
typeMap.put("chat.type.team.text", "minecraft:team_msg_command");
|
||||
typeMap.put("chat.type.emote", "minecraft:emote_command");
|
||||
keys.add("chat.type.text");
|
||||
keys.add("chat.type.announcement");
|
||||
keys.add("commands.message.display.incoming");
|
||||
keys.add("chat.type.team.text");
|
||||
keys.add("chat.type.emote");
|
||||
}
|
||||
|
||||
public MinecraftChatParser (Bot bot) {
|
||||
|
@ -40,7 +36,7 @@ public class MinecraftChatParser implements ChatParser {
|
|||
public PlayerMessage parse (TranslatableComponent message) {
|
||||
final List<Component> args = message.args();
|
||||
final String key = message.key();
|
||||
if (args.size() < 2 || !typeMap.containsKey(key)) return null;
|
||||
if (args.size() < 2 || !keys.contains(key)) return null;
|
||||
|
||||
final Component senderComponent = args.get(0);
|
||||
final Component contents = args.get(1);
|
||||
|
|
|
@ -12,12 +12,11 @@ import net.kyori.adventure.text.event.HoverEvent;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
// Might be a confusing name, but I mean the [Chat] chayapak custom chat thing or any other
|
||||
// custom chat that uses the `[%s] %s › %s` translation or %s %s › %s
|
||||
public class ChomeNSCustomChatParser implements ChatParser {
|
||||
// parses `[%s] %s › %s` translation or `%s %s › %s`
|
||||
public class U203aChatParser implements ChatParser {
|
||||
private final Bot bot;
|
||||
|
||||
public ChomeNSCustomChatParser (Bot bot) {
|
||||
public U203aChatParser(Bot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCh
|
|||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.ChomeNSCustomChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.U203aChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.CreayunChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.KaboomChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.MinecraftChatParser;
|
||||
|
@ -54,7 +54,7 @@ public class ChatPlugin extends Bot.Listener {
|
|||
chatParsers = new ArrayList<>();
|
||||
chatParsers.add(new MinecraftChatParser(bot));
|
||||
chatParsers.add(new KaboomChatParser(bot));
|
||||
chatParsers.add(new ChomeNSCustomChatParser(bot));
|
||||
chatParsers.add(new U203aChatParser(bot));
|
||||
chatParsers.add(new CreayunChatParser(bot));
|
||||
|
||||
bot.executor().scheduleAtFixedRate(this::sendChatTick, 0, queueDelay, TimeUnit.MILLISECONDS);
|
||||
|
|
Loading…
Reference in a new issue