}
try {
CommonPlayer commonPlayer = CommonEntity.get(player);
Object playerHandle = Conversion.toEntityHandle.convert(player);
File source = getSaveFile(player);
CommonTagCompound data = read(source, player);
// First, clear previous player information when loading involves adding new elements
clearEffects(player);
// Refresh attributes
if (data.containsKey("Attributes")) {
NBTUtil.loadAttributes(player, data.get("Attributes", CommonTagList.class));
}
// Load the data
NBTUtil.loadInventory(player.getInventory(), data.createList("Inventory"));
EntityHumanRef.exp.set(playerHandle, data.getValue("XpP", 0.0f));
EntityHumanRef.expLevel.set(playerHandle, data.getValue("XpLevel", 0));
EntityHumanRef.expTotal.set(playerHandle, data.getValue("XpTotal", 0));
if (Common.MC_VERSION.equals("1.5.2")) {
commonPlayer.setHealth(data.getValue("Health", (int) commonPlayer.getMaxHealth()));
} else {
commonPlayer.setHealth(data.getValue("HealF", (float) commonPlayer.getMaxHealth()));
}
// Respawn position
String spawnWorld = data.getValue("SpawnWorld", "");
IntVector3 spawn = null;
if (!spawnWorld.isEmpty()) {
Integer x = data.getValue("SpawnX", Integer.class);
Integer y = data.getValue("SpawnY", Integer.class);
Integer z = data.getValue("SpawnZ", Integer.class);
if (x != null && y != null && z != null) {
spawn = new IntVector3(x, y, z);
} else {
spawnWorld = ""; //reset, invalid coordinates
}
}
EntityHumanRef.spawnCoord.set(playerHandle, spawn);
EntityHumanRef.spawnWorld.set(playerHandle, spawnWorld);
EntityHumanRef.spawnForced.set(playerHandle, data.getValue("SpawnForced", false));
// Other data
NBTUtil.loadFoodMetaData(EntityHumanRef.foodData.get(playerHandle), data);
NBTUtil.loadInventory(player.getEnderChest(), data.createList("EnderItems"));
// Load Mob Effects
HashMap<Integer, Object> effects = EntityHumanRef.mobEffects.get(playerHandle);
if (data.containsKey("ActiveEffects")) {
CommonTagList taglist = data.createList("ActiveEffects");
for (int i = 0; i < taglist.size(); ++i) {
Object mobEffect = NBTUtil.loadMobEffect((CommonTagCompound) taglist.get(i));
effects.put(MobEffectRef.effectId.get(mobEffect), mobEffect);
}
}