3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Cleanup of mcstructs branch (#3604)

Dieser Commit ist enthalten in:
RK_01 2023-12-27 19:37:48 +01:00 committet von GitHub
Ursprung ca4b6fc765
Commit 28a0813676
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 12 neuen und 60 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,9 @@ dependencies {
api(libs.flareFastutil)
api(libs.vianbt)
api(libs.gson)
implementation(rootProject.libs.text) {
exclude("com.google.code.gson", "gson")
}
compileOnlyApi(libs.snakeYaml)
compileOnlyApi(libs.netty)

Datei anzeigen

@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_1;
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
import com.viaversion.viaversion.util.GsonUtil;
import net.lenni0451.mcstructs.text.utils.JsonUtils;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@ -62,7 +62,7 @@ public class MessageBody {
dataOutputStream.write(this.content.plain().getBytes(StandardCharsets.UTF_8));
dataOutputStream.write(HASH_SEPARATOR_BYTE);
if (this.content.isDecorated()) {
dataOutputStream.write(GsonUtil.toSortedString(this.content.decorated(), null).getBytes(StandardCharsets.UTF_8));
dataOutputStream.write(JsonUtils.toSortedString(this.content.decorated(), null).getBytes(StandardCharsets.UTF_8));
}
for (PlayerMessageSignature lastSeenMessage : this.lastSeenMessages) {

Datei anzeigen

@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.minecraft.signature.storage;
import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
import com.viaversion.viaversion.util.GsonUtil;
import net.lenni0451.mcstructs.text.utils.JsonUtils;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -48,7 +48,7 @@ public class ChatSession1_19_0 extends ChatSession {
buffer.putLong(metadata.sender().getMostSignificantBits()).putLong(metadata.sender().getLeastSignificantBits());
buffer.putLong(metadata.timestamp().getEpochSecond());
signer.accept(data);
signer.accept(GsonUtil.toSortedString(content.decorated(), null).getBytes(StandardCharsets.UTF_8));
signer.accept(JsonUtils.toSortedString(content.decorated(), null).getBytes(StandardCharsets.UTF_8));
});
}

Datei anzeigen

@ -22,12 +22,8 @@
*/
package com.viaversion.viaversion.util;
import com.google.gson.*;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public final class GsonUtil {
private static final Gson GSON = new GsonBuilder().create();
@ -41,52 +37,4 @@ public final class GsonUtil {
return GSON;
}
/**
* Convert a json element to a sorted string.<br>
* If the {@code comparator} is null, {@link Comparator#naturalOrder()} will be used.
*
* @param element The element to convert
* @param comparator The comparator to use
* @return The sorted string
*/
public static String toSortedString(@Nullable final JsonElement element, @Nullable final Comparator<String> comparator) {
if (element == null) {
return null;
} else if (comparator != null) {
return sort(element, comparator).toString();
} else {
return sort(element, Comparator.naturalOrder()).toString();
}
}
/**
* Sort a json element.
*
* @param element The element to sort
* @param comparator The comparator to use
* @return The sorted element
*/
public static JsonElement sort(@Nullable final JsonElement element, final Comparator<String> comparator) {
if (element == null) {
return null;
} else if (element.isJsonArray()) {
final JsonArray array = element.getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
array.set(i, sort(array.get(i), comparator));
}
return array;
} else if (element.isJsonObject()) {
final JsonObject object = element.getAsJsonObject();
final JsonObject sorted = new JsonObject();
final List<String> keys = new ArrayList<>(object.keySet());
keys.sort(comparator);
for (String key : keys) {
sorted.add(key, sort(object.get(key), comparator));
}
return sorted;
} else {
return element;
}
}
}

Datei anzeigen

@ -22,7 +22,6 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via;
import java.util.logging.Level;
import net.lenni0451.mcstructs.snbt.SNbtSerializer;
import net.lenni0451.mcstructs.text.ATextComponent;
import net.lenni0451.mcstructs.text.Style;
@ -33,6 +32,8 @@ import net.lenni0451.mcstructs.text.serializer.TextComponentCodec;
import net.lenni0451.mcstructs.text.serializer.TextComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.logging.Level;
/**
* Component conversion utility, trying to divert most calls to the component library to this class instead for easy replacement.
*/
@ -105,7 +106,7 @@ public final class ComponentUtil {
}
public static String jsonToLegacy(final String value) {
return TextComponentSerializer.V1_12.deserialize(value).asLegacyFormatString();
return TextComponentSerializer.V1_12.deserializeReader(value).asLegacyFormatString();
}
public static String jsonToLegacy(final JsonElement value) {