package org.inventivetalent.npclib.npc.living.human;

import org.bukkit.entity.HumanEntity;
import org.inventivetalent.nbt.annotation.NBT;
import org.inventivetalent.npclib.Reflection;
import org.inventivetalent.npclib.entity.living.human.NPCEntityHuman;
import org.inventivetalent.npclib.npc.living.NPCLivingAbstract;
import org.inventivetalent.npclib.skin.ISkinnableEntity;
import org.inventivetalent.npclib.skin.SkinLayer;
import org.inventivetalent.reflection.minecraft.DataWatcher;

public abstract class NPCHumanAbstract<N extends NPCEntityHuman, B extends HumanEntity> extends NPCLivingAbstract<N, B> implements ISkinnableEntity {

	public NPCHumanAbstract(N npcEntity) {
		super(npcEntity);
	}

	@Override
	public void setSkinLayers(SkinLayer... visibleLayers) {
		setSkinLayerFlag(SkinLayer.getValue(visibleLayers));
	}

	@NBT({
				 "npclib.options",
				 "human",
				 "skinLayers" })
	protected void setSkinLayerFlag(@NBT int flag) {
		try {
			DataWatcher.setValue(Reflection.getDataWatcher(getBukkitEntity()), 10, DataWatcher.V1_9.ValueType.ENTITY_HUMAN_SKIN_LAYERS, (byte) flag);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@NBT({
				 "npclib.options",
				 "human",
				 "skinLayers" })
	protected int getSkinLayerFlag() {
		try {
			return (byte) DataWatcher.getValue(Reflection.getDataWatcher(getBukkitEntity()), 10, DataWatcher.V1_9.ValueType.ENTITY_HUMAN_SKIN_LAYERS);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}

@@ -69,73 +69,210 @@
 kit.
-entity.HumanEntity;%0Aimport org.inventivetalent.nbt.annotation.NBT
+Location;%0Aimport org.bukkit.Material;%0Aimport org.bukkit.entity.HumanEntity;%0Aimport org.bukkit.entity.Player;%0Aimport org.inventivetalent.nbt.annotation.NBT;%0Aimport org.inventivetalent.npclib.ClassBuilder
 ;%0Aim
@@ -769,16 +769,123 @@
 tity %7B%0A%0A
+%09@NBT(value = %7B%0A%09%09%09%22npclib.options%22,%0A%09%09%09%22human%22,%0A%09%09%09%22laying%22 %7D,%0A%09%09 read = false)%0A%09private boolean laying;%0A%0A
 %09public 
@@ -1720,10 +1720,737 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09@NBT(value = %7B%0A%09%09%09%22npclib.options%22,%0A%09%09%09%22human%22,%0A%09%09%09%22laying%22 %7D)%0A%09public void setLaying(@NBT boolean laying) %7B%0A%09%09this.laying = laying;%0A%09%09updateNearby();%0A%09%7D%0A%0A%09public boolean isLaying() %7B%0A%09%09return laying;%0A%09%7D%0A%0A%09@Override%0A%09public void updateToPlayer(Player player) %7B%0A%09%09if (getBukkitEntity().isDead()) %7B return; %7D%0A%09%09super.updateToPlayer(player);%0A%09%09if (isLaying()) %7B%0A%09%09%09Location bedLocation = getBukkitEntity().getLocation().clone();%0A%09%09%09bedLocation.setY(0);%0A%09%09%09// Create a fake bed block%0A%09%09%09player.sendBlockChange(bedLocation, Material.BED_BLOCK, (byte) 0);%0A%0A%09%09%09sendPacket(player, ClassBuilder.buildPacketPlayOutBed(getBukkitEntity().getEntityId(), bedLocation.getBlockX(), bedLocation.getBlockY(), bedLocation.getBlockZ()));%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

add laying methods