import { runInterval, test } from "./Eternal/Utils";
import { overworld } from "./Eternal/Constants";

runInterval(() => {
  overworld.commandRunAsync(
    `execute as @p if entity @e[type=eternal:golden_dragon_gate,has_property={p:state="close"}] run tag @a[x=49112,y=112,z=-199,dx=-78,dy=27,dz=42,m=!creative] add d_tres`,
    `execute as @p if entity @e[type=eternal:mystical_golem_gate,has_property={p:state="close"}] run tag @a[x=50046,y=125,z=522,dx=-30,dy=11,dz=-32,m=!creative] add mg_tres`,
    `execute as @p if entity @e[type=eternal:yeti_gate,has_property={p:state="close"}] run tag @a[x=49843,y=113,z=-1040,dx=-53,dy=34,dz=-62,m=!creative] add y_tres`
  );
  // 49843 113 -1040
  // 49790 147 -1102
  // -53 34 -62
  const d_tres = overworld.fetchEntities("@a[tag=d_tres]");
  d_tres.forEach((player) => {
    player.commandRunAsync(
      `tag @s remove d_tres`,
      `teleport @s 49153 112 -178 facing 49152 112 -178`,
      `titleraw @s actionbar {"rawtext": [{"translate": "translate.restricted_area"}]}`
    );
  });

  const mg_tres = overworld.fetchEntities("@a[tag=mg_tres]");
  mg_tres.forEach((player) => {
    player.commandRunAsync(
      `tag @s remove mg_tres`,
      `teleport @s 50031 142 438 facing 50031 142 439`,
      `titleraw @s actionbar {"rawtext": [{"translate": "translate.restricted_area"}]}`
    );
  });

  const y_tres = overworld.fetchEntities("@a[tag=y_tres]");
  y_tres.forEach((player) => {
    player.commandRunAsync(
      `tag @s remove y_tres`,
      `teleport @s 49818 114 -1028 facing 49818 114 -1029`,
      `titleraw @s actionbar {"rawtext": [{"translate": "translate.restricted_area"}]}`
    );
  });
});
