diff --git a/Minepacks/resources/config.yml b/Minepacks/resources/config.yml index d2df004..ab3b6a9 100644 --- a/Minepacks/resources/config.yml +++ b/Minepacks/resources/config.yml @@ -7,7 +7,6 @@ Language: # Options: # Overwrite (deletes all changes from the file and extracts a new language file) # Upgrade (extracts a new language file and copy's all settings from the old language file) - # Update (adds the default (english) text values for all missing values, just some basic formatting) UpdateMode: Upgrade # Title to be shown for the opened inventory for everyone except the owner of the backpack. Can contain {OwnerName} (which will be replaced with the players name). diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/Files.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/Files.java index 3e67152..200c700 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/Files.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/Files.java @@ -124,10 +124,10 @@ public void loadPlayer(final @NotNull MinepacksPlayerData player) bp = new Backpack(player, backpackFile.getItemStacks()[0]); } if(bp == null) bp = new Backpack(player); - player.setLoaded(file); + player.setLoaded(file, 0); player.setBackpack(bp); } @Override - public void loadBackpack(@NotNull MinepacksPlayerData player) {} // Already loaded with the player + public void loadBackpack(final @NotNull MinepacksPlayerData player) {} // Already loaded with the player } \ No newline at end of file diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQL.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQL.java index 0be54f2..92aca02 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQL.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQL.java @@ -46,7 +46,7 @@ public abstract class SQL extends DatabaseBackend protected String fieldCdPlayer = "id", fieldCdTime = "time"; // Table Fields @Language("SQL") protected String queryUpdatePlayerAdd, queryInsertBp, queryUpdateBp, queryGetPlayer, queryGetBP, queryDeleteOldBackpacks, queryGetUnsetOrInvalidUUIDs, queryFixUUIDs; // DB Querys - @Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys + @Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown; // DB Querys protected boolean syncCooldown; public SQL(@NotNull Minepacks plugin, @NotNull ConnectionProvider connectionProvider) @@ -185,11 +185,12 @@ public Connection getConnection() throws SQLException protected final void buildQueries() { // Build the SQL queries with placeholders for the table and field names - queryGetPlayer = "SELECT * FROM {TablePlayers} WHERE {FieldUUID}=?;"; + queryGetPlayer = "SELECT * FROM {TablePlayers}" + + (syncCooldown ? " LEFT JOIN {TableCooldowns} ON {TablePlayers}.{FieldPlayerID} = {TableCooldowns}.{FieldCDPlayer}" : "") + + " WHERE {FieldUUID}=?;"; queryUpdatePlayerAdd = "INSERT INTO {TablePlayers} ({FieldName},{FieldUUID}) VALUES (?,?) ON DUPLICATE KEY UPDATE {FieldName}=?;"; queryGetBP = "SELECT * FROM {TableBackpacks} WHERE {FieldBPOwner}=?;"; - queryGetCooldown = "SELECT * FROM {TableCooldowns} WHERE {FieldCDPlayer} IN (SELECT {FieldPlayerID} FROM {TablePlayers} WHERE {FieldUUID}=?);"; - querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) SELECT {FieldPlayerID},? FROM {TablePlayers} WHERE {FieldUUID}=? ON DUPLICATE KEY UPDATE {FieldCDTime}=?;"; + querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) VALUE (?,?) ON DUPLICATE KEY UPDATE {FieldCDTime}=?;"; queryDeleteOldCooldowns = "DELETE FROM {TableCooldowns} WHERE {FieldCDTime} player.setLoaded(id)); + long cooldown = 0; + if(syncCooldown) cooldown = rs.getTimestamp(fieldCdPlayer).getTime(); + final long cd = cooldown; + plugin.getServer().getScheduler().runTask(plugin, () -> player.setLoaded(id, cd)); return; } } @@ -349,6 +352,6 @@ public void saveBackpack(final @NotNull Backpack backpack) public void saveCooldown(final @NotNull MinepacksPlayerData player) { final Timestamp ts = new Timestamp(player.getCooldown()); - runStatementAsync(querySyncCooldown, ts, formatUUID(player.getUUID()), ts); + runStatementAsync(querySyncCooldown, player.getDatabaseKey(), ts, ts); } } \ No newline at end of file diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQLite.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQLite.java index c850303..e1343e8 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQLite.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Backend/SQLite.java @@ -57,7 +57,8 @@ protected void loadSettings() fieldBpIts = "itemstacks"; // Set fixed settings useUUIDSeparators = false; - syncCooldown = false; + + tableCooldowns = "minepacks_cooldown"; } @Override @@ -94,6 +95,8 @@ protected void checkDB() stmt.execute("CREATE TABLE IF NOT EXISTS `backpack_players` (`player_id` INT UNSIGNED PRIMARY KEY AUTOINCREMENT, `name` CHAR(16) NOT NULL , `uuid` CHAR(32) UNIQUE);"); stmt.execute("CREATE TABLE IF NOT EXISTS `backpacks` (`owner` INT UNSIGNED PRIMARY KEY, `itemstacks` BLOB, `version` INT DEFAULT 0, `lastupdate` DATE DEFAULT CURRENT_DATE);"); + stmt.execute("CREATE TABLE IF NOT EXISTS `minepacks_cooldown` (`id` INT UNSIGNED PRIMARY KEY, `time` UNSIGNED BIG INT NOT NULL, " + + "CONSTRAINT fk_minepacks_cooldown_minepacks_players FOREIGN KEY (id) REFERENCES backpack_players (player_id) ON DELETE CASCADE ON UPDATE CASCADE);"); DBTools.runStatement(connection, "INSERT OR REPLACE INTO `minepacks_metadata` (`key`, `value`) VALUES ('db_version',?);", plugin.getDescription().getVersion()); } diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/BackupHandler.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/BackupHandler.java index 2626d8f..18e15ee 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/BackupHandler.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/BackupHandler.java @@ -107,7 +107,7 @@ public void writeBackup(@Nullable String userName, @NotNull String userIdentifie } } - public List getBackups() + public @NotNull List getBackups() { File[] files = backupFolder.listFiles((dir, name) -> name.endsWith(Files.EXT)); if(files != null) @@ -120,6 +120,6 @@ public List getBackups() } return backups; } - return new ArrayList<>(); + return new ArrayList<>(0); } } \ No newline at end of file diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java index 98f6120..1a02839 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java @@ -138,7 +138,7 @@ public void backup(@NotNull Backpack backpack) return backupHandler.loadBackup(backupName); } - public List getBackups() + public @NotNull List getBackups() { return backupHandler.getBackups(); } diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MinepacksPlayerData.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MinepacksPlayerData.java index 2a9e43b..215110c 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MinepacksPlayerData.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MinepacksPlayerData.java @@ -79,9 +79,10 @@ public void setBackpack(final @NotNull Backpack backpack) backpackLoadedQueue.forEach(backpackCallback -> backpackCallback.onResult(backpack)); } - public void setLoaded(final @NotNull Object databaseKey) + public void setLoaded(final @NotNull Object databaseKey, final long cooldown) { this.databaseKey = databaseKey; + this.cooldown = cooldown; playerLoadedQueue.forEach(loadedCallback -> loadedCallback.onResult(this)); }