Program: 187657
Project: 187657
Buggy source:
@EventHandler public void onEntityDamage(final EntityDamageEvent event){
  if (!(event instanceof EntityDamageByEntityEvent) || event.isCancelled()) {
    return;
  }
  EntityDamageByEntityEvent e=(EntityDamageByEntityEvent)event;
  if (event.getEntity() instanceof CraftMyPet) {
    if (e.getDamager() instanceof Player) {
      Player damager=(Player)e.getDamager();
      MyPet MPet=MyPetList.getMyPet(event.getEntity().getEntityId());
      MPet.ResetSitTimer();
      if (damager.getItemInHand().getType() == MyPetConfig.LeashItem) {
        String msg;
        if (MPet.getHealth() > MPet.getMaxHealth() / 3 * 2) {
          msg="String_Node_Str" + ChatColor.GREEN + MPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ ChatColor.YELLOW+ MPet.getMaxHealth()+ ChatColor.WHITE;
        }
 else         if (MPet.getHealth() > MPet.getMaxHealth() / 3) {
          msg="String_Node_Str" + ChatColor.YELLOW + MPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ ChatColor.YELLOW+ MPet.getMaxHealth()+ ChatColor.WHITE;
        }
 else {
          msg="String_Node_Str" + ChatColor.RED + MPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ ChatColor.YELLOW+ MPet.getMaxHealth()+ ChatColor.WHITE;
        }
        damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",MPet.Name).replace("String_Node_Str",msg));
        if (MyPetConfig.LevelSystem) {
          int lvl=MPet.getExperience().getLevel();
          double EXP=MPet.getExperience().getCurrentExp();
          double reqEXP=MPet.getExperience().getRequiredExp();
          damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",MPet.Name).replace("String_Node_Str",String.format("String_Node_Str",EXP)).replace("String_Node_Str","String_Node_Str" + lvl).replace("String_Node_Str",String.format("String_Node_Str",reqEXP)).replace("String_Node_Str",String.format("String_Node_Str",EXP * 100 / reqEXP)));
        }
        if (MPet.Pet.isSitting()) {
          MPet.Pet.setSitting(true);
        }
        event.setCancelled(true);
      }
      if (!event.getEntity().getLocation().getWorld().getPVP()) {
        event.setCancelled(true);
      }
      if (!MyPetUtil.canHurtWorldGuard(MPet.getOwner().getPlayer())) {
        event.setCancelled(true);
      }
      if (!MyPetUtil.canHurtFactions(damager,MPet.getOwner().getPlayer())) {
        event.setCancelled(true);
      }
      if (!MyPetUtil.canHurtTowny(damager,MPet.getOwner().getPlayer())) {
        event.setCancelled(true);
      }
    }
  }
 else   if (MyPetType.isLeashableEntityType(event.getEntity().getType())) {
    if (e.getDamager() instanceof Player) {
      Player damager=(Player)e.getDamager();
      if (!MyPetList.hasMyPet(damager)) {
        if (!MyPetPermissions.has(damager,"String_Node_Str") || damager.getItemInHand().getType() != MyPetConfig.LeashItem) {
          return;
        }
        Entity leashTarget=event.getEntity();
        boolean willBeLeashed=false;
        boolean sitting=false;
        if (leashTarget instanceof Wolf) {
          Wolf TargetWolf=(Wolf)event.getEntity();
          String OwnerOfTheWolf=((CraftWolf)TargetWolf).getHandle().getOwnerName();
          Player Attacker=(Player)e.getDamager();
          boolean isTarmed=TargetWolf.isTamed();
          sitting=((Wolf)event.getEntity()).isSitting();
          if (isTarmed && OwnerOfTheWolf.equals(Attacker.getName())) {
            willBeLeashed=true;
          }
        }
        if (willBeLeashed) {
          event.setCancelled(true);
          MyPet MPet=MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getNewMyPetInstance(damager);
          MyPetUtil.getServer().getPluginManager().callEvent(new MyPetLeashEvent(MPet));
          MyPetList.addMyPet(MPet);
          MPet.createPet();
          MPet.setSitting(sitting);
          event.getEntity().remove();
          MyPetUtil.getDebugLogger().info("String_Node_Str");
          MyPetUtil.getDebugLogger().info("String_Node_Str" + MPet.toString());
          MyPetPlugin.getPlugin().savePets(MyPetPlugin.NBTPetFile);
          damager.sendMessage(MyPetUtil.setColors(MyPetLanguage.getString("String_Node_Str")));
        }
      }
    }
  }
}

