Handle in-depth components in dialogs (#4876)
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
This commit is contained in:
1 parent
bb9aa8b31c
commit
6bd081cefd
1 file changed
+89
-19
@@ -175,38 +175,108 @@ public class RegistryDataRewriter implements com.viaversion.viaversion.api.rewri
|
||||
|
||||
@Override
|
||||
public void updateDialog(final UserConnection connection, final CompoundTag tag) {
|
||||
final ComponentRewriter componentRewriter = protocol.getComponentRewriter();
|
||||
if (componentRewriter != null) {
|
||||
componentRewriter.processTag(connection, tag.get("title"));
|
||||
componentRewriter.processTag(connection, tag.get("external_title"));
|
||||
}
|
||||
|
||||
final ListTag<CompoundTag> inputsTag = tag.getListTag("inputs", CompoundTag.class);
|
||||
if (inputsTag != null && componentRewriter != null) {
|
||||
for (final CompoundTag input : inputsTag) {
|
||||
updateTextComponent(connection, input, "label");
|
||||
|
||||
final String type = input.getString("type");
|
||||
if (!Key.equals(type, "single_option")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final ListTag<CompoundTag> optionsTag = input.getListTag("options", CompoundTag.class);
|
||||
if (optionsTag != null) {
|
||||
optionsTag.forEach(option -> updateTextComponent(connection, option, "display"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final String type = tag.getString("type");
|
||||
switch (Key.stripMinecraftNamespace(type)) {
|
||||
case "confirmation" -> {
|
||||
updateDialogAction(connection, tag.getCompoundTag("yes"));
|
||||
updateDialogAction(connection, tag.getCompoundTag("no"));
|
||||
}
|
||||
case "dialog_list" -> {
|
||||
updateDialogAction(connection, tag.getCompoundTag("exit_action"));
|
||||
|
||||
final ListTag<CompoundTag> dialogsTag = tag.getListTag("dialogs", CompoundTag.class);
|
||||
if (dialogsTag != null) {
|
||||
dialogsTag.forEach(dialog -> updateDialog(connection, dialog));
|
||||
} else {
|
||||
final CompoundTag dialogTag = tag.getCompoundTag("dialogs");
|
||||
if (dialogTag != null) {
|
||||
updateDialog(connection, dialogTag); // inlined
|
||||
}
|
||||
}
|
||||
}
|
||||
case "multi_action" -> {
|
||||
updateDialogAction(connection, tag.getCompoundTag("exit_action"));
|
||||
|
||||
final ListTag<CompoundTag> actionsTag = tag.getListTag("actions", CompoundTag.class);
|
||||
if (actionsTag != null) {
|
||||
actionsTag.forEach(action -> updateDialogAction(connection, action));
|
||||
}
|
||||
}
|
||||
case "notice" -> updateDialogAction(connection, tag.getCompoundTag("action"));
|
||||
case "server_links" -> updateDialogAction(connection, tag.getCompoundTag("exit_action"));
|
||||
}
|
||||
|
||||
final ListTag<CompoundTag> bodiesTag = tag.getListTag("body", CompoundTag.class);
|
||||
if (bodiesTag == null) {
|
||||
if (bodiesTag != null) {
|
||||
bodiesTag.forEach(body -> updateDialogBody(connection, body));
|
||||
} else {
|
||||
final CompoundTag bodyTag = tag.getCompoundTag("body");
|
||||
if (bodyTag != null) {
|
||||
updateDialogBody(connection, bodyTag); // inlined
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final CompoundTag entry : bodiesTag) {
|
||||
updateDialogBody(connection, entry);
|
||||
public void updateDialogAction(final UserConnection connection, final CompoundTag tag) {
|
||||
updateTextComponent(connection, tag, "label");
|
||||
updateTextComponent(connection, tag, "tooltip");
|
||||
}
|
||||
|
||||
protected void updateTextComponent(final UserConnection connection, @Nullable final CompoundTag tag, final String key) {
|
||||
if (tag != null && protocol.getComponentRewriter() != null) {
|
||||
protocol.getComponentRewriter().processTag(connection, tag.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDialogBody(final UserConnection connection, final CompoundTag tag) {
|
||||
final String type = tag.getString("type");
|
||||
if (!Key.equals(type, "item")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final StringTag itemTag = tag.getStringTag("item");
|
||||
if (itemTag != null) {
|
||||
final String mappedId = protocol.getMappingData().getFullItemMappings().mappedIdentifier(itemTag.getValue());
|
||||
if (mappedId != null) {
|
||||
itemTag.setValue(mappedId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final ComponentRewriter componentRewriter = protocol.getComponentRewriter();
|
||||
if (componentRewriter != null) {
|
||||
componentRewriter.handleShowItem(connection, tag.getCompoundTag("item"));
|
||||
if (Key.equals(type, "plain_message")) {
|
||||
if (componentRewriter != null) {
|
||||
componentRewriter.processTag(connection, tag.get("contents"));
|
||||
}
|
||||
} else if (Key.equals(type, "item")) {
|
||||
if (componentRewriter != null) {
|
||||
// Either a plain message or an inlined component
|
||||
final Tag description = tag.get("description");
|
||||
componentRewriter.processTag(connection, description);
|
||||
if (description instanceof final CompoundTag descriptionTag) {
|
||||
componentRewriter.processTag(connection, descriptionTag.get("contents"));
|
||||
}
|
||||
}
|
||||
|
||||
final StringTag itemIdTag = tag.getStringTag("item");
|
||||
if (itemIdTag != null) {
|
||||
final String mappedId = protocol.getMappingData().getFullItemMappings().mappedIdentifier(itemIdTag.getValue());
|
||||
if (mappedId != null) {
|
||||
itemIdTag.setValue(mappedId);
|
||||
}
|
||||
} else if (componentRewriter != null) {
|
||||
componentRewriter.handleShowItem(connection, tag.getCompoundTag("item"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user