3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-24 15:20:19 +01:00

More or less handle new chat type formats

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-05-05 11:20:03 +02:00
Ursprung ef0e412d36
Commit 34fa4f85db
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
5 geänderte Dateien mit 62 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -18,10 +18,12 @@
package com.viaversion.viabackwards;
import com.viaversion.viaversion.util.Config;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.File;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -33,6 +35,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
private boolean alwaysShowOriginalMobName;
private boolean fix1_13FormattedInventoryTitles;
private boolean handlePingsAsInvAcknowledgements;
private Map<String, String> chatTypeFormats;
public ViaBackwardsConfig(File configFile) {
super(configFile);
@ -51,6 +54,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
fix1_13FormattedInventoryTitles = getBoolean("fix-formatted-inventory-titles", true);
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false);
chatTypeFormats = get("chat-types", Map.class, new HashMap<String, String>());
}
@Override
@ -83,6 +87,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
return handlePingsAsInvAcknowledgements || Boolean.getBoolean("com.viaversion.handlePingsAsInvAcknowledgements");
}
@Override
public @Nullable String chatTypeFormat(final String translationKey) {
return chatTypeFormats.get(translationKey);
}
@Override
public URL getDefaultConfigURL() {
return getClass().getClassLoader().getResource("assets/viabackwards/config.yml");

Datei anzeigen

@ -17,6 +17,8 @@
*/
package com.viaversion.viabackwards.api;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface ViaBackwardsConfig {
/**
@ -50,4 +52,6 @@ public interface ViaBackwardsConfig {
boolean alwaysShowOriginalMobName();
boolean handlePingsAsInvAcknowledgements();
@Nullable String chatTypeFormat(String translationKey);
}

Datei anzeigen

@ -27,6 +27,7 @@ import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.packets.EntityP
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19Types;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
@ -35,6 +36,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.libs.kyori.adventure.text.TextReplacementConfig;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
@ -53,6 +55,7 @@ import java.util.UUID;
public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPackets1_19, ClientboundPackets1_18, ServerboundPackets1_19, ServerboundPackets1_17> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings();
private static final String[] CHAT_KEYS = {"chat.type.text", null, null, "chat.type.announcement", "commands.message.display.incoming", "chat.type.team.text", "chat.type.emote", null};
private static final UUID ZERO_UUID = new UUID(0, 0);
private static final byte[] EMPTY_BYTES = new byte[0];
private final EntityPackets1_19 entityRewriter = new EntityPackets1_19(this);
@ -177,35 +180,21 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
}
});
//TODO Handle chat formats once they're stable
registerClientbound(ClientboundPackets1_19.PLAYER_CHAT, ClientboundPackets1_18.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.COMPONENT); // Message
handler(wrapper -> {
int type = wrapper.read(Type.VAR_INT);
if (type > 2) {
type = 0; // Chat
}
wrapper.write(Type.BYTE, (byte) type);
});
map(Type.VAR_INT, Type.BYTE); // Chat type
map(Type.UUID); // Sender
handler(wrapper -> {
final JsonElement senderName = wrapper.read(Type.COMPONENT);
wrapper.read(Type.COMPONENT); // Team name
wrapper.read(Type.LONG); // Timestamp
wrapper.read(Type.LONG); // Salt
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
final JsonElement teamName = wrapper.read(Type.COMPONENT);
final JsonElement element = wrapper.get(Type.COMPONENT, 0);
translatableRewriter.processText(element);
Component component = GsonComponentSerializer.gson().deserializeFromTree(element);
component = Component.text().append(Component.text("<Tis I, "))
.append(GsonComponentSerializer.gson().deserializeFromTree(senderName))
.append(Component.text("> ")).append(component).build();
wrapper.set(Type.COMPONENT, 0, GsonComponentSerializer.gson().serializeToTree(component));
handleChatType(wrapper, senderName, teamName, element);
});
read(Type.LONG); // Timestamp
read(Type.LONG); // Salt
read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
}
});
@ -213,15 +202,9 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
@Override
public void registerMap() {
map(Type.COMPONENT); // Message
handler(wrapper -> {
int type = wrapper.read(Type.VAR_INT);
if (type > 2) {
type = 0; // Chat
}
wrapper.write(Type.BYTE, (byte) type);
});
map(Type.VAR_INT, Type.BYTE); // Chat type
create(Type.UUID, ZERO_UUID); // Sender
handler(wrapper -> translatableRewriter.processText(wrapper.get(Type.COMPONENT, 0)));
handler(wrapper -> handleChatType(wrapper, null, null, wrapper.get(Type.COMPONENT, 0)));
}
});
@ -304,4 +287,32 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
public ItemRewriter getItemRewriter() {
return blockItemPackets;
}
private TextReplacementConfig replace(final JsonElement replacement) {
return TextReplacementConfig.builder().matchLiteral("%s").replacement(GsonComponentSerializer.gson().deserializeFromTree(replacement)).once().build();
}
//TODO keep updated, sanity checks for system messages
private void handleChatType(final PacketWrapper wrapper, final JsonElement senderName, final JsonElement teamName, final JsonElement text) throws Exception {
translatableRewriter.processText(text);
final byte type = wrapper.get(Type.BYTE, 0);
if (type > 2) {
wrapper.set(Type.BYTE, 0, (byte) 0); // Chat type
}
final String key = CHAT_KEYS[type];
if (key != null) {
Component component = Component.text(ViaBackwards.getConfig().chatTypeFormat(key));
if (key.equals("chat.type.team.text")) {
//TODO team message broken...?
component = component.replaceText(replace(teamName));
}
if (senderName != null) {
component = component.replaceText(replace(senderName));
}
component = component.replaceText(replace(text));
wrapper.set(Type.COMPONENT, 0, GsonComponentSerializer.gson().serializeToTree(component));
}
}
}

Datei anzeigen

@ -19,4 +19,12 @@ fix-formatted-inventory-titles: true
#
# Sends inventory acknowledgement packets to act as a replacement for ping packets for sub 1.17 clients.
# This only takes effect for ids in the short range. Useful for anticheat compatibility.
handle-pings-as-inv-acknowledgements: false
handle-pings-as-inv-acknowledgements: false
#
# Chat type formats used for sub 1.19 clients.
chat-types:
"chat.type.text": "<%s> %s"
"chat.type.announcement": "[%s] %s"
"commands.message.display.incoming": "%s whispers to you: %s"
"chat.type.team.text": "%s <%s> %s"
"chat.type.emote": "* %s %s"

Datei anzeigen

@ -71,7 +71,7 @@
"item.minecraft.mangrove_boat": "Mangrove Boat",
"item.minecraft.recovery_compass": "Recovery Compass",
"item.minecraft.music_disc_5": "Music Disc",
"item.minecraft.music_disc_5.desc": "Samuel <EFBFBD>berg - 5",
"item.minecraft.music_disc_5.desc": "Samuel Åberg - 5",
"item.minecraft.mangrove_chest_boat": "Mangrove Boat with Chest",
"item.minecraft.disc_fragment_5": "Disc Fragment",
"item.minecraft.disc_fragment_5.desc": "Music Disc - 5",