3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-25 07:40:08 +01:00

Fix legacy hover conversion

Fixes ViaVersion/ViaVersion#2471
Dieser Commit ist enthalten in:
KennyTV 2021-05-14 11:04:45 +02:00
Ursprung 084fc5d327
Commit 5f59a57a78
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
4 geänderte Dateien mit 16 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -8,7 +8,7 @@ plugins {
allprojects {
group = "com.viaversion"
version = "4.0.0-21w19a"
version = "4.0.0-21w19a-SNAPSHOT"
description = "Allow older clients to join newer server versions."
}

Datei anzeigen

@ -32,6 +32,7 @@ import java.util.regex.Pattern;
/**
* Utility class to serialize a JsonObject with Minecraft's CompoundTag serialization
*/
@Deprecated
public class TagSerializer {
private static final Pattern PLAIN_TEXT = Pattern.compile("[A-Za-z0-9._+-]+");

Datei anzeigen

@ -22,6 +22,8 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
public class TranslatableRewriter1_16 extends TranslatableRewriter {
@ -48,6 +50,7 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter {
super(protocol);
}
@Override
public void processText(JsonElement value) {
super.processText(value);
if (!value.isJsonObject()) return;
@ -63,41 +66,18 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter {
object.addProperty("color", closestChatColor);
}
}
}
@Override
protected void handleHoverEvent(JsonObject hoverEvent) {
// Don't call super, convert and process contents here
JsonElement contentsElement = hoverEvent.remove("contents");
if (contentsElement == null) return;
JsonObject hoverEvent = object.getAsJsonObject("hoverEvent");
if (hoverEvent != null) {
// show_text as chat component
// show_entity and show_item serialized as nbt
// Let adventure handle all of that
Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(object);
JsonObject processedHoverEvent = ((JsonObject) ChatRewriter.HOVER_GSON_SERIALIZER.serializeToTree(component)).getAsJsonObject("hoverEvent");
// show_text as chat component
// show_entity and show_item serialized as nbt
String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
switch (action) {
case "show_text":
processText(contentsElement);
hoverEvent.add("value", contentsElement);
break;
case "show_item":
JsonObject item = contentsElement.getAsJsonObject();
JsonElement count = item.remove("count");
item.addProperty("Count", count != null ? count.getAsByte() : 1);
hoverEvent.addProperty("value", TagSerializer.toString(item));
break;
case "show_entity":
JsonObject entity = contentsElement.getAsJsonObject();
JsonObject name = entity.getAsJsonObject("name");
if (name != null) {
processText(name);
entity.addProperty("name", name.toString());
}
JsonObject hoverObject = new JsonObject();
hoverObject.addProperty("text", TagSerializer.toString(entity));
hoverEvent.add("value", hoverObject);
break;
// Remove new format
processedHoverEvent.remove("contents");
object.add("hoverEvent", processedHoverEvent);
}
}

Datei anzeigen

@ -3,7 +3,7 @@ metadata.format.version = "1.0"
[versions]
# ViaVersion
viaver = "4.0.0-21w19a"
viaver = "4.0.0-21w19a-SNAPSHOT"
# Common provided
netty = "4.0.20.Final"