- Made SQL calls async
This commit is contained in:
parent
156982460f
commit
e032b81842
|
@ -38,22 +38,31 @@ public class EloRepository extends MinecraftRepository
|
|||
|
||||
public boolean saveElo(int accountId, int gameType, int oldElo, int elo) throws SQLException
|
||||
{
|
||||
boolean updateSucceeded = false;
|
||||
|
||||
// If we're increasing in elo we verify the server version matches the database version (prevent d/c and double wins with concurrent matches)
|
||||
// Otherwise we always take their elo down if they lose.
|
||||
if (elo > oldElo)
|
||||
updateSucceeded = executeUpdate(UPDATE_ELO_ONLY_IF_MATCH, new ColumnInt("elo", elo - oldElo), new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType), new ColumnInt("elo", oldElo)) > 0;
|
||||
else
|
||||
final List<Boolean> ret = new ArrayList<Boolean>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
updateSucceeded = executeUpdate(UPDATE_ELO, new ColumnInt("elo", elo - oldElo), new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType)) > 0;
|
||||
|
||||
if (!updateSucceeded && executeUpdate(INSERT_ELO, new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType), new ColumnInt("elo", elo)) > 0)
|
||||
updateSucceeded = true;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
boolean updateSucceeded = false;
|
||||
|
||||
// If we're increasing in elo we verify the server version matches the database version (prevent d/c and double wins with concurrent matches)
|
||||
// Otherwise we always take their elo down if they lose.
|
||||
if (elo > oldElo)
|
||||
updateSucceeded = executeUpdate(UPDATE_ELO_ONLY_IF_MATCH, new ColumnInt("elo", elo - oldElo), new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType), new ColumnInt("elo", oldElo)) > 0;
|
||||
else
|
||||
{
|
||||
updateSucceeded = executeUpdate(UPDATE_ELO, new ColumnInt("elo", elo - oldElo), new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType)) > 0;
|
||||
|
||||
if (!updateSucceeded && executeUpdate(INSERT_ELO, new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType), new ColumnInt("elo", elo)) > 0)
|
||||
updateSucceeded = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return updateSucceeded;
|
||||
if (ret.isEmpty())
|
||||
ret.add(false);
|
||||
|
||||
return ret.get(0);
|
||||
}
|
||||
|
||||
public EloClientData loadClientInformation(ResultSet resultSet) throws SQLException
|
||||
|
@ -71,17 +80,23 @@ public class EloRepository extends MinecraftRepository
|
|||
public long getStrikeExpiry(int accountId)
|
||||
{
|
||||
final List<Long> expire = new ArrayList<Long>();
|
||||
executeQuery(GRAB_STRIKE_EXPIRY, new ResultSetCallable()
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
public void run()
|
||||
{
|
||||
while(resultSet.next())
|
||||
executeQuery(GRAB_STRIKE_EXPIRY, new ResultSetCallable()
|
||||
{
|
||||
expire.add(resultSet.getLong(1));
|
||||
}
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while(resultSet.next())
|
||||
{
|
||||
expire.add(resultSet.getLong(1));
|
||||
}
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
});
|
||||
|
||||
if (expire.isEmpty())
|
||||
expire.add(System.currentTimeMillis() - 5555);
|
||||
|
@ -92,17 +107,23 @@ public class EloRepository extends MinecraftRepository
|
|||
public long getBanExpiry(int accountId)
|
||||
{
|
||||
final List<Long> expire = new ArrayList<Long>();
|
||||
executeQuery(GRAB_BAN_EXPIRY, new ResultSetCallable()
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
public void run()
|
||||
{
|
||||
while(resultSet.next())
|
||||
executeQuery(GRAB_BAN_EXPIRY, new ResultSetCallable()
|
||||
{
|
||||
expire.add(resultSet.getLong(1));
|
||||
}
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while(resultSet.next())
|
||||
{
|
||||
expire.add(resultSet.getLong(1));
|
||||
}
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
});
|
||||
|
||||
if (expire.isEmpty())
|
||||
expire.add(System.currentTimeMillis() - 5555);
|
||||
|
@ -113,17 +134,23 @@ public class EloRepository extends MinecraftRepository
|
|||
public int getStrikes(int accountId)
|
||||
{
|
||||
final List<Integer> strike = new ArrayList<Integer>();
|
||||
executeQuery(GRAB_STRIKES, new ResultSetCallable()
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
public void run()
|
||||
{
|
||||
while(resultSet.next())
|
||||
executeQuery(GRAB_STRIKES, new ResultSetCallable()
|
||||
{
|
||||
strike.add(resultSet.getInt(1));
|
||||
}
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while(resultSet.next())
|
||||
{
|
||||
strike.add(resultSet.getInt(1));
|
||||
}
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
});
|
||||
|
||||
if (strike.isEmpty())
|
||||
strike.add(0);
|
||||
|
@ -164,15 +191,28 @@ public class EloRepository extends MinecraftRepository
|
|||
minutes = 240;
|
||||
break;
|
||||
}
|
||||
long banEnd = System.currentTimeMillis() + UtilTime.convert(minutes, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
|
||||
long strikesExpire = System.currentTimeMillis() + UtilTime.convert(1, TimeUnit.DAYS, TimeUnit.MILLISECONDS);
|
||||
int newStrikes = Math.min(getStrikes(accountId) + 1, 8);
|
||||
executeUpdate(UPDATE_BAN, new ColumnInt("accountId", accountId), new ColumnInt("strikes", newStrikes), new ColumnLong("strikesExpire", strikesExpire), new ColumnLong("banEnd", banEnd));
|
||||
final long banEnd = System.currentTimeMillis() + UtilTime.convert(minutes, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
|
||||
final long strikesExpire = System.currentTimeMillis() + UtilTime.convert(1, TimeUnit.DAYS, TimeUnit.MILLISECONDS);
|
||||
final int newStrikes = Math.min(getStrikes(accountId) + 1, 8);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
executeUpdate(UPDATE_BAN, new ColumnInt("accountId", accountId), new ColumnInt("strikes", newStrikes), new ColumnLong("strikesExpire", strikesExpire), new ColumnLong("banEnd", banEnd));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void resetStrikes(int accountId)
|
||||
{
|
||||
executeUpdate(DELETE_STRIKES, new ColumnInt("accountId", accountId));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
executeUpdate(DELETE_STRIKES, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue