
class Utilities {
  isVanilla(block) {
    return block?.typeId.startsWith("minecraft:");
  }

  isBedrock(block) {
    return block?.typeId == "minecraft:bedrock";
  }

  async runCommand(player, command) {
    try {
      return await player.runCommandAsync(command);
    } catch (e) {
      return { error: true };
    }
  }

  getEntities(dimension, includesName, type) {
    const entities = dimension.getEntities();
    const result = [];

    for (const entity of entities) {
      const tags = entity.getTags();

      if (tags.find((tag) => tag.includes(includesName)) && entity?.typeId == type) result.push(entity);
    }
    return result;
  }

  getName(entity, nametag) {
    if (!entity) return;

    for (const tag of entity.getTags()) {
      if (tag.includes("camera") || tag.includes("mine") || tag.includes("drone")) {
        const name = tag.split(":")[1].replace(nametag, "");

        return name;
      }
    }
  }
}

export const utilities = new Utilities();
