do the same for chomens chat parser mabe
This commit is contained in:
parent
4dc7a84972
commit
04cbb51df6
1 changed files with 14 additions and 4 deletions
|
@ -7,8 +7,10 @@ import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerMessage;
|
||||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||||
import net.kyori.adventure.text.Component;
|
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 java.util.List;
|
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
|
// 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
|
// custom chat that uses the `[%s] %s › %s` translation or %s %s › %s
|
||||||
|
@ -30,14 +32,22 @@ public class ChomeNSCustomChatParser implements ChatParser {
|
||||||
final List<Component> args = message.args();
|
final List<Component> args = message.args();
|
||||||
if (args.size() < 3 || (!message.key().equals("[%s] %s › %s") && !message.key().equals("%s %s › %s"))) return null;
|
if (args.size() < 3 || (!message.key().equals("[%s] %s › %s") && !message.key().equals("%s %s › %s"))) return null;
|
||||||
|
|
||||||
final Component username = args.get(1);
|
final Component senderComponent = args.get(1);
|
||||||
final Component contents = args.get(2);
|
final Component contents = args.get(2);
|
||||||
|
|
||||||
final String stringUsername = ComponentUtilities.stringify(username);
|
MutablePlayerListEntry sender;
|
||||||
MutablePlayerListEntry sender = bot.players().getEntry(stringUsername);
|
final HoverEvent<?> hoverEvent = senderComponent.hoverEvent();
|
||||||
|
if (hoverEvent != null && hoverEvent.action().equals(HoverEvent.Action.SHOW_ENTITY)) {
|
||||||
|
HoverEvent.ShowEntity entityInfo = (HoverEvent.ShowEntity) hoverEvent.value();
|
||||||
|
final UUID senderUUID = entityInfo.id();
|
||||||
|
sender = bot.players().getEntry(senderUUID);
|
||||||
|
} else {
|
||||||
|
final String stringUsername = ComponentUtilities.stringify(senderComponent);
|
||||||
|
sender = bot.players().getEntry(stringUsername);
|
||||||
|
}
|
||||||
|
|
||||||
if (sender == null) return null;
|
if (sender == null) return null;
|
||||||
|
|
||||||
return new PlayerMessage(sender, username, contents);
|
return new PlayerMessage(sender, senderComponent, contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue