mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +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.google.gson.GsonBuilder;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
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.
|
* Utility methods for Google's GSON library.
|
||||||
@ -41,6 +43,7 @@ public final class GsonUtil {
|
|||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||||
gsonBuilder.registerTypeAdapter(BlockVector3.class, new BlockVectorAdapter());
|
gsonBuilder.registerTypeAdapter(BlockVector3.class, new BlockVectorAdapter());
|
||||||
|
gsonBuilder.registerTypeAdapter(ItemType.class, new ItemTypeAdapter());
|
||||||
return gsonBuilder;
|
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
|
//FAWE start
|
||||||
private int internalId;
|
private transient int internalId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInternalId(int internalId) {
|
public void setInternalId(int internalId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user