3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

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

Dieser Commit ist enthalten in:
Valaphee The Meerkat 2023-04-30 03:41:14 +02:00 committet von GitHub
Ursprung baae46822e
Commit 4d929f8a2c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 10 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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();

Datei anzeigen

@ -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;
} }