// Makes Tickets of Eternal Keeping not consumed on death.

const tickets = {};

EntityEvents.death((event) => {
  const player = event.player;
  if (event.entity.isPlayer()) {
    tickets[player.uuid] = null;

    player.inventory.allItems.forEach((item) => {
      if (item.nbt && item.nbt.EternalKeep) tickets[player.uuid] = item.copy();
    });
  }
});

PlayerEvents.respawned((event) => {
  const player = event.player;

  const ticket = tickets[player.uuid];

  if (ticket != null) player.give(Item.of(ticket, 1));

  tickets[player.uuid] = null;
});
