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

system.events.beforeWatchdogTerminate.subscribe(data => {
  data.cancel = true;
}); 

const swords = [ 
  "zweihander", "ōdachi","dane_axe"
];

const slownesSwords = [
  "long_sword", "bardiche"
];

world.events.tick.subscribe(() => {
  let players = world.getPlayers();

  for (const player of players) {
    const hand = player.getComponent("inventory").container.getItem(player.selectedSlot);
    const handId = hand ? hand.typeId.split(":")[1].toLowerCase() : null;
    
    if (!handId) continue;
    if (swords.find(id => handId.includes(id))) {
      player.addEffect(MinecraftEffectTypes.slowness, 1, 0, false);
    } else if (slownesSwords.find(id => handId.includes(id))) {
      player.addEffect(MinecraftEffectTypes.slowness, 1, 1, false);
    }
  }
});