Java: Как сократить мой гкод

Помогите пожалуйста дурачку)

@EventHandler
    public void getFigurePositions(EventGetFigurePositions event) {
        if (event.getFigure() != this) return;

        ArrayList<Integer[]> positions = new ArrayList<>();

        BoardCell cell = event.getCell();
        Board board = cell.board;
        int fx = cell.x, fy = cell.y;

        // Up side
        for (int y = 1; y < board.height; y++) {
            if (fy - y < 0) break;
            if (board.getCell(fx, fy - y).getTeam() == cell.getTeam()) break;
            if (board.getCell(fx, fy - y).getTeam() != cell.getTeam() &&
                board.getCell(fx, fy - y).getTeam() != null) {
                positions.add(new Integer[] {fx, fy - y});
                break;
            }

            positions.add(new Integer[] {fx, fy - y});
        }

        // Down side
        for (int y = 1; y < board.height; y++) {
            if (fy + y >= board.height) break;
            if (board.getCell(fx, fy + y).getTeam() == cell.getTeam()) break;
            if (board.getCell(fx, fy + y).getTeam() != cell.getTeam() &&
                board.getCell(fx, fy + y).getTeam() != null) {
                positions.add(new Integer[] {fx, fy + y});
                break;
            }
            
            positions.add(new Integer[] {fx, fy + y});
        }

        // Left side
        for (int x = 1; x < board.width; x++) {
            if (fx - x < 0) break;
            if (board.getCell(fx - x, fy).getTeam() == cell.getTeam()) break;
            if (board.getCell(fx - x, fy).getTeam() != cell.getTeam() &&
                board.getCell(fx - x, fy).getTeam() != null) {
                positions.add(new Integer[] {fx - x, fy});
                break;
            }

            positions.add(new Integer[] {fx - x, fy});
        }

        // Right side
        for (int x = 1; x < board.width; x++) {
            if (fx + x >= board.width) break;
            if (board.getCell(fx + x, fy).getTeam() == cell.getTeam()) break;
            if (board.getCell(fx + x, fy).getTeam() != cell.getTeam() &&
                board.getCell(fx + x, fy).getTeam() != null) {
                positions.add(new Integer[] {fx + x, fy});
                break;
            }

            positions.add(new Integer[] {fx + x, fy});
        }
        
        //positions
    }
1 лайк

убери пробелы

это в любом случае пиздец какой-то, как можно было к такому прийти вообще изначально

Спасибо, как ты к такому пришел, это реально пздц. До этого додуматься нужно