import { world, system } from "@minecraft/server";
import { transferPlayer } from "@minecraft/server-admin";

// ADVENTURE tag
world.afterEvents.entityHitEntity.subscribe((data) => {
    const { hitEntity: entity, damagingEntity: player } = data;
    if (!entity || !player || !player.isValid) return;

    if (entity.hasTag("adventure")) {
        system.run(() => {
            transferPlayer(player, {
                hostname: "PR_GoldServer.exaroton.me",
                port: 64575
            });
        });
    }
});

// SURVIVAL tag
world.afterEvents.entityHitEntity.subscribe((data) => {
    const { hitEntity: entity, damagingEntity: player } = data;
    if (!entity || !player || !player.isValid) return;

    if (entity.hasTag("survival")) {
        system.run(() => {
            transferPlayer(player, {
                hostname: "PR_BLUE_SERVER.exaroton.me",
                port: 37183
            });
        });
    }
});

// PRISON tag
world.afterEvents.entityHitEntity.subscribe((data) => {
    const { hitEntity: entity, damagingEntity: player } = data;
    if (!entity || !player || !player.isValid) return;

    if (entity.hasTag("prison")) {
        system.run(() => {
            transferPlayer(player, {
                hostname: "PR_GoldServer.exaroton.me",
                port: 64575
            });
        });
    }
});
