- Made SQL calls async
This commit is contained in:
parent
156982460f
commit
e032b81842
@ -37,6 +37,11 @@ public class EloRepository extends MinecraftRepository
|
||||
public void initialize() { }
|
||||
|
||||
public boolean saveElo(int accountId, int gameType, int oldElo, int elo) throws SQLException
|
||||
{
|
||||
final List<Boolean> ret = new ArrayList<Boolean>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
boolean updateSucceeded = false;
|
||||
|
||||
@ -51,9 +56,13 @@ public class EloRepository extends MinecraftRepository
|
||||
if (!updateSucceeded && executeUpdate(INSERT_ELO, new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType), new ColumnInt("elo", elo)) > 0)
|
||||
updateSucceeded = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (ret.isEmpty())
|
||||
ret.add(false);
|
||||
|
||||
return updateSucceeded;
|
||||
return ret.get(0);
|
||||
}
|
||||
|
||||
public EloClientData loadClientInformation(ResultSet resultSet) throws SQLException
|
||||
@ -71,6 +80,10 @@ public class EloRepository extends MinecraftRepository
|
||||
public long getStrikeExpiry(int accountId)
|
||||
{
|
||||
final List<Long> expire = new ArrayList<Long>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
executeQuery(GRAB_STRIKE_EXPIRY, new ResultSetCallable()
|
||||
{
|
||||
@Override
|
||||
@ -82,6 +95,8 @@ public class EloRepository extends MinecraftRepository
|
||||
}
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
});
|
||||
|
||||
if (expire.isEmpty())
|
||||
expire.add(System.currentTimeMillis() - 5555);
|
||||
@ -92,6 +107,10 @@ public class EloRepository extends MinecraftRepository
|
||||
public long getBanExpiry(int accountId)
|
||||
{
|
||||
final List<Long> expire = new ArrayList<Long>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
executeQuery(GRAB_BAN_EXPIRY, new ResultSetCallable()
|
||||
{
|
||||
@Override
|
||||
@ -103,6 +122,8 @@ public class EloRepository extends MinecraftRepository
|
||||
}
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
});
|
||||
|
||||
if (expire.isEmpty())
|
||||
expire.add(System.currentTimeMillis() - 5555);
|
||||
@ -113,6 +134,10 @@ public class EloRepository extends MinecraftRepository
|
||||
public int getStrikes(int accountId)
|
||||
{
|
||||
final List<Integer> strike = new ArrayList<Integer>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
executeQuery(GRAB_STRIKES, new ResultSetCallable()
|
||||
{
|
||||
@Override
|
||||
@ -124,6 +149,8 @@ public class EloRepository extends MinecraftRepository
|
||||
}
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
});
|
||||
|
||||
if (strike.isEmpty())
|
||||
strike.add(0);
|
||||
@ -164,16 +191,29 @@ 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);
|
||||
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)
|
||||
{
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
executeUpdate(DELETE_STRIKES, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update()
|
||||
|
Loading…
Reference in New Issue
Block a user