public static LivingEntity addCustomNBT(LivingEntity entity, String key, String value) {
if (entity == null) return null;
Entity bukkitEntity = entity;
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle();
NBTTagCompound tag = new NBTTagCompound();
// Writes the entity's NBT data to tag
nmsEntity.c(tag);
// Add custom NBT
tag.setString(key, value);
// Write tag back
((EntityLiving)nmsEntity).a(tag);
return entity;
}