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:
Ursprung
ef0e412d36
Commit
34fa4f85db
@ -18,10 +18,12 @@
|
|||||||
package com.viaversion.viabackwards;
|
package com.viaversion.viabackwards;
|
||||||
|
|
||||||
import com.viaversion.viaversion.util.Config;
|
import com.viaversion.viaversion.util.Config;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -33,6 +35,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
|||||||
private boolean alwaysShowOriginalMobName;
|
private boolean alwaysShowOriginalMobName;
|
||||||
private boolean fix1_13FormattedInventoryTitles;
|
private boolean fix1_13FormattedInventoryTitles;
|
||||||
private boolean handlePingsAsInvAcknowledgements;
|
private boolean handlePingsAsInvAcknowledgements;
|
||||||
|
private Map<String, String> chatTypeFormats;
|
||||||
|
|
||||||
public ViaBackwardsConfig(File configFile) {
|
public ViaBackwardsConfig(File configFile) {
|
||||||
super(configFile);
|
super(configFile);
|
||||||
@ -51,6 +54,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
|||||||
fix1_13FormattedInventoryTitles = getBoolean("fix-formatted-inventory-titles", true);
|
fix1_13FormattedInventoryTitles = getBoolean("fix-formatted-inventory-titles", true);
|
||||||
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
|
alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true);
|
||||||
handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false);
|
handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false);
|
||||||
|
chatTypeFormats = get("chat-types", Map.class, new HashMap<String, String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,6 +87,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
|||||||
return handlePingsAsInvAcknowledgements || Boolean.getBoolean("com.viaversion.handlePingsAsInvAcknowledgements");
|
return handlePingsAsInvAcknowledgements || Boolean.getBoolean("com.viaversion.handlePingsAsInvAcknowledgements");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String chatTypeFormat(final String translationKey) {
|
||||||
|
return chatTypeFormats.get(translationKey);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getDefaultConfigURL() {
|
public URL getDefaultConfigURL() {
|
||||||
return getClass().getClassLoader().getResource("assets/viabackwards/config.yml");
|
return getClass().getClassLoader().getResource("assets/viabackwards/config.yml");
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viabackwards.api;
|
package com.viaversion.viabackwards.api;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public interface ViaBackwardsConfig {
|
public interface ViaBackwardsConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,4 +52,6 @@ public interface ViaBackwardsConfig {
|
|||||||
boolean alwaysShowOriginalMobName();
|
boolean alwaysShowOriginalMobName();
|
||||||
|
|
||||||
boolean handlePingsAsInvAcknowledgements();
|
boolean handlePingsAsInvAcknowledgements();
|
||||||
|
|
||||||
|
@Nullable String chatTypeFormat(String translationKey);
|
||||||
}
|
}
|
||||||
|
@ -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.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19Types;
|
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.packet.State;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||||
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
|
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.data.entity.EntityTrackerBase;
|
||||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
|
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.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||||
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
|
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 final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPackets1_19, ClientboundPackets1_18, ServerboundPackets1_19, ServerboundPackets1_17> {
|
||||||
|
|
||||||
public static final BackwardsMappings MAPPINGS = new BackwardsMappings();
|
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 UUID ZERO_UUID = new UUID(0, 0);
|
||||||
private static final byte[] EMPTY_BYTES = new byte[0];
|
private static final byte[] EMPTY_BYTES = new byte[0];
|
||||||
private final EntityPackets1_19 entityRewriter = new EntityPackets1_19(this);
|
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() {
|
registerClientbound(ClientboundPackets1_19.PLAYER_CHAT, ClientboundPackets1_18.CHAT_MESSAGE, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.COMPONENT); // Message
|
map(Type.COMPONENT); // Message
|
||||||
handler(wrapper -> {
|
map(Type.VAR_INT, Type.BYTE); // Chat type
|
||||||
int type = wrapper.read(Type.VAR_INT);
|
|
||||||
if (type > 2) {
|
|
||||||
type = 0; // Chat
|
|
||||||
}
|
|
||||||
wrapper.write(Type.BYTE, (byte) type);
|
|
||||||
});
|
|
||||||
map(Type.UUID); // Sender
|
map(Type.UUID); // Sender
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
final JsonElement senderName = wrapper.read(Type.COMPONENT);
|
final JsonElement senderName = wrapper.read(Type.COMPONENT);
|
||||||
wrapper.read(Type.COMPONENT); // Team name
|
final JsonElement teamName = wrapper.read(Type.COMPONENT);
|
||||||
wrapper.read(Type.LONG); // Timestamp
|
|
||||||
wrapper.read(Type.LONG); // Salt
|
|
||||||
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
|
|
||||||
|
|
||||||
final JsonElement element = wrapper.get(Type.COMPONENT, 0);
|
final JsonElement element = wrapper.get(Type.COMPONENT, 0);
|
||||||
translatableRewriter.processText(element);
|
handleChatType(wrapper, senderName, teamName, 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));
|
|
||||||
});
|
});
|
||||||
|
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
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.COMPONENT); // Message
|
map(Type.COMPONENT); // Message
|
||||||
handler(wrapper -> {
|
map(Type.VAR_INT, Type.BYTE); // Chat type
|
||||||
int type = wrapper.read(Type.VAR_INT);
|
|
||||||
if (type > 2) {
|
|
||||||
type = 0; // Chat
|
|
||||||
}
|
|
||||||
wrapper.write(Type.BYTE, (byte) type);
|
|
||||||
});
|
|
||||||
create(Type.UUID, ZERO_UUID); // Sender
|
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() {
|
public ItemRewriter getItemRewriter() {
|
||||||
return blockItemPackets;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
# 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.
|
# 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"
|
@ -71,7 +71,7 @@
|
|||||||
"item.minecraft.mangrove_boat": "Mangrove Boat",
|
"item.minecraft.mangrove_boat": "Mangrove Boat",
|
||||||
"item.minecraft.recovery_compass": "Recovery Compass",
|
"item.minecraft.recovery_compass": "Recovery Compass",
|
||||||
"item.minecraft.music_disc_5": "Music Disc",
|
"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.mangrove_chest_boat": "Mangrove Boat with Chest",
|
||||||
"item.minecraft.disc_fragment_5": "Disc Fragment",
|
"item.minecraft.disc_fragment_5": "Disc Fragment",
|
||||||
"item.minecraft.disc_fragment_5.desc": "Music Disc - 5",
|
"item.minecraft.disc_fragment_5.desc": "Music Disc - 5",
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren