Skip to content

Commit 7baf520

Browse files
committed
Make chatbox message name "format" only
1 parent 16832df commit 7baf520

File tree

4 files changed

+13
-31
lines changed

4 files changed

+13
-31
lines changed

src/main/java/cc/reconnected/chatbox/ClientPacketsHandler.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ public static void register() {
7878
var owner = PlayerData.getPlayer(ownerId);
7979

8080
var name = packet.name != null ? packet.name : owner.getEffectiveName();
81-
var message = TextComponents.buildChatbotMessage(name, packet.text, packet.mode, owner);
81+
var message = Component.empty()
82+
.append(TextComponents.sayPrefix)
83+
.appendSpace()
84+
.append(TextComponents.buildChatbotMessage(name, packet.text, packet.mode, owner));
8285

83-
var cbmsg = new ClientMessage(client.webSocket, packet.id != null ? packet.id : -1, MessageTypes.SAY, message, null);
84-
if(tryEnqueue(client.license.uuid(), cbmsg)) {
86+
var fullMessage = new ClientMessage(client.webSocket, packet.id != null ? packet.id : -1, MessageTypes.SAY, message, null);
87+
if(tryEnqueue(client.license.uuid(), fullMessage)) {
8588
client.webSocket.send(Chatbox.GSON.toJson(new SuccessPacket("message_queued", packet.id)));
8689
} else {
8790
var err = ClientErrors.RATE_LIMITED;
@@ -113,8 +116,8 @@ public static void register() {
113116
.appendSpace()
114117
.append(TextComponents.buildChatbotMessage(name, packet.text, packet.mode, owner));
115118

116-
var cbmsg = new ClientMessage(client.webSocket, packet.id != null ? packet.id : -1, MessageTypes.TELL, message, player.getUuid());
117-
if(tryEnqueue(client.license.uuid(), cbmsg)) {
119+
var fullMessage = new ClientMessage(client.webSocket, packet.id != null ? packet.id : -1, MessageTypes.TELL, message, player.getUuid());
120+
if(tryEnqueue(client.license.uuid(), fullMessage)) {
118121
client.webSocket.send(Chatbox.GSON.toJson(new SuccessPacket("message_queued", packet.id)));
119122
} else {
120123
var err = ClientErrors.RATE_LIMITED;

src/main/java/cc/reconnected/chatbox/parsers/MarkdownParser.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ public class MarkdownParser {
1515
MarkdownLiteParserV1.MarkdownFormat.URL
1616
};
1717

18-
public static final MarkdownFormat[] NAME = new MarkdownFormat[] {
19-
MarkdownLiteParserV1.MarkdownFormat.BOLD,
20-
MarkdownLiteParserV1.MarkdownFormat.ITALIC,
21-
MarkdownLiteParserV1.MarkdownFormat.UNDERLINE,
22-
MarkdownLiteParserV1.MarkdownFormat.STRIKETHROUGH,
23-
};
24-
2518
public static final NodeParser contentParser = createParser(ALL);
26-
public static final NodeParser nameParser = createParser(NAME);
2719

2820
public static NodeParser createParser(MarkdownFormat[] capabilities) {
2921
return new MarkdownLiteParserV1(

src/main/java/cc/reconnected/chatbox/parsers/MiniMessageSerializer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,8 @@ public class MiniMessageSerializer {
2222
StandardTags.translatable(),
2323
StandardTags.insertion()
2424
);
25-
public static final Set<TagResolver> labelTags = Set.of(
26-
StandardTags.color(),
27-
StandardTags.decorations(),
28-
StandardTags.gradient(),
29-
StandardTags.rainbow(),
30-
StandardTags.reset(),
31-
StandardTags.transition()
32-
);
3325

3426
public static final MiniMessage defaultSerializer = createSerializer(defaultTags);
35-
public static final MiniMessage labelSerializer = createSerializer(labelTags);
3627

3728
public static MiniMessage createSerializer(Collection<TagResolver> tags) {
3829
return MiniMessage.builder()

src/main/java/cc/reconnected/chatbox/utils/TextComponents.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public class TextComponents {
1717
.append(Component.text("CB PM").color(NamedTextColor.DARK_GRAY).hoverEvent(HoverEvent.showText(Component.text("This message was privately sent to you by an automated chatbot."))))
1818
.append(Component.text("]", NamedTextColor.GRAY));
1919

20-
public static final Style chatbotNameStyle = Style.style(NamedTextColor.WHITE);
20+
public static final Component sayPrefix = Component.empty()
21+
.append(Component.text("[", NamedTextColor.GRAY))
22+
.append(Component.text("CB").color(NamedTextColor.DARK_GRAY).hoverEvent(HoverEvent.showText(Component.text("This message was publicly sent by an automated chatbot."))))
23+
.append(Component.text("]", NamedTextColor.GRAY));
2124

2225
public static Component getChatbotName(Component name, PlayerData owner) {
2326
var ownerMeta = Component.text("Owned by " + owner.getEffectiveName());
@@ -26,25 +29,18 @@ public static Component getChatbotName(Component name, PlayerData owner) {
2629

2730
public static Component buildChatbotMessage(String label, String content, String type, PlayerData owner) {
2831
content = content.trim();
29-
label = label.trim();
30-
Component formattedLabel;
32+
Component formattedLabel = LegacyComponentSerializer.legacyAmpersand().deserialize(label.trim());
3133
Component formattedContent;
3234
if ("format".equals(type)) {
3335
formattedContent = LegacyComponentSerializer.legacyAmpersand().deserialize(content);
34-
formattedLabel = LegacyComponentSerializer.legacyAmpersand().deserialize(label);
3536
} else if ("markdown".equals(type)) {
36-
var rawLabel = MarkdownParser.nameParser.parseNode(label).toText();
3737
var rawContent = MarkdownParser.contentParser.parseNode(content).toText();
3838
var json = JSONComponentSerializer.json();
39-
40-
formattedLabel = json.deserialize(Text.Serializer.toJson(rawLabel));
4139
formattedContent = json.deserialize(Text.Serializer.toJson(rawContent));
4240
} else if("minimessage".equals(type)) {
43-
formattedLabel = MiniMessageSerializer.labelSerializer.deserialize(label);
4441
formattedContent = MiniMessageSerializer.defaultSerializer.deserialize(content);
4542
} else {
4643
formattedContent = Component.text(content);
47-
formattedLabel = Component.text(label);
4844
}
4945
return Component.empty()
5046
.append(getChatbotName(formattedLabel, owner))

0 commit comments

Comments
 (0)