import { world, ItemStack } from "@minecraft/server";

world.afterEvents.playerSpawn.subscribe((data) => {
  const firstSpawn = data.initialSpawn;
  const player = data.player;

  if (!firstSpawn) return;

  const inventory = player.getComponent("minecraft:inventory").container;
  inventory.setItem(8, new ItemStack("arcedge_bap:guide_book", 1));

  if (!player.getDynamicProperty("first_buddy_interact_default")) {
    player.setDynamicProperty("first_buddy_interact_default", false);
  }
  if (!player.getDynamicProperty("first_baby_buddy_spawn")) {
    player.setDynamicProperty("first_baby_buddy_spawn", false);
  }
  if (!player.getDynamicProperty("first_buddy_interact_turtle_special")) {
    player.setDynamicProperty("first_buddy_interact_turtle_special", false);
  }
  if (!player.getDynamicProperty("first_buddy_builder_interact_default")) {
    player.setDynamicProperty("first_buddy_builder_interact_default", false);
  }
  if (!player.getDynamicProperty("first_buddy_trader_interact_default")) {
    player.setDynamicProperty("first_buddy_trader_interact_default", false);
  }
});