From 5cced1beca880561b204885a5a2256ce5fa09abd Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Tue, 30 Jan 2018 02:15:46 -0500 Subject: [PATCH] Allow the stat converter to handle excessively large stat values rather than having to do it manually --- .../src/com/mineplex/statconverter/Main.java | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java b/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java index a300a5731..bb1bb6d5a 100644 --- a/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java +++ b/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java @@ -11,9 +11,11 @@ import java.sql.Statement; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.regex.Pattern; import com.google.common.io.Files; import com.mineplex.statconverter.database.mysql.DBPool; +import com.mysql.jdbc.exceptions.jdbc4.MySQLDataException; public class Main { @@ -106,7 +108,57 @@ public class Main { while (rs.next()) { - converting.put(new Integer[] {rs.getInt("accountId"), rs.getInt("statId")}, rs.getLong("value")); + final int accountId = rs.getInt("accountId"); + final int statId = rs.getInt("statId"); + long value = 0; + try + { + value = rs.getLong("value"); + } + catch (MySQLDataException ex) + { + long played = 0; + try (ResultSet r = s.executeQuery("SELECT name FROM stats WHERE id=" + statId + ";")) + { + r.next(); + String[] parts = r.getString(1).split(Pattern.quote(".")); + String type = parts[0]; + String stat = parts[1]; + if (!stat.equals("ExpEarned")) + { + System.out.println("VALUE IS TOO BIG BUT STAT IS NOT EXPEARNED"); + System.exit(0); + return; + } + + ResultSet playedSet; + if (type.equals("Global")) + { + playedSet = s.executeQuery("SELECT SUM(value) FROM accountStat WHERE accountId=" + accountId + " AND statId IN (SELECT id FROM stats WHERE name LIKE '%.Wins' OR name LIKE '%.Losses');"); + } + else + { + playedSet = s.executeQuery("SELECT SUM(value) FROM accountStat WHERE accountId=" + accountId + " AND statId IN (SELECT id FROM stats WHERE name IN ('" + type + ".Wins', '" + type + ".Losses'));"); + } + if (playedSet.next()) + { + try + { + played = playedSet.getLong(1); + } + catch (Exception anything) {} + finally + { + playedSet.close(); + } + } + } + + long newValue = played * 625; //Average xp per game network-wide + s.executeUpdate("UPDATE accountStat SET value=" + newValue + " WHERE accountId=" + accountId + " AND statId=" + statId + ";"); + value = newValue; + } + converting.put(new Integer[] {rs.getInt("accountId"), rs.getInt("statId")}, value); } } }