Fixed version (ground truth):
@EventHandler public void onEntityDamage(final EntityDamageEvent event){
  if (!(event instanceof EntityDamageByEntityEvent) || event.isCancelled()) {
    return;
  }
  EntityDamageByEntityEvent e=(EntityDamageByEntityEvent)event;
  if (event.getEntity() instanceof CraftMyPet) {
    if (e.getDamager() instanceof Player) {
      Player damager=(Player)e.getDamager();
      MyPet MPet=MyPetList.getMyPet(event.getEntity().getEntityId());
      MPet.ResetSitTimer();
      if (damager.getItemInHand().getType() == MyPetConfig.LeashItem) {
        String msg;
        if (MPet.getHealth() > MPet.getMaxHealth() / 3 * 2) {
          msg="String_Node_Str" + ChatColor.GREEN + MPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ ChatColor.YELLOW+ MPet.getMaxHealth()+ ChatColor.WHITE;
        }
 else         if (MPet.getHealth() > MPet.getMaxHealth() / 3) {
          msg="String_Node_Str" + ChatColor.YELLOW + MPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ ChatColor.YELLOW+ MPet.getMaxHealth()+ ChatColor.WHITE;
        }
 else {
          msg="String_Node_Str" + ChatColor.RED + MPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ ChatColor.YELLOW+ MPet.getMaxHealth()+ ChatColor.WHITE;
        }
        damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",MPet.Name).replace("String_Node_Str",msg));
        if (MyPetConfig.LevelSystem) {
          int lvl=MPet.getExperience().getLevel();
          double EXP=MPet.getExperience().getCurrentExp();
          double reqEXP=MPet.getExperience().getRequiredExp();
          damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",MPet.Name).replace("String_Node_Str",String.format("String_Node_Str",EXP)).replace("String_Node_Str","String_Node_Str" + lvl).replace("String_Node_Str",String.format("String_Node_Str",reqEXP)).replace("String_Node_Str",String.format("String_Node_Str",EXP * 100 / reqEXP)));
        }
        if (MPet.getPet().isSitting()) {
          MPet.getPet().setSitting(true);
        }
        event.setCancelled(true);
      }
      if (!event.getEntity().getLocation().getWorld().getPVP()) {
        event.setCancelled(true);
      }
      if (!MyPetUtil.canHurtWorldGuard(MPet.getOwner().getPlayer())) {
        event.setCancelled(true);
      }
      if (!MyPetUtil.canHurtFactions(damager,MPet.getOwner().getPlayer())) {
        event.setCancelled(true);
      }
      if (!MyPetUtil.canHurtTowny(damager,MPet.getOwner().getPlayer())) {
        event.setCancelled(true);
      }
    }
  }
 else   if (MyPetType.isLeashableEntityType(event.getEntity().getType())) {
    if (e.getDamager() instanceof Player) {
      Player damager=(Player)e.getDamager();
      if (!MyPetList.hasMyPet(damager)) {
        if (!MyPetPermissions.has(damager,"String_Node_Str") || damager.getItemInHand().getType() != MyPetConfig.LeashItem) {
          return;
        }
        Entity leashTarget=event.getEntity();
        boolean willBeLeashed=false;
        boolean sitting=false;
        if (leashTarget instanceof Wolf) {
          Wolf TargetWolf=(Wolf)event.getEntity();
          String OwnerOfTheWolf=((CraftWolf)TargetWolf).getHandle().getOwnerName();
          Player Attacker=(Player)e.getDamager();
          boolean isTarmed=TargetWolf.isTamed();
          sitting=((Wolf)event.getEntity()).isSitting();
          if (isTarmed && OwnerOfTheWolf.equals(Attacker.getName())) {
            willBeLeashed=true;
          }
        }
        if (willBeLeashed) {
          event.setCancelled(true);
          MyPet MPet=MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getNewMyPetInstance(damager);
          MyPetUtil.getServer().getPluginManager().callEvent(new MyPetLeashEvent(MPet));
          MyPetList.addMyPet(MPet);
          MPet.createPet(leashTarget.getLocation());
          MPet.setSitting(sitting);
          event.getEntity().remove();
          MyPetUtil.getDebugLogger().info("String_Node_Str");
          MyPetUtil.getDebugLogger().info("String_Node_Str" + MPet.toString());
          MyPetPlugin.getPlugin().savePets(MyPetPlugin.NBTPetFile);
          damager.sendMessage(MyPetUtil.setColors(MyPetLanguage.getString("String_Node_Str")));
        }
      }
    }
  }
}