Replace § in sign text and book editing operations (#3721)

This commit is contained in:
Valaphee The Meerkat 2023-04-30 03:41:14 +02:00 committed by GitHub
parent baae46822e
commit 4d929f8a2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -34,6 +34,7 @@ import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.geyser.util.SignUtils; import org.geysermc.geyser.util.SignUtils;
@Translator(packet = BlockEntityDataPacket.class) @Translator(packet = BlockEntityDataPacket.class)
@ -52,6 +53,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
} else { } else {
text = tag.getString("Text"); text = tag.getString("Text");
} }
text = MessageTranslator.convertToPlainText(text);
// Note: as of 1.18.30, only one packet is sent from Bedrock when the sign is finished. // Note: as of 1.18.30, only one packet is sent from Bedrock when the sign is finished.
// Previous versions did not have this behavior. // Previous versions did not have this behavior.
StringBuilder newMessage = new StringBuilder(); StringBuilder newMessage = new StringBuilder();

View file

@ -36,6 +36,7 @@ import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.translator.text.MessageTranslator;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
@ -68,19 +69,19 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
for (int i = pages.size(); i < page; i++) { for (int i = pages.size(); i < page; i++) {
pages.add(i, new StringTag("", "")); pages.add(i, new StringTag("", ""));
} }
pages.add(page, new StringTag("", packet.getText())); pages.add(page, new StringTag("", MessageTranslator.convertToPlainText(packet.getText())));
break; break;
} }
// Called whenever a page is modified // Called whenever a page is modified
case REPLACE_PAGE: { case REPLACE_PAGE: {
if (page < pages.size()) { if (page < pages.size()) {
pages.set(page, new StringTag("", packet.getText())); pages.set(page, new StringTag("", MessageTranslator.convertToPlainText(packet.getText())));
} else { } else {
// Add empty pages in between // Add empty pages in between
for (int i = pages.size(); i < page; i++) { for (int i = pages.size(); i < page; i++) {
pages.add(i, new StringTag("", "")); pages.add(i, new StringTag("", ""));
} }
pages.add(page, new StringTag("", packet.getText())); pages.add(page, new StringTag("", MessageTranslator.convertToPlainText(packet.getText())));
} }
break; break;
} }
@ -98,8 +99,8 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
break; break;
} }
case SIGN_BOOK: { case SIGN_BOOK: {
tag.put(new StringTag("author", packet.getAuthor())); tag.put(new StringTag("author", MessageTranslator.convertToPlainText(packet.getAuthor())));
tag.put(new StringTag("title", packet.getTitle())); tag.put(new StringTag("title", MessageTranslator.convertToPlainText(packet.getTitle())));
break; break;
} }
default: default:
@ -127,12 +128,11 @@ public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket>
String title; String title;
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) { if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
// Add title to packet so the server knows we're signing // Add title to packet so the server knows we're signing
if (packet.getTitle().getBytes(StandardCharsets.UTF_8).length > MAXIMUM_TITLE_LENGTH) { title = MessageTranslator.convertToPlainText(packet.getTitle());
if (title.getBytes(StandardCharsets.UTF_8).length > MAXIMUM_TITLE_LENGTH) {
session.getGeyser().getLogger().warning("Book title larger than server allows!"); session.getGeyser().getLogger().warning("Book title larger than server allows!");
return; return;
} }
title = packet.getTitle();
} else { } else {
title = null; title = null;
} }