mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-12-04 14:03:24 +01:00
Fix cooldown sync issues
This commit is contained in:
parent
5ae8f29950
commit
83c1ca1cc0
@ -41,7 +41,7 @@ Cooldown:
|
||||
# If enabled, cooldowns will be synced between servers (BungeeCord network). It will also allow keeping the cooldown through server restarts.
|
||||
# You should only use it with long cooldown times.
|
||||
Sync: false
|
||||
# Adds the cooldown when the player joins the server
|
||||
# Adds the cooldown when the player joins the server. Will be disabled if sync is enabled.
|
||||
AddOnJoin: true
|
||||
|
||||
# Controls for the auto pickup on full inventory function
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
public class MySQL extends SQL
|
||||
{
|
||||
public MySQL(@NotNull Minepacks plugin, @Nullable ConnectionProvider connectionProvider) throws SQLException
|
||||
public MySQL(final @NotNull Minepacks plugin, final @Nullable ConnectionProvider connectionProvider) throws SQLException
|
||||
{
|
||||
super(plugin, (connectionProvider == null) ? new MySQLConnectionProvider(plugin.getLogger(), plugin.getDescription().getName(), plugin.getConfiguration()) : connectionProvider);
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ protected final void buildQueries()
|
||||
" WHERE {FieldUUID}=?;";
|
||||
queryUpdatePlayerAdd = "INSERT INTO {TablePlayers} ({FieldName},{FieldUUID}) VALUES (?,?) ON DUPLICATE KEY UPDATE {FieldName}=?;";
|
||||
queryGetBP = "SELECT * FROM {TableBackpacks} WHERE {FieldBPOwner}=?;";
|
||||
querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) VALUE (?,?) ON DUPLICATE KEY UPDATE {FieldCDTime}=?;";
|
||||
querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) VALUES (?,?) ON DUPLICATE KEY UPDATE {FieldCDTime}=?;";
|
||||
queryDeleteOldCooldowns = "DELETE FROM {TableCooldowns} WHERE {FieldCDTime}<?;";
|
||||
queryInsertBp = "REPLACE INTO {TableBackpacks} ({FieldBPOwner},{FieldBPITS},{FieldBPVersion}) VALUES (?,?,?);";
|
||||
queryUpdateBp = "UPDATE {TableBackpacks} SET {FieldBPITS}=?,{FieldBPVersion}=?,{FieldBPLastUpdate}={NOW} WHERE {FieldBPOwner}=?;";
|
||||
|
@ -30,10 +30,7 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.*;
|
||||
|
||||
public class SQLite extends SQL
|
||||
{
|
||||
@ -71,6 +68,7 @@ protected void updateQueriesForDialect()
|
||||
queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')";
|
||||
queryUpdateBp = queryUpdateBp.replaceAll("\\{NOW}", "DATE('now')");
|
||||
queryUpdatePlayerAdd = "INSERT OR IGNORE INTO {TablePlayers} ({FieldName},{FieldUUID}) VALUES (?,?);";
|
||||
querySyncCooldown = "INSERT OR REPLACE INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) VALUES (?,?);";
|
||||
}
|
||||
|
||||
private void doPHQuery(final @NotNull Statement statement, final @NotNull @Language("SQL") String query) throws SQLException
|
||||
@ -129,4 +127,10 @@ protected void updatePlayer(@NotNull Connection connection, @NotNull MinepacksPl
|
||||
DBTools.runStatement(connection, queryUpdatePlayerAdd, player.getName(), formatUUID(player.getUUID()));
|
||||
DBTools.runStatement(connection, "UPDATE `" + tablePlayers + "` SET `" + fieldPlayerName + "`=? WHERE `" + fieldPlayerUUID + "`=?;", player.getName(), formatUUID(player.getUUID()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCooldown(final @NotNull MinepacksPlayerData player)
|
||||
{
|
||||
runStatementAsync(querySyncCooldown, player.getDatabaseKey(), new Timestamp(player.getCooldown()));
|
||||
}
|
||||
}
|
@ -226,7 +226,7 @@ public boolean isCommandCooldownSyncEnabled()
|
||||
|
||||
public boolean isCommandCooldownAddOnJoinEnabled()
|
||||
{
|
||||
return getConfigE().getBoolean("Cooldown.AddOnJoin", true);
|
||||
return getConfigE().getBoolean("Cooldown.AddOnJoin", true) && !isCommandCooldownSyncEnabled();
|
||||
}
|
||||
|
||||
public Collection<GameMode> getAllowedGameModes()
|
||||
|
@ -53,7 +53,7 @@ public class MinepacksPlayerData implements MinepacksPlayerExtended, ICacheableP
|
||||
@Getter private String backpackStyleName = MagicValues.BACKPACK_STYLE_NAME_DEFAULT;
|
||||
private ItemConfig backpackStyle = null;
|
||||
@Getter private Backpack backpack = null;
|
||||
@Getter private long cooldown = 0;
|
||||
@Getter private long cooldown = System.currentTimeMillis();
|
||||
@Getter @Setter private boolean backpackLoadingRequested = false;
|
||||
|
||||
@Getter @Setter private Object databaseKey = null;
|
||||
|
@ -39,11 +39,8 @@ public CooldownHandler(final @NotNull Minepacks plugin)
|
||||
|
||||
public long getRemainingCooldown(final @NotNull MinepacksPlayer player)
|
||||
{
|
||||
long cd = player.getCooldown() + cooldown;
|
||||
if(cd > System.currentTimeMillis())
|
||||
{
|
||||
return cd - System.currentTimeMillis();
|
||||
}
|
||||
long cd = player.getCooldown() + cooldown - System.currentTimeMillis();
|
||||
if(cd > 0) return cd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user