add creayun chat parser
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package land.chipmunk.chayapak.chomens_bot.chatParsers;
|
||||
|
||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.ChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerMessage;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CreayunChatParser implements ChatParser {
|
||||
private final Bot bot;
|
||||
|
||||
// is parsing creayun chat using regex a good idea?
|
||||
// mabe mabe mabe
|
||||
// it doesn't use like translation or anything
|
||||
private static final Pattern PATTERN = Pattern.compile("([^ ]*) » (.*)");
|
||||
|
||||
public CreayunChatParser (Bot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerMessage parse (Component message) {
|
||||
final String stringified = ComponentUtilities.stringify(message);
|
||||
|
||||
final Matcher matcher = PATTERN.matcher(stringified);
|
||||
|
||||
if (matcher.find()) {
|
||||
final String displayName = matcher.group(1);
|
||||
final String contents = matcher.group(2);
|
||||
|
||||
MutablePlayerListEntry sender = bot.players().getEntry(displayName);
|
||||
if (sender == null) sender = new MutablePlayerListEntry(new GameProfile(new UUID(0L, 0L), null), GameMode.SURVIVAL, 0, Component.text(displayName), 0L, null, new byte[0], true);
|
||||
|
||||
return new PlayerMessage(sender, Component.text(displayName), Component.text(contents));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ 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.CreayunChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.KaboomChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.MinecraftChatParser;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.commandSpy.CommandSpyParser;
|
||||
@@ -55,6 +56,7 @@ public class ChatPlugin extends Bot.Listener {
|
||||
chatParsers.add(new MinecraftChatParser(bot));
|
||||
chatParsers.add(new KaboomChatParser(bot));
|
||||
chatParsers.add(new ChomeNSCustomChatParser(bot));
|
||||
chatParsers.add(new CreayunChatParser(bot));
|
||||
|
||||
bot.executor().scheduleAtFixedRate(this::_sendChatTick, 0, 1, TimeUnit.MILLISECONDS);
|
||||
bot.executor().scheduleAtFixedRate(this::sendChatTick, 0, queueDelay, TimeUnit.MILLISECONDS);
|
||||
|
||||
Reference in New Issue
Block a user