Add a gson adapter for PlayerInventory.
This commit is contained in:
parent
1ca7764c03
commit
6fc7723466
@ -9,10 +9,12 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import com.massivecraft.mcore.adapter.InventoryAdapter;
|
import com.massivecraft.mcore.adapter.InventoryAdapter;
|
||||||
import com.massivecraft.mcore.adapter.ItemStackAdapter;
|
import com.massivecraft.mcore.adapter.ItemStackAdapter;
|
||||||
import com.massivecraft.mcore.adapter.MongoURIAdapter;
|
import com.massivecraft.mcore.adapter.MongoURIAdapter;
|
||||||
|
import com.massivecraft.mcore.adapter.PlayerInventoryAdapter;
|
||||||
import com.massivecraft.mcore.cmd.CmdMcore;
|
import com.massivecraft.mcore.cmd.CmdMcore;
|
||||||
import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures;
|
import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures;
|
||||||
import com.massivecraft.mcore.mixin.ScheduledTeleportEngine;
|
import com.massivecraft.mcore.mixin.ScheduledTeleportEngine;
|
||||||
@ -67,6 +69,7 @@ public class MCore extends MPlugin
|
|||||||
.registerTypeAdapter(MongoURI.class, MongoURIAdapter.get())
|
.registerTypeAdapter(MongoURI.class, MongoURIAdapter.get())
|
||||||
.registerTypeAdapter(ItemStack.class, ItemStackAdapter.get())
|
.registerTypeAdapter(ItemStack.class, ItemStackAdapter.get())
|
||||||
.registerTypeAdapter(Inventory.class, InventoryAdapter.get())
|
.registerTypeAdapter(Inventory.class, InventoryAdapter.get())
|
||||||
|
.registerTypeAdapter(PlayerInventory.class, PlayerInventoryAdapter.get())
|
||||||
.registerTypeAdapter(PS.class, PSAdapter.get());
|
.registerTypeAdapter(PS.class, PSAdapter.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,13 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
|
|||||||
public static final String CHESTPLATE = "chestplate";
|
public static final String CHESTPLATE = "chestplate";
|
||||||
public static final String LEGGINGS = "leggings";
|
public static final String LEGGINGS = "leggings";
|
||||||
public static final String BOOTS = "boots";
|
public static final String BOOTS = "boots";
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static InventoryAdapter i = new InventoryAdapter();
|
||||||
|
public static InventoryAdapter get() { return i; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
@ -214,11 +221,4 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// INSTANCE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static InventoryAdapter i = new InventoryAdapter();
|
|
||||||
public static InventoryAdapter get() { return i; }
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.massivecraft.mcore.adapter;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.xlib.gson.JsonDeserializationContext;
|
||||||
|
import com.massivecraft.mcore.xlib.gson.JsonDeserializer;
|
||||||
|
import com.massivecraft.mcore.xlib.gson.JsonElement;
|
||||||
|
import com.massivecraft.mcore.xlib.gson.JsonParseException;
|
||||||
|
import com.massivecraft.mcore.xlib.gson.JsonSerializationContext;
|
||||||
|
import com.massivecraft.mcore.xlib.gson.JsonSerializer;
|
||||||
|
|
||||||
|
public class PlayerInventoryAdapter implements JsonDeserializer<PlayerInventory>, JsonSerializer<PlayerInventory>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static PlayerInventoryAdapter i = new PlayerInventoryAdapter();
|
||||||
|
public static PlayerInventoryAdapter get() { return i; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// IMPLEMENTATION
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(PlayerInventory src, Type typeOfSrc, JsonSerializationContext context)
|
||||||
|
{
|
||||||
|
return InventoryAdapter.toJson(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlayerInventory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||||
|
{
|
||||||
|
return (PlayerInventory) InventoryAdapter.fromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -218,6 +218,11 @@ public class InventoryUtil
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PlayerInventory cloneInventory(PlayerInventory inventory)
|
||||||
|
{
|
||||||
|
return (PlayerInventory)cloneInventory((Inventory)inventory);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// SET CONTENT
|
// SET CONTENT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
Loading…
Reference in New Issue
Block a user