package org.darkstorm.darkbot.minecraftbot.protocol.v5x.play.server;

import java.io.*;

import org.darkstorm.darkbot.minecraftbot.protocol.*;
import org.darkstorm.darkbot.minecraftbot.protocol.ProtocolX.State;
import org.darkstorm.darkbot.minecraftbot.util.IntHashMap;
import org.darkstorm.darkbot.minecraftbot.world.entity.WatchableObject;

public class PacketS0C_SpawnPlayer extends AbstractPacketX implements ReadablePacket {
	private int entityId;
	private String uuid, name;

	private double x, y, z, yaw, pitch;
	private int heldItemId;
	private IntHashMap<WatchableObject> metadata;

	public PacketS0C_SpawnPlayer() {
		super(0x0C, State.PLAY, Direction.DOWNSTREAM);
	}

	@Override
	public void readData(DataInputStream in) throws IOException {
		entityId = readVarInt(in);
		uuid = readString(in);
		name = readString(in);

		x = in.readInt() / 32D;
		y = in.readInt() / 32D;
		z = in.readInt() / 32D;
		yaw = (in.readByte() * 360) / 256D;
		pitch = (in.readByte() * 360) / 256D;
		heldItemId = in.readShort();
		metadata = readWatchableObjects(in);
	}

	public int getEntityId() {
		return entityId;
	}

	public String getUuid() {
		return uuid;
	}

	public String getName() {
		return name;
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	public double getZ() {
		return z;
	}

	public double getYaw() {
		return yaw;
	}

	public double getPitch() {
		return pitch;
	}

	public int getHeldItemId() {
		return heldItemId;
	}

	public IntHashMap<WatchableObject> getMetadata() {
		return metadata;
	}
}

@@ -473,16 +473,54 @@
 d, name;
+%0A%09private PlayerProperty%5B%5D properties;
 %0A%0A%09priva
@@ -864,16 +864,287 @@
 g(in);%0A%0A
+%09%09properties = new PlayerProperty%5BreadVarInt(in)%5D;%0A%09%09for(int i = 0; i %3C properties.length; i++) %7B%0A%09%09%09String name = readString(in);%0A%09%09%09String value = readString(in);%0A%09%09%09String signature = readString(in);%0A%09%09%09properties%5Bi%5D = new PlayerProperty(name, value, signature);%0A%09%09%7D%0A%0A
 %09%09x = in
@@ -1504,24 +1504,100 @@
 n name;%0A%09%7D%0A%0A
+%09public PlayerProperty%5B%5D getProperties() %7B%0A%09%09return properties.clone();%0A%09%7D%0A%0A
 %09public doub
@@ -1899,24 +1899,24 @@
 etadata() %7B%0A
-
 %09%09return met
@@ -1924,11 +1924,411 @@
 data;%0A%09%7D
+%0A%0A%09public static class PlayerProperty %7B%0A%09%09private final String name, value, signature;%0A%0A%09%09private PlayerProperty(String name, String value, String signature) %7B%0A%09%09%09this.name = name;%0A%09%09%09this.value = value;%0A%09%09%09this.signature = signature;%0A%09%09%7D%0A%0A%09%09public String getName() %7B%0A%09%09%09return name;%0A%09%09%7D%0A%0A%09%09public String getValue() %7B%0A%09%09%09return value;%0A%09%09%7D%0A%0A%09%09public String getSignature() %7B%0A%09%09%09return signature;%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

Fix protocol 5x crashing on player spawn