Allow the stat converter to handle excessively large stat values rather than having to do it manually
This commit is contained in:
parent
600378d361
commit
5cced1beca
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue