fix chat.type.text after ages

This commit is contained in:
Chayapak 2023-04-01 13:29:08 +07:00
parent 6f5587c232
commit 2dec676bdc

View file

@ -1,19 +1,16 @@
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.chatParsers.data.ChatParser;
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry;
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.PlayerMessage;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
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;
public class MinecraftChatParser implements ChatParser {
private final Bot bot;
@ -48,14 +45,10 @@ public class MinecraftChatParser implements ChatParser {
final Component senderComponent = args.get(0);
final Component contents = args.get(1);
// try to find the sender then make it a player list entry
final HoverEvent<?> hoverEvent = senderComponent.hoverEvent();
if (hoverEvent == null || !hoverEvent.action().equals(HoverEvent.Action.SHOW_ENTITY)) return null;
HoverEvent.ShowEntity entityInfo = (HoverEvent.ShowEntity) hoverEvent.value();
final UUID senderUUID = entityInfo.id();
final String stringUsername = ComponentUtilities.stringify(senderComponent);
MutablePlayerListEntry sender = bot.players().getEntry(stringUsername);
MutablePlayerListEntry sender = bot.players().getEntry(senderUUID);
if (sender == null) sender = new MutablePlayerListEntry(new GameProfile(senderUUID, null), GameMode.SURVIVAL, 0, entityInfo.name(), 0L, null, new byte[0]);
if (sender == null) return null;
parameters.put("sender", senderComponent);
parameters.put("contents", contents);