some stuff about the chat parsers

This commit is contained in:
Chayapak 2023-06-22 18:36:58 +07:00
parent 0931739856
commit efb8e3ad41
3 changed files with 13 additions and 18 deletions

View file

@ -9,22 +9,18 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class MinecraftChatParser implements ChatParser { public class MinecraftChatParser implements ChatParser {
private final Bot bot; private final Bot bot;
// ? Is such a mapping necessary? private static final List<String> keys = new ArrayList<>();
private static final Map<String, String> typeMap = new HashMap<>();
static { static {
typeMap.put("chat.type.text", "minecraft:chat"); keys.add("chat.type.text");
typeMap.put("chat.type.announcement", "minecraft:say_command"); keys.add("chat.type.announcement");
typeMap.put("commands.message.display.incoming", "minecraft:msg_command"); keys.add("commands.message.display.incoming");
typeMap.put("chat.type.team.text", "minecraft:team_msg_command"); keys.add("chat.type.team.text");
typeMap.put("chat.type.emote", "minecraft:emote_command"); keys.add("chat.type.emote");
} }
public MinecraftChatParser (Bot bot) { public MinecraftChatParser (Bot bot) {
@ -40,7 +36,7 @@ public class MinecraftChatParser implements ChatParser {
public PlayerMessage parse (TranslatableComponent message) { public PlayerMessage parse (TranslatableComponent message) {
final List<Component> args = message.args(); final List<Component> args = message.args();
final String key = message.key(); 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 senderComponent = args.get(0);
final Component contents = args.get(1); final Component contents = args.get(1);

View file

@ -12,12 +12,11 @@ import net.kyori.adventure.text.event.HoverEvent;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
// Might be a confusing name, but I mean the [Chat] chayapak custom chat thing or any other // parses `[%s] %s %s` translation or `%s %s %s`
// custom chat that uses the `[%s] %s %s` translation or %s %s %s public class U203aChatParser implements ChatParser {
public class ChomeNSCustomChatParser implements ChatParser {
private final Bot bot; private final Bot bot;
public ChomeNSCustomChatParser (Bot bot) { public U203aChatParser(Bot bot) {
this.bot = bot; this.bot = bot;
} }

View file

@ -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.Session;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import land.chipmunk.chayapak.chomens_bot.Bot; 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.CreayunChatParser;
import land.chipmunk.chayapak.chomens_bot.chatParsers.KaboomChatParser; import land.chipmunk.chayapak.chomens_bot.chatParsers.KaboomChatParser;
import land.chipmunk.chayapak.chomens_bot.chatParsers.MinecraftChatParser; import land.chipmunk.chayapak.chomens_bot.chatParsers.MinecraftChatParser;
@ -54,7 +54,7 @@ public class ChatPlugin extends Bot.Listener {
chatParsers = new ArrayList<>(); chatParsers = new ArrayList<>();
chatParsers.add(new MinecraftChatParser(bot)); chatParsers.add(new MinecraftChatParser(bot));
chatParsers.add(new KaboomChatParser(bot)); chatParsers.add(new KaboomChatParser(bot));
chatParsers.add(new ChomeNSCustomChatParser(bot)); chatParsers.add(new U203aChatParser(bot));
chatParsers.add(new CreayunChatParser(bot)); chatParsers.add(new CreayunChatParser(bot));
bot.executor().scheduleAtFixedRate(this::sendChatTick, 0, queueDelay, TimeUnit.MILLISECONDS); bot.executor().scheduleAtFixedRate(this::sendChatTick, 0, queueDelay, TimeUnit.MILLISECONDS);