Skip to content

Commit

Permalink
Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Jun 29, 2023
1 parent 9123233 commit 8259fd2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class Database implements Listener
protected boolean useUUIDSeparators, asyncSave = true;
protected long maxAge;
private final Map<UUID, Backpack> backpacks = new ConcurrentHashMap<>();
private final UnCacheStrategy unCacheStrategie;
private final UnCacheStrategy unCacheStrategy;
private final File backupFolder;

public Database(Minepacks mp)
Expand All @@ -63,7 +63,7 @@ public Database(Minepacks mp)
bungeeCordMode = plugin.getConfiguration().isBungeeCordModeEnabled();
forceSaveOnUnload = plugin.getConfiguration().isForceSaveOnUnloadEnabled();
maxAge = plugin.getConfiguration().getAutoCleanupMaxInactiveDays();
unCacheStrategie = bungeeCordMode ? new OnDisconnect(this) : UnCacheStrategy.getUnCacheStrategie(this);
unCacheStrategy = bungeeCordMode ? new OnDisconnect(this) : UnCacheStrategy.getUnCacheStrategy(this);
backupFolder = new File(this.plugin.getDataFolder(), "backups");
if(!backupFolder.exists() && !backupFolder.mkdirs()) mp.getLogger().info("Failed to create backups folder.");
}
Expand All @@ -79,7 +79,7 @@ public void close()
asyncSave = false;
backpacks.forEach((key, value) -> { if (forceSaveOnUnload) { value.setChanged(); } value.closeAll(); });
backpacks.clear();
unCacheStrategie.close();
unCacheStrategy.close();
}

public static @Nullable Database getDatabase(Minepacks plugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package at.pcgamingfreaks.Minepacks.Bukkit.Database;
Expand All @@ -35,7 +35,7 @@ public MySQL(@NotNull Minepacks plugin, @Nullable ConnectionProvider connectionP
}

@Override
protected void updateQuerysForDialect()
protected void updateQueriesForDialect()
{
queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} + INTERVAL {VarMaxAge} day < NOW()";
queryUpdateBp = queryUpdateBp.replaceAll("\\{NOW}", "NOW()");
Expand Down
21 changes: 11 additions & 10 deletions Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2023 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package at.pcgamingfreaks.Minepacks.Bukkit.Database;
Expand All @@ -23,6 +23,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Utils;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
Expand All @@ -38,8 +39,8 @@ public abstract class SQL extends Database

protected String tablePlayers, tableBackpacks, tableCooldowns; // Table Names
protected String fieldPlayerName, fieldPlayerID, fieldPlayerUUID, fieldBpOwner, fieldBpIts, fieldBpVersion, fieldBpLastUpdate, fieldCdPlayer, fieldCdTime; // Table Fields
@Language("SQL") protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBp, queryUpdateBp, queryGetBP, queryDeleteOldBackpacks; // DB Querys
@Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys
@Language("SQL") protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBp, queryUpdateBp, queryGetBP, queryDeleteOldBackpacks; // DB Queries
@Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Queries
protected boolean syncCooldown;

public SQL(@NotNull Minepacks plugin, @NotNull ConnectionProvider connectionProvider)
Expand All @@ -50,7 +51,7 @@ public SQL(@NotNull Minepacks plugin, @NotNull ConnectionProvider connectionProv
if(!dataSource.isAvailable()) throw new IllegalStateException("Failed to initialize database connection!");

loadSettings();
buildQuerys();
buildQueries();
checkDB();
checkUUIDs(); // Check if there are user accounts without UUID

Expand Down Expand Up @@ -125,9 +126,9 @@ public Connection getConnection() throws SQLException

protected abstract void checkDB();

protected final void buildQuerys()
protected final void buildQueries()
{
// Build the SQL querys with placeholders for the table and field names
// Build the SQL queries with placeholders for the table and field names
queryGetBP = "SELECT {FieldBPOwner},{FieldBPITS},{FieldBPVersion} FROM {TableBackpacks} INNER JOIN {TablePlayers} ON {TableBackpacks}.{FieldBPOwner}={TablePlayers}.{FieldPlayerID} WHERE {FieldUUID}=?;";
querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) SELECT {FieldPlayerID},? FROM {TablePlayers} WHERE {FieldUUID}=? ON DUPLICATE KEY UPDATE {FieldCDTime}=?;";
queryUpdatePlayerAdd = "INSERT INTO {TablePlayers} ({FieldName},{FieldUUID}) VALUES (?,?) ON DUPLICATE KEY UPDATE {FieldName}=?;";
Expand All @@ -138,7 +139,7 @@ protected final void buildQuerys()
queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')";
queryDeleteOldCooldowns = "DELETE FROM {TableCooldowns} WHERE {FieldCDTime}<?;";

updateQuerysForDialect();
updateQueriesForDialect();

setTableAndFieldNames();
}
Expand All @@ -151,13 +152,13 @@ protected void setTableAndFieldNames()
queryGetBP = replacePlaceholders(queryGetBP);
queryInsertBp = replacePlaceholders(queryInsertBp);
queryUpdateBp = replacePlaceholders(queryUpdateBp);
queryDeleteOldBackpacks = replacePlaceholders(queryDeleteOldBackpacks.replaceAll("\\{VarMaxAge}", maxAge + ""));
queryDeleteOldBackpacks = replacePlaceholders(queryDeleteOldBackpacks.replace("{VarMaxAge}", String.valueOf(maxAge)));
querySyncCooldown = replacePlaceholders(querySyncCooldown);
queryGetCooldown = replacePlaceholders(queryGetCooldown);
queryDeleteOldCooldowns = replacePlaceholders(queryDeleteOldCooldowns);
}

protected abstract void updateQuerysForDialect();
protected abstract void updateQueriesForDialect();

protected String replacePlaceholders(@Language("SQL") String query)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2023 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package at.pcgamingfreaks.Minepacks.Bukkit.Database;
Expand Down Expand Up @@ -69,7 +69,7 @@ protected void loadSettings()
}

@Override
protected void updateQuerysForDialect()
protected void updateQueriesForDialect()
{
queryInsertBp = queryInsertBp.replaceAll("\\) VALUES \\(\\?,\\?,\\?", ",{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')");
queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies;
Expand All @@ -29,13 +29,13 @@ public UnCacheStrategy(Database cache)
this.cache = cache;
}

public static UnCacheStrategy getUnCacheStrategie(Database cache)
public static UnCacheStrategy getUnCacheStrategy(Database cache)
{
switch(Minepacks.getInstance().getConfiguration().getUnCacheStrategy())
{
case "ondisconnect": return new OnDisconnect(cache);
case "ondisconnectdelayed": return new OnDisconnectDelayed(cache);
case "intervalChecked": return new IntervalChecked(cache);
case "intervalchecked": return new IntervalChecked(cache);
case "interval": default: return new Interval(cache);
}
}
Expand Down

0 comments on commit 8259fd2

Please sign in to comment.