Fix error with cooldown sync

This commit is contained in:
GeorgH93 2021-04-13 01:13:18 +02:00
parent b688cd3022
commit 9d851304f2
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 3 additions and 6 deletions

View File

@ -95,12 +95,9 @@ public void onPlayerJoinEvent(PlayerJoinEvent event)
plugin.getDatabase().getCooldown(event.getPlayer(), new Callback<Long>() { plugin.getDatabase().getCooldown(event.getPlayer(), new Callback<Long>() {
@Override @Override
public void onResult(Long dbCooldownTime) public void onResult(Long dbCooldownTime)
{
if(dbCooldownTime > System.currentTimeMillis())
{ {
cooldowns.put(uuid, dbCooldownTime); cooldowns.put(uuid, dbCooldownTime);
} }
}
@Override @Override
public void onFail() {} public void onFail() {}

View File

@ -56,7 +56,7 @@ protected void checkDB()
"REFERENCES {TablePlayers} ({FieldPlayerID}) ON DELETE CASCADE ON UPDATE CASCADE\n);")); "REFERENCES {TablePlayers} ({FieldPlayerID}) ON DELETE CASCADE ON UPDATE CASCADE\n);"));
if(syncCooldown) if(syncCooldown)
{ {
DBTools.updateDB(connection, replacePlaceholders("CREATE TABLE IF NOT EXISTS {TableCooldowns} (\n{FieldCDPlayer} INT UNSIGNED NOT NULL,\n{FieldCDTime} LONG NOT NULL,\nPRIMARY KEY ({FieldCDPlayer}),\n" + DBTools.updateDB(connection, replacePlaceholders("CREATE TABLE IF NOT EXISTS {TableCooldowns} (\n{FieldCDPlayer} INT UNSIGNED NOT NULL,\n{FieldCDTime} DATETIME NOT NULL,\nPRIMARY KEY ({FieldCDPlayer}),\n" +
"CONSTRAINT fk_{TableCooldowns}_{TablePlayers}_{FieldCDPlayer} FOREIGN KEY ({FieldCDPlayer}) " + "CONSTRAINT fk_{TableCooldowns}_{TablePlayers}_{FieldCDPlayer} FOREIGN KEY ({FieldCDPlayer}) " +
"REFERENCES {TablePlayers} ({FieldPlayerID}) ON DELETE CASCADE ON UPDATE CASCADE\n);")); "REFERENCES {TablePlayers} ({FieldPlayerID}) ON DELETE CASCADE ON UPDATE CASCADE\n);"));
} }

View File

@ -375,7 +375,7 @@ public void getCooldown(final Player player, final Callback<Long> callback)
ps.setString(1, getPlayerFormattedUUID(player)); ps.setString(1, getPlayerFormattedUUID(player));
try(ResultSet rs = ps.executeQuery()) try(ResultSet rs = ps.executeQuery())
{ {
final long time = (rs.next()) ? rs.getLong(fieldCdTime) : 0; final long time = (rs.next()) ? rs.getTimestamp(fieldCdTime).getTime() : 0;
plugin.getServer().getScheduler().runTask(plugin, () -> callback.onResult(time)); plugin.getServer().getScheduler().runTask(plugin, () -> callback.onResult(time));
} }
} }