Legacy custom serializer since removal of getHandle
This commit is contained in:
parent
1e601bea2d
commit
552f74274a
@ -1,5 +1,5 @@
|
|||||||
name: mcore5
|
name: mcore5
|
||||||
version: 1.1.0
|
version: 1.1.1
|
||||||
main: com.massivecraft.mcore5.MCore
|
main: com.massivecraft.mcore5.MCore
|
||||||
load: startup
|
load: startup
|
||||||
permissions:
|
permissions:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.massivecraft.mcore5.adapter;
|
package com.massivecraft.mcore5.adapter;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ public class ItemStackAdapter implements JsonDeserializer<ItemStack>, JsonSerial
|
|||||||
if (!(stack instanceof CraftItemStack)) return null;
|
if (!(stack instanceof CraftItemStack)) return null;
|
||||||
CraftItemStack craftItemStack = (CraftItemStack)stack;
|
CraftItemStack craftItemStack = (CraftItemStack)stack;
|
||||||
|
|
||||||
NBTTagCompound nbt = craftItemStack.getHandle().tag;
|
NBTTagCompound nbt = getHandle(craftItemStack).tag;
|
||||||
if (nbt == null) return null;
|
if (nbt == null) return null;
|
||||||
|
|
||||||
JsonObject gsonbt = (JsonObject) NbtGsonConverter.nbtToGsonVal(nbt);
|
JsonObject gsonbt = (JsonObject) NbtGsonConverter.nbtToGsonVal(nbt);
|
||||||
@ -147,11 +148,12 @@ public class ItemStackAdapter implements JsonDeserializer<ItemStack>, JsonSerial
|
|||||||
{
|
{
|
||||||
JsonObject jsonbt = jsonItemStack.get(TAG).getAsJsonObject();
|
JsonObject jsonbt = jsonItemStack.get(TAG).getAsJsonObject();
|
||||||
|
|
||||||
CraftItemStack craftItemStack = new CraftItemStack(stack);
|
CraftItemStack craftItemStack = CraftItemStack.asCraftCopy(stack);
|
||||||
stack = craftItemStack;
|
stack = craftItemStack;
|
||||||
|
|
||||||
NBTBase nbt = NbtGsonConverter.gsonValToNbt(jsonbt, null, NBType.COMPOUND, NBType.UNKNOWN);
|
NBTBase nbt = NbtGsonConverter.gsonValToNbt(jsonbt, null, NBType.COMPOUND, NBType.UNKNOWN);
|
||||||
craftItemStack.getHandle().tag = (NBTTagCompound) nbt;
|
|
||||||
|
getHandle(craftItemStack).tag = (NBTTagCompound) nbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add enchantments if there are any
|
// Add enchantments if there are any
|
||||||
@ -168,4 +170,36 @@ public class ItemStackAdapter implements JsonDeserializer<ItemStack>, JsonSerial
|
|||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// GET HANDLE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static Field fieldCraftItemStackDotHandle = null;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fieldCraftItemStackDotHandle = CraftItemStack.class.getDeclaredField("handle");
|
||||||
|
fieldCraftItemStackDotHandle.setAccessible(true);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static net.minecraft.server.v1_4_5.ItemStack getHandle(CraftItemStack craftItemStack)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (net.minecraft.server.v1_4_5.ItemStack) fieldCraftItemStackDotHandle.get(craftItemStack);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,6 +224,9 @@ public class PlayerUtil implements Listener
|
|||||||
|
|
||||||
protected static void populateCaseInsensitiveNameToCaseCorrectName()
|
protected static void populateCaseInsensitiveNameToCaseCorrectName()
|
||||||
{
|
{
|
||||||
|
// The player file may not exist yet
|
||||||
|
if (playerfolder == null) return;
|
||||||
|
|
||||||
// Populate by removing .dat
|
// Populate by removing .dat
|
||||||
for (File playerfile : playerfolder.listFiles())
|
for (File playerfile : playerfolder.listFiles())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user