import { world, Player } from "@minecraft/server";

world.afterEvents.projectileHitEntity.subscribe((event) => {
	if (world.getDynamicProperty("addon_toggle") == false) return;
	
	const projectile = event.projectile;
	const player = event.source;
	const target = event.getEntityHit().entity;
	if (!player || !target) return;
	const configCheck = (player.getDynamicProperty("bowHitSound") == true);
	
	if (projectile.typeId === "minecraft:arrow"
	&& configCheck
	&& target instanceof Player
	&& player !== target) {
		player.playSound( "random.orb", { pitch: 0.5 });
	}
});