const tagToAppliedEffectOnMelee = {
  'skill_toxic_touch': {
    '1': {id: 'minecraft:poison', duration: 100, amplifier: 0},
    '2': {id: 'minecraft:poison', duration: 60, amplifier: 2}
  },
  'skill_withering_touch': {
    '1': {id: 'minecraft:wither', duration: 100, amplifier: 0},
    '2': {id: 'minecraft:wither', duration: 60, amplifier: 2}
  }
}

EntityEvents.hurt(event => {
  const { entity, source: { actual }, source } = event;
  if (actual == null || actual.type != 'minecraft:player') {
    return;
  }

  if (!source.isIndirect()) {
    for (let tag in tagToAppliedEffectOnMelee) {
      let foundTags = actual.tags.filter(t => t.startsWith(tag));
      if (!foundTags || foundTags.length == 0) {
        continue;
      }
      foundTags.sort((a, b) => a.localeCompare(b));
      let foundTag = foundTags[foundTags.length - 1];
      let level = foundTag.substring(foundTag.length() - 1);
      foundTag = foundTag.substring(0, foundTag.length() - 2);
      let effect = tagToAppliedEffectOnMelee[foundTag][level];
      if (effect) {
        entity.potionEffects.add(effect.id, effect.duration, effect.amplifier, false, false);
      }
    }
  }
});