Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Methods for VB
Dieser Commit ist enthalten in:
Ursprung
c62a8274ed
Commit
984c625776
@ -348,16 +348,20 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
overlay = true;
|
overlay = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CompoundTag decoaration = chatData.get("decoration");
|
final CompoundTag decoration = chatData.get("decoration");
|
||||||
if (decoaration == null) {
|
if (decoration == null) {
|
||||||
return new ChatDecorationResult(message, overlay);
|
return new ChatDecorationResult(message, overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String translationKey = (String) decoaration.get("translation_key").getValue();
|
return new ChatDecorationResult(translatabaleComponentFromTag(decoration, senderName, teamName, message), overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonElement translatabaleComponentFromTag(final CompoundTag tag, final JsonElement senderName, @Nullable final JsonElement targetName, final JsonElement message) {
|
||||||
|
final String translationKey = (String) tag.get("translation_key").getValue();
|
||||||
final Style style = new Style();
|
final Style style = new Style();
|
||||||
|
|
||||||
// Add the style
|
// Add the style
|
||||||
final CompoundTag styleTag = decoaration.get("style");
|
final CompoundTag styleTag = tag.get("style");
|
||||||
if (styleTag != null) {
|
if (styleTag != null) {
|
||||||
final StringTag color = styleTag.get("color");
|
final StringTag color = styleTag.get("color");
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
@ -368,12 +372,12 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (final Map.Entry<String, TextFormatting> entry : TextFormatting.FORMATTINGS.entrySet()) {
|
for (final Map.Entry<String, TextFormatting> entry : TextFormatting.FORMATTINGS.entrySet()) {
|
||||||
final Tag tag = styleTag.get(entry.getKey());
|
final Tag formattingTag = styleTag.get(entry.getKey());
|
||||||
if (!(tag instanceof ByteTag)) {
|
if (!(formattingTag instanceof ByteTag)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean value = ((NumberTag) tag).asBoolean();
|
final boolean value = ((NumberTag) formattingTag).asBoolean();
|
||||||
final TextFormatting formatting = entry.getValue();
|
final TextFormatting formatting = entry.getValue();
|
||||||
if (formatting == TextFormatting.OBFUSCATED) {
|
if (formatting == TextFormatting.OBFUSCATED) {
|
||||||
style.setObfuscated(value);
|
style.setObfuscated(value);
|
||||||
@ -390,7 +394,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the replacements
|
// Add the replacements
|
||||||
final ListTag parameters = decoaration.get("parameters");
|
final ListTag parameters = tag.get("parameters");
|
||||||
final List<ATextComponent> arguments = new ArrayList<>();
|
final List<ATextComponent> arguments = new ArrayList<>();
|
||||||
if (parameters != null) {
|
if (parameters != null) {
|
||||||
for (final Tag element : parameters) {
|
for (final Tag element : parameters) {
|
||||||
@ -403,8 +407,9 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
argument = message;
|
argument = message;
|
||||||
break;
|
break;
|
||||||
case "team_name":
|
case "team_name":
|
||||||
Preconditions.checkNotNull(teamName, "Team name is null");
|
case "target": // So that this method can also be used in VB
|
||||||
argument = teamName;
|
Preconditions.checkNotNull(targetName, "Team name is null");
|
||||||
|
argument = targetName;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Via.getPlatform().getLogger().warning("Unknown parameter for chat decoration: " + element.getValue());
|
Via.getPlatform().getLogger().warning("Unknown parameter for chat decoration: " + element.getValue());
|
||||||
@ -415,7 +420,6 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final TranslationComponent translatable = new TranslationComponent(translationKey, arguments);
|
return TextComponentSerializer.LATEST.serializeJson(new TranslationComponent(translationKey, arguments));
|
||||||
return new ChatDecorationResult(TextComponentSerializer.LATEST.serializeJson(translatable), overlay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,8 @@ public final class ComponentUtil {
|
|||||||
public static String jsonToLegacy(final String value) {
|
public static String jsonToLegacy(final String value) {
|
||||||
return TextComponentSerializer.LATEST.deserialize(value).asLegacyFormatString();
|
return TextComponentSerializer.LATEST.deserialize(value).asLegacyFormatString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String jsonToLegacy(final JsonElement value) {
|
||||||
|
return TextComponentSerializer.LATEST.deserialize(value).asLegacyFormatString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren