mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2025-02-01 23:32:01 +01:00
Use JsonElement for chat components
This commit is contained in:
parent
385ca98125
commit
875ffb7f2d
@ -30,7 +30,7 @@ import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_15_1to1_15_2.Protocol1_15_1To1_15_2;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_15to1_15_1.Protocol1_15To1_15_1;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_1.Protocol1_16To1_16_1;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_16to1_16_1.Protocol1_16To1_16_1;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
@ -43,7 +43,7 @@ import static us.myles.ViaVersion.api.protocol.ProtocolRegistry.registerProtocol
|
||||
|
||||
public interface ViaBackwardsPlatform {
|
||||
|
||||
String MINIMUM_VV_VERSION = "3.0.0";
|
||||
String MINIMUM_VV_VERSION = "3.0.2";
|
||||
|
||||
/**
|
||||
* Initialize ViaBackwards.
|
||||
|
@ -10,7 +10,7 @@ public class MappedItem {
|
||||
|
||||
public MappedItem(int id, String name) {
|
||||
this.id = id;
|
||||
this.jsonName = ChatRewriter.legacyTextToJson(ChatColor.RESET + name);
|
||||
this.jsonName = ChatRewriter.legacyTextToJson(ChatColor.RESET + name).toString();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -16,7 +16,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
public class EntityData {
|
||||
private final int id;
|
||||
private final int replacementId;
|
||||
private String mobName;
|
||||
private Object mobName;
|
||||
private MetaCreator defaultMeta;
|
||||
|
||||
public EntityData(int id, int replacementId) {
|
||||
@ -47,8 +47,11 @@ public class EntityData {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return custom mobname, can be either a String or a JsonElement
|
||||
*/
|
||||
@Nullable
|
||||
public String getMobName() {
|
||||
public Object getMobName() {
|
||||
return mobName;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class EnchantmentRewriter {
|
||||
Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue();
|
||||
String loreValue = enchantmentName + " " + getRomanNumber(level.intValue());
|
||||
if (jsonFormat) {
|
||||
loreValue = ChatRewriter.legacyTextToJson(loreValue);
|
||||
loreValue = ChatRewriter.legacyTextToJson(loreValue).toString();
|
||||
}
|
||||
|
||||
lore.add(new StringTag("", loreValue));
|
||||
|
@ -40,7 +40,7 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
|
||||
// Handle name and lore components
|
||||
StringTag name = tag.get("Name");
|
||||
if (name != null) {
|
||||
String newValue = translatableRewriter.processText(name.getValue());
|
||||
String newValue = translatableRewriter.processText(name.getValue()).toString();
|
||||
if (name.getValue().equals(newValue)) {
|
||||
textChanged = true;
|
||||
}
|
||||
@ -53,7 +53,7 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
|
||||
if (!(loreEntry instanceof StringTag)) continue;
|
||||
|
||||
StringTag stringTag = (StringTag) loreEntry;
|
||||
String newValue = translatableRewriter.processText(stringTag.getValue());
|
||||
String newValue = translatableRewriter.processText(stringTag.getValue()).toString();
|
||||
if (stringTag.getValue().equals(newValue)) {
|
||||
textChanged = true;
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
|
||||
CompoundTag tag = new CompoundTag("");
|
||||
tag.put(new CompoundTag("display"));
|
||||
text = ChatColor.RESET + text;
|
||||
((CompoundTag) tag.get("display")).put(new StringTag("Name", jsonNameFormat ? ChatRewriter.legacyTextToJson(text) : text));
|
||||
((CompoundTag) tag.get("display")).put(new StringTag("Name", jsonNameFormat ? ChatRewriter.legacyTextToJson(text).toString() : text));
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
@ -5,17 +5,16 @@ import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
|
||||
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
import us.myles.viaversion.libs.gson.JsonPrimitive;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TranslatableRewriter {
|
||||
public class TranslatableRewriter extends ComponentRewriter {
|
||||
|
||||
private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>();
|
||||
protected final BackwardsProtocol protocol;
|
||||
@ -50,7 +49,7 @@ public class TranslatableRewriter {
|
||||
protocol.registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))));
|
||||
handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -59,7 +58,7 @@ public class TranslatableRewriter {
|
||||
protocol.registerOutgoing(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))));
|
||||
handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -68,7 +67,7 @@ public class TranslatableRewriter {
|
||||
protocol.registerOutgoing(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))));
|
||||
handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -82,7 +81,7 @@ public class TranslatableRewriter {
|
||||
handler(wrapper -> {
|
||||
int action = wrapper.get(Type.VAR_INT, 0);
|
||||
if (action == 0 || action == 3) {
|
||||
wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)));
|
||||
processText(wrapper.passthrough(Type.COMPONENT));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -95,7 +94,7 @@ public class TranslatableRewriter {
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // Id
|
||||
map(Type.STRING); // Window Type
|
||||
handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))));
|
||||
handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -106,7 +105,7 @@ public class TranslatableRewriter {
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // Id
|
||||
map(Type.VAR_INT); // Window Type
|
||||
handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING))));
|
||||
handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -119,7 +118,7 @@ public class TranslatableRewriter {
|
||||
if (wrapper.passthrough(Type.VAR_INT) == 2) {
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.INT);
|
||||
wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)));
|
||||
processText(wrapper.passthrough(Type.COMPONENT));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -133,7 +132,7 @@ public class TranslatableRewriter {
|
||||
handler(wrapper -> {
|
||||
int action = wrapper.passthrough(Type.VAR_INT);
|
||||
if (action >= 0 && action <= 2) {
|
||||
wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)));
|
||||
processText(wrapper.passthrough(Type.COMPONENT));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -145,84 +144,18 @@ public class TranslatableRewriter {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)));
|
||||
wrapper.write(Type.COMPONENT_STRING, processText(wrapper.read(Type.COMPONENT_STRING)));
|
||||
processText(wrapper.passthrough(Type.COMPONENT));
|
||||
processText(wrapper.passthrough(Type.COMPONENT));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String processText(String value) {
|
||||
JsonElement root = GsonUtil.getJsonParser().parse(value);
|
||||
processText(root);
|
||||
return root.toString();
|
||||
}
|
||||
|
||||
protected void processText(JsonElement element) {
|
||||
if (element == null || element.isJsonNull()) return;
|
||||
if (element.isJsonArray()) {
|
||||
processAsArray(element);
|
||||
return;
|
||||
}
|
||||
if (element.isJsonPrimitive()) {
|
||||
handleText(element.getAsJsonPrimitive());
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
JsonPrimitive text = object.getAsJsonPrimitive("text");
|
||||
if (text != null) {
|
||||
handleText(text);
|
||||
}
|
||||
|
||||
JsonElement translate = object.get("translate");
|
||||
if (translate != null) {
|
||||
handleTranslate(object, translate.getAsString());
|
||||
|
||||
JsonElement with = object.get("with");
|
||||
if (with != null) {
|
||||
processAsArray(with);
|
||||
}
|
||||
}
|
||||
|
||||
JsonElement extra = object.get("extra");
|
||||
if (extra != null) {
|
||||
processAsArray(extra);
|
||||
}
|
||||
|
||||
JsonObject hoverEvent = object.getAsJsonObject("hoverEvent");
|
||||
if (hoverEvent != null) {
|
||||
handleHoverEvent(hoverEvent);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleText(JsonPrimitive text) {
|
||||
// In case this is needed in the future
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject root, String translate) {
|
||||
String newTranslate = newTranslatables.get(translate);
|
||||
if (newTranslate != null) {
|
||||
root.addProperty("translate", newTranslate);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleHoverEvent(JsonObject hoverEvent) {
|
||||
String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
|
||||
if (action.equals("show_text")) {
|
||||
JsonElement value = hoverEvent.get("value");
|
||||
processText(value != null ? value : hoverEvent.get("contents"));
|
||||
} else if (action.equals("show_entity")) {
|
||||
JsonObject contents = hoverEvent.getAsJsonObject("contents");
|
||||
if (contents != null) {
|
||||
processText(contents.get("name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processAsArray(JsonElement element) {
|
||||
for (JsonElement jsonElement : element.getAsJsonArray()) {
|
||||
processText(jsonElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.STRING); // 1 - Window Type
|
||||
map(Type.STRING); // 2 - Title
|
||||
map(Type.COMPONENT); // 2 - Title
|
||||
map(Type.UNSIGNED_BYTE); // 3 - Slots
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@ -278,8 +278,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = -1;
|
||||
// Passthrough Entity ID
|
||||
if (wrapper.get(Type.STRING, 0).equals("EntityHorse"))
|
||||
if (wrapper.get(Type.STRING, 0).equals("EntityHorse")) {
|
||||
entityId = wrapper.passthrough(Type.INT);
|
||||
}
|
||||
|
||||
// Track Inventory
|
||||
String inventory = wrapper.get(Type.STRING, 0);
|
||||
@ -288,8 +289,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
windowTracker.setEntityId(entityId);
|
||||
|
||||
// Change llama slotcount to the donkey one
|
||||
if (isLlama(wrapper.user()))
|
||||
if (isLlama(wrapper.user())) {
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 1, (short) 17);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
|
||||
public class PlayerPackets1_11 {
|
||||
private static final ValueTransformer<Short, Float> TO_NEW_FLOAT = new ValueTransformer<Short, Float>(Type.FLOAT) {
|
||||
@ -43,10 +43,8 @@ public class PlayerPackets1_11 {
|
||||
if (action == 2) {
|
||||
// Convert to the old actionbar way
|
||||
PacketWrapper actionbar = new PacketWrapper(0x0F, null, wrapper.user()); // Chat Message packet
|
||||
String msg = wrapper.read(Type.STRING);
|
||||
msg = ChatRewriter.jsonTextToLegacy(msg);
|
||||
msg = "{\"text\":\"" + msg + "\"}";
|
||||
actionbar.write(Type.STRING, msg);
|
||||
JsonElement msg = wrapper.read(Type.COMPONENT);
|
||||
actionbar.write(Type.COMPONENT, msg);
|
||||
actionbar.write(Type.BYTE, (byte) 2); // Above hotbar
|
||||
|
||||
actionbar.send(Protocol1_10To1_11.class);
|
||||
|
@ -31,7 +31,7 @@ public class ShoulderTracker extends StoredObject {
|
||||
public void update() {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x0F, null, getUser());
|
||||
|
||||
wrapper.write(Type.STRING, Protocol1_9To1_8.fixJson(generateString()));
|
||||
wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(generateString()));
|
||||
wrapper.write(Type.BYTE, (byte) 2);
|
||||
|
||||
try {
|
||||
|
@ -10,22 +10,28 @@
|
||||
|
||||
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.rewriters.Rewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
|
||||
|
||||
private final ComponentRewriter componentRewriter = new ComponentRewriter() {
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject object, String translate) {
|
||||
String text = AdvancementTranslations.get(translate);
|
||||
if (text != null) {
|
||||
object.addProperty("translate", text);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ChatPackets1_12(Protocol1_11_1To1_12 protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
@ -35,68 +41,14 @@ public class ChatPackets1_12 extends Rewriter<Protocol1_11_1To1_12> {
|
||||
protocol.registerOutgoing(ClientboundPackets1_12.CHAT_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING); // 0 - Json Data
|
||||
map(Type.COMPONENT); // 0 - Json Data
|
||||
map(Type.BYTE); // 1 - Position
|
||||
|
||||
handler(wrapper -> {
|
||||
try {
|
||||
JsonObject object = GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0)).getAsJsonObject();
|
||||
// Skip if the root doesn't contain translate
|
||||
if (object.has("translate")) {
|
||||
handleTranslations(object);
|
||||
}
|
||||
|
||||
ChatItemRewriter.toClient(object, wrapper.user());
|
||||
wrapper.set(Type.STRING, 0, object.toString());
|
||||
} catch (Exception e) {
|
||||
// Only print if ViaVer debug is enabled
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().severe("Failed to handle translations");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
JsonElement element = wrapper.passthrough(Type.COMPONENT);
|
||||
componentRewriter.processText(element);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// improve this, not copying will cause ConcurrentModificationException
|
||||
public void handleTranslations(JsonObject object) {
|
||||
JsonObject copiedObj = copy(object);
|
||||
|
||||
if (object.isJsonObject()) {
|
||||
for (Map.Entry<String, JsonElement> entry : copiedObj.entrySet()) {
|
||||
// Get the text that doesn't exist for 1.11 <
|
||||
|
||||
if (entry.getKey().equalsIgnoreCase("translate")) {
|
||||
String translate = entry.getValue().getAsString();
|
||||
String text = AdvancementTranslations.get(translate);
|
||||
if (text != null) {
|
||||
object.addProperty("translate", text);
|
||||
}
|
||||
}
|
||||
// Handle arrays
|
||||
if (entry.getValue().isJsonArray())
|
||||
for (JsonElement element : object.get(entry.getKey()).getAsJsonArray())
|
||||
if (element.isJsonObject())
|
||||
handleTranslations(element.getAsJsonObject());
|
||||
|
||||
// Handle objects
|
||||
if (entry.getValue().isJsonObject())
|
||||
handleTranslations(object.get(entry.getKey()).getAsJsonObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject copy(JsonObject object) {
|
||||
JsonObject result = new JsonObject();
|
||||
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
|
||||
if (entry.getValue().isJsonObject())
|
||||
result.add(entry.getKey(), copy(entry.getValue().getAsJsonObject()));
|
||||
else
|
||||
result.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
byte z = wrapper.read(Type.BYTE);
|
||||
byte direction = wrapper.read(Type.BYTE);
|
||||
if (wrapper.read(Type.BOOLEAN)) {
|
||||
wrapper.read(Type.STRING);
|
||||
wrapper.read(Type.COMPONENT);
|
||||
}
|
||||
if (type > 9) {
|
||||
wrapper.set(Type.VAR_INT, 1, wrapper.get(Type.VAR_INT, 1) - 1);
|
||||
@ -789,7 +789,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
StringTag name = displayTag.get("Name");
|
||||
if (name instanceof StringTag) {
|
||||
displayTag.put(new StringTag(extraNbtTag + "|Name", name.getValue()));
|
||||
name.setValue(ChatRewriter.legacyTextToJson(name.getValue()));
|
||||
name.setValue(ChatRewriter.legacyTextToJson(name.getValue()).toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@ -171,7 +172,7 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
packetWrapper.passthrough(Type.VAR_INT);
|
||||
packetWrapper.passthrough(Type.VAR_INT);
|
||||
if (packetWrapper.passthrough(Type.BOOLEAN)) {
|
||||
packetWrapper.passthrough(Type.STRING);
|
||||
packetWrapper.passthrough(Type.COMPONENT);
|
||||
}
|
||||
} else if (action == 1) { // Update Game Mode
|
||||
packetWrapper.passthrough(Type.VAR_INT);
|
||||
@ -179,7 +180,7 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
packetWrapper.passthrough(Type.VAR_INT);
|
||||
} else if (action == 3) { // Update Display Name
|
||||
if (packetWrapper.passthrough(Type.BOOLEAN)) {
|
||||
packetWrapper.passthrough(Type.STRING);
|
||||
packetWrapper.passthrough(Type.COMPONENT);
|
||||
}
|
||||
} else if (action == 4) { // Remove Player
|
||||
storage.usernames.remove(uuid);
|
||||
@ -200,9 +201,12 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
byte mode = wrapper.get(Type.BYTE, 0);
|
||||
if (mode == 0 || mode == 2) {
|
||||
String value = wrapper.read(Type.STRING);
|
||||
String value = wrapper.read(Type.COMPONENT).toString();
|
||||
value = ChatRewriter.jsonTextToLegacy(value);
|
||||
if (value.length() > 32) value = value.substring(0, 32);
|
||||
if (value.length() > 32) {
|
||||
value = value.substring(0, 32);
|
||||
}
|
||||
|
||||
wrapper.write(Type.STRING, value);
|
||||
int type = wrapper.read(Type.VAR_INT);
|
||||
wrapper.write(Type.STRING, type == 1 ? "hearts" : "integer");
|
||||
@ -237,9 +241,10 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
colour = -1;
|
||||
}
|
||||
|
||||
String prefix = wrapper.read(Type.STRING);
|
||||
String suffix = wrapper.read(Type.STRING);
|
||||
prefix = prefix == null || prefix.equals("null") ? "" : ChatRewriter.jsonTextToLegacy(prefix);
|
||||
JsonElement prefixComponent = wrapper.read(Type.COMPONENT);
|
||||
JsonElement suffixComponent = wrapper.read(Type.COMPONENT);
|
||||
|
||||
String prefix = prefixComponent == null || prefixComponent.isJsonNull() ? "" : ChatRewriter.jsonTextToLegacy(prefixComponent.toString());
|
||||
if (ViaBackwards.getConfig().addTeamColorTo1_13Prefix()) {
|
||||
prefix += "§" + (colour > -1 && colour <= 15 ? Integer.toHexString(colour) : "r");
|
||||
}
|
||||
@ -248,7 +253,7 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||
if (prefix.length() > 16) prefix = prefix.substring(0, 16);
|
||||
if (prefix.endsWith("§")) prefix = prefix.substring(0, prefix.length() - 1);
|
||||
|
||||
suffix = suffix == null || suffix.equals("null") ? "" : ChatRewriter.jsonTextToLegacy(suffix);
|
||||
String suffix = suffixComponent == null || suffixComponent.isJsonNull() ? "" : ChatRewriter.jsonTextToLegacy(suffixComponent.toString());
|
||||
suffix = ChatUtil.removeUnusedColor(suffix, 'f');
|
||||
if (suffix.length() > 16) suffix = suffix.substring(0, 16);
|
||||
if (suffix.endsWith("§")) suffix = suffix.substring(0, suffix.length() - 1);
|
||||
|
@ -34,7 +34,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
import us.myles.viaversion.libs.opennbt.conversion.ConverterRegistry;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
@ -137,19 +137,19 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
|
||||
wrapper.write(Type.STRING, stringType);
|
||||
|
||||
String title = wrapper.read(Type.COMPONENT_STRING);
|
||||
JsonElement title = wrapper.read(Type.COMPONENT);
|
||||
if (containerTitle != null) {
|
||||
// Don't rewrite renamed, only translatable titles
|
||||
JsonObject object = GsonUtil.getGson().fromJson(title, JsonObject.class);
|
||||
if (object.has("translate")) {
|
||||
JsonObject object;
|
||||
if (title.isJsonObject() && (object = title.getAsJsonObject()).has("translate")) {
|
||||
// Don't rewrite other 9x3 translatable containers
|
||||
if (type != 2 || object.getAsJsonPrimitive("translate").getAsString().equals("container.barrel")) {
|
||||
title = ChatRewriter.legacyTextToJson(containerTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
wrapper.write(Type.COMPONENT_STRING, title);
|
||||
|
||||
wrapper.write(Type.COMPONENT, title);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) slotSize);
|
||||
}
|
||||
});
|
||||
@ -165,7 +165,9 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Window id
|
||||
wrapper.write(Type.STRING, "EntityHorse"); // Type
|
||||
wrapper.write(Type.STRING, "{\"translate\":\"minecraft.horse\"}"); // Title
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("translate", "minecraft.horse");
|
||||
wrapper.write(Type.COMPONENT, object); // Title
|
||||
wrapper.write(Type.UNSIGNED_BYTE, wrapper.read(Type.VAR_INT).shortValue()); // Number of slots
|
||||
wrapper.passthrough(Type.INT); // Entity id
|
||||
}
|
||||
@ -573,7 +575,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
display.put(ConverterRegistry.convertToTag(nbtTagName + "|Lore", ConverterRegistry.convertToValue(lore)));
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
((StringTag) loreEntry).setValue(ChatRewriter.legacyTextToJson(((StringTag) loreEntry).getValue()));
|
||||
((StringTag) loreEntry).setValue(ChatRewriter.legacyTextToJson(((StringTag) loreEntry).getValue()).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int action = wrapper.get(Type.VAR_INT, 0);
|
||||
if (action == 0 || action == 3) {
|
||||
wrapper.write(Type.COMPONENT_STRING, translatableRewriter.processText(wrapper.read(Type.COMPONENT_STRING)));
|
||||
translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT));
|
||||
if (action == 0) {
|
||||
wrapper.passthrough(Type.FLOAT);
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
|
@ -53,7 +53,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
|
||||
registerOutgoing(ClientboundPackets1_16.CHAT_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, translatableRewriter.processText(wrapper.read(Type.COMPONENT_STRING))));
|
||||
handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
|
||||
map(Type.BYTE);
|
||||
map(Type.UUID, Type.NOTHING); // Sender
|
||||
}
|
||||
@ -64,7 +64,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // Window Id
|
||||
map(Type.VAR_INT); // Window Type
|
||||
handler(wrapper -> wrapper.write(Type.COMPONENT_STRING, translatableRewriter.processText(wrapper.read(Type.COMPONENT_STRING))));
|
||||
handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
|
||||
handler(wrapper -> {
|
||||
int windowType = wrapper.get(Type.VAR_INT, 1);
|
||||
if (windowType == 20) { // Smithing table
|
||||
|
@ -31,7 +31,7 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
protected void processText(JsonElement value) {
|
||||
public void processText(JsonElement value) {
|
||||
super.processText(value);
|
||||
if (!value.isJsonObject()) return;
|
||||
|
||||
|
@ -19,6 +19,7 @@ import us.myles.ViaVersion.api.type.types.Particle;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
|
||||
public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
|
||||
@ -143,9 +144,9 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
Particle particle = (Particle) meta.getValue();
|
||||
particle.setId(ParticleMapping.getOldId(particle.getId()));
|
||||
} else if (type == MetaType1_14.OptChat) {
|
||||
String text = meta.getCastedValue();
|
||||
JsonElement text = meta.getCastedValue();
|
||||
if (text != null) {
|
||||
meta.setValue(protocol.getTranslatableRewriter().processText(text));
|
||||
protocol.getTranslatableRewriter().processText(text);
|
||||
}
|
||||
}
|
||||
return meta;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_1;
|
||||
package nl.matsv.viabackwards.protocol.protocol1_16to1_16_1;
|
||||
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
Loading…
Reference in New Issue
Block a user