Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-25 15:50:12 +01:00
Ursprung
084fc5d327
Commit
5f59a57a78
@ -8,7 +8,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "com.viaversion"
|
group = "com.viaversion"
|
||||||
version = "4.0.0-21w19a"
|
version = "4.0.0-21w19a-SNAPSHOT"
|
||||||
description = "Allow older clients to join newer server versions."
|
description = "Allow older clients to join newer server versions."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import java.util.regex.Pattern;
|
|||||||
/**
|
/**
|
||||||
* Utility class to serialize a JsonObject with Minecraft's CompoundTag serialization
|
* Utility class to serialize a JsonObject with Minecraft's CompoundTag serialization
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class TagSerializer {
|
public class TagSerializer {
|
||||||
|
|
||||||
private static final Pattern PLAIN_TEXT = Pattern.compile("[A-Za-z0-9._+-]+");
|
private static final Pattern PLAIN_TEXT = Pattern.compile("[A-Za-z0-9._+-]+");
|
||||||
|
@ -22,6 +22,8 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
|||||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
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 {
|
public class TranslatableRewriter1_16 extends TranslatableRewriter {
|
||||||
|
|
||||||
@ -48,6 +50,7 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter {
|
|||||||
super(protocol);
|
super(protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void processText(JsonElement value) {
|
public void processText(JsonElement value) {
|
||||||
super.processText(value);
|
super.processText(value);
|
||||||
if (!value.isJsonObject()) return;
|
if (!value.isJsonObject()) return;
|
||||||
@ -63,41 +66,18 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter {
|
|||||||
object.addProperty("color", closestChatColor);
|
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_text as chat component
|
||||||
// show_entity and show_item serialized as nbt
|
// show_entity and show_item serialized as nbt
|
||||||
String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
|
// Let adventure handle all of that
|
||||||
switch (action) {
|
Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(object);
|
||||||
case "show_text":
|
JsonObject processedHoverEvent = ((JsonObject) ChatRewriter.HOVER_GSON_SERIALIZER.serializeToTree(component)).getAsJsonObject("hoverEvent");
|
||||||
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));
|
// Remove new format
|
||||||
break;
|
processedHoverEvent.remove("contents");
|
||||||
case "show_entity":
|
object.add("hoverEvent", processedHoverEvent);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ metadata.format.version = "1.0"
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
# ViaVersion
|
# ViaVersion
|
||||||
viaver = "4.0.0-21w19a"
|
viaver = "4.0.0-21w19a-SNAPSHOT"
|
||||||
|
|
||||||
# Common provided
|
# Common provided
|
||||||
netty = "4.0.20.Final"
|
netty = "4.0.20.Final"
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren