code: static List<Long> fixupShortcuts(List<Long> path, NavMeshQuery navQuery) {
          if (path.size() < 3) {
              return path;
          }
  
          // Get connected polygons
          List<Long> neis = new ArrayList<>();
  
          Result<Tupple2<MeshTile, Poly>> tileAndPoly = navQuery.getAttachedNavMesh().getTileAndPolyByRef(path.get(0));
          if (tileAndPoly.failed()) {
              return path;
          }
          MeshTile tile = tileAndPoly.result.first;
          Poly poly = tileAndPoly.result.second;
  
          for (int k = poly.firstLink; k != NavMesh.DT_NULL_LINK; k = tile.links.get(k).next) {
              Link link = tile.links.get(k);
              if (link.ref != 0) {
                  neis.add(link.ref);
              }
          }
  
          // If any of the neighbour polygons is within the next few polygons
          // in the path, short cut to that polygon directly.
          int maxLookAhead = 6;
          int cut = 0;
          for (int i = Math.min(maxLookAhead, path.size()) - 1; i > 1 && cut == 0; i--) {
              for (int j = 0; j < neis.size(); j++) {
                  if (path.get(i).longValue() == neis.get(j).longValue()) {
                      cut = i;
                      break;
                  }
              }
          }
          if (cut > 1) {
              List<Long> shortcut = new ArrayList<>();
              shortcut.add(path.get(0));
              shortcut.addAll(path.subList(cut, path.size()));
              return shortcut;
          }
          return path;
      }
docs: +---+---+