mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
fix: correctly (de)serialise ItemType (#2620)
- InternalId changes depending on ~~magic~~ so we should not store this value - fixes #2589
This commit is contained in:
parent
df9527b0b7
commit
8363badf80
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user