Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly (de)serialise ItemType (#2620)
- InternalId changes depending on ~~magic~~ so we should not store this value - fixes #2589
- Loading branch information
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/ItemTypeAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters