9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-23 16:49:19 +00:00

feat: Minecraft 1.20.5/6 support (#295)

* feat: start 1.20.5 update testing

nbt-api seems to work great already :)

* feat: add DFU support for legacy upgrade

Adds an optional overload to `deserialize` to support passing the MC Version of the snapshot data

* refactor: `clone` ItemStack[] bukkit data arrays, close #294

Don't perform async operations on mutable player data
This commit is contained in:
William
2024-05-01 12:08:42 +01:00
committed by GitHub
parent 68ec79add6
commit e35dcf3aad
7 changed files with 101 additions and 25 deletions

View File

@@ -392,7 +392,7 @@ public class DataSnapshot {
private Map<Identifier, Data> deserializeData(@NotNull HuskSync plugin) {
return data.entrySet().stream()
.map((entry) -> plugin.getIdentifier(entry.getKey()).map(id -> Map.entry(
id, plugin.getSerializers().get(id).deserialize(entry.getValue())
id, plugin.getSerializers().get(id).deserialize(entry.getValue(), getMinecraftVersion())
)).orElse(null))
.filter(Objects::nonNull)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

View File

@@ -19,22 +19,27 @@
package net.william278.husksync.data;
import net.william278.desertwell.util.Version;
import org.jetbrains.annotations.NotNull;
public interface Serializer<T extends Data> {
T deserialize(@NotNull String serialized) throws DeserializationException;
T deserialize(@NotNull String serialized);
default T deserialize(@NotNull String serialized, @NotNull Version dataMcVersion) throws DeserializationException {
return deserialize(serialized);
}
@NotNull
String serialize(@NotNull T element) throws SerializationException;
static final class DeserializationException extends IllegalStateException {
final class DeserializationException extends IllegalStateException {
DeserializationException(@NotNull String message, @NotNull Throwable cause) {
super(message, cause);
}
}
static final class SerializationException extends IllegalStateException {
final class SerializationException extends IllegalStateException {
SerializationException(@NotNull String message, @NotNull Throwable cause) {
super(message, cause);
}