package me.eddiep.minecraft.ls.game.lsrating;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class LSRating {
    private int rating;
    private int avgAir;
    private double variance;
    private int matchesPlayed;
    private int[] matches; //Match rewards

    private static final double LOSS_MULTIPLIER = .875;

    public static final int DEFAULT_RATING = 1000;

    public LRSating() {}

    public void addMatch(int blockCount, String uuid) {
        this.matchesPlayed++;
        String url = "jdbc:mariadb://" + config.getString("Lavasurvival.DBHost") + "/" + config.getString("Lavasurvival.DBTable"), user = config.getString("Lavasurvival.DBUser"),
                pass = config.getString("Lavasurvival.DBPassword");
        try {
            Class.forName("org.mariadb.jdbc.Driver");
            Connection conn = DriverManager.getConnection(url, user, pass);
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(
                    "IF NOT EXISTS (SELECT 1 FROM users WHERE uuid='" + uuid + "') " +
                            "BEGIN " +
                                "INSERT INTO users (uuid, rating, matches, matchCount) VALUES ('" + uuid + "', '" + this.DEFAULT_RATING + "', '" + blockCount + "', '1');" +
                            "END" +
                    "ELSE " +
                            "BEGIN " +
                                "UPDATE users SET matches=CONCAT('," + blockCount + "',matches) WHERE uuid='" + uuid + "';" +
                            "END ;"
            );
            rs.close();
            stmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getRating() {return this.rating;}
}

@@ -180,16 +180,36 @@
 atement;
+%0Aimport java.util.*;
 %0A%0Apublic
@@ -253,244 +253,8 @@
 ing;
-%0A    private int avgAir;%0A    private double variance;%0A    private int matchesPlayed;%0A    private int%5B%5D matches; //Match rewards%0A%0A    private static final double LOSS_MULTIPLIER = .875;%0A%0A    public static final int DEFAULT_RATING = 1000;
 %0A%0A  
@@ -337,38 +337,8 @@
 ) %7B%0A
-        this.matchesPlayed++;%0A
     
@@ -827,424 +827,8 @@
 ry(%0A
-                    %22IF NOT EXISTS (SELECT 1 FROM users WHERE uuid='%22 + uuid + %22') %22 +%0A                            %22BEGIN %22 +%0A                                %22INSERT INTO users (uuid, rating, matches, matchCount) VALUES ('%22 + uuid + %22', '%22 + this.DEFAULT_RATING + %22', '%22 + blockCount + %22', '1');%22 +%0A                            %22END%22 +%0A                    %22ELSE %22 +%0A                            %22BEGIN %22 +%0A            
     
@@ -938,46 +938,8 @@
 %22';%22
- +%0A                            %22END ;%22
 %0A   

Don't need query if statement