3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-04 18:40:06 +01:00

fix: correctly (de)serialise ItemType (#2620)

- InternalId changes depending on ~~magic~~ so we should not store this value
 - fixes #2589
Dieser Commit ist enthalten in:
Jordan 2024-03-15 18:39:35 +01:00 committet von GitHub
Ursprung df9527b0b7
Commit 8363badf80
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
3 geänderte Dateien mit 30 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -23,6 +23,8 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
/**
* Utility methods for Google's GSON library.
@ -41,6 +43,7 @@ public final class GsonUtil {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
gsonBuilder.registerTypeAdapter(BlockVector3.class, new BlockVectorAdapter());
gsonBuilder.registerTypeAdapter(ItemType.class, new ItemTypeAdapter());
return gsonBuilder;
}

Datei anzeigen

@ -0,0 +1,26 @@
package com.sk89q.worldedit.util.gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import java.lang.reflect.Type;
public final class ItemTypeAdapter implements JsonDeserializer<ItemType> {
@Override
public ItemType deserialize(JsonElement json, Type type, JsonDeserializationContext cont) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
String id = jsonObject.get("id").getAsString();
ItemType itemType = ItemTypes.get(id);
if (itemType == null) {
throw new JsonParseException("Could not parse item type `" + id + "`");
}
return itemType;
}
}

Datei anzeigen

@ -79,7 +79,7 @@ public class ItemType implements RegistryItem, Keyed {
}
//FAWE start
private int internalId;
private transient int internalId;
@Override
public void setInternalId(int internalId) {