import { world } from "@minecraft/server";
import { GAMGroupManager } from "./GAMGroupManager.js";

const mbEntities = [
  "pb_gat:mb_gam_lever_entity",
  "pb_gat:mb_tinker_table_entity",
  "pb_gat:mb_upgrade_puncher_entity",
];

world.afterEvents.entityDie.subscribe((data) => {
  const killed = data.deadEntity;
  if (!mbEntities.includes(killed.typeId)) return;

  try {
    const groupId = killed.getDynamicProperty("pb_gat:group_id");
    if (groupId) {
      GAMGroupManager.destroyGroup(groupId);
    }
  } catch (e) {
  }
});
