Fix error when using the cooldown sync option

This commit is contained in:
GeorgH93 2019-07-03 19:30:14 +02:00
parent be65d62340
commit 128dc2bee1
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
4 changed files with 11 additions and 17 deletions

View File

@ -53,8 +53,6 @@ FullInventory:
Database:
# Database type. MySQL, SQLite or Files
Type: SQLite
# Turn off if you want to use player ids created from an other plugin. When using shared tables please check the tables selection
UpdatePlayer: true
# Auto database cleanup settings
AutoCleanup:
# Defines the max amount of days backpacks will be stored. -1 to disable auto cleanup
@ -141,7 +139,7 @@ WorldSettings:
Blacklist: []
# Defines how the Blacklist will be enforced
# Options:
# Message = The player will see an message that the usage of the backpack is denied in this world.
# Message = The player will see a message that the usage of the backpack is denied in this world.
# MissingPermission = The player will receive the plugins no permission message.
# NoPlugin = The plugin will not be available at all and act as if it was not installed.
# This also exclude players with permission to bypass the world restriction from using it!

View File

@ -155,11 +155,6 @@ public String getDBFields(String sub, String def)
return getConfig().getString("Database.Tables.Fields." + sub, def);
}
public boolean getUpdatePlayer()
{
return getConfig().getBoolean("Database.UpdatePlayer", true);
}
public boolean getUseUUIDs()
{
return getConfig().getBoolean("Database.UseUUIDs", true);

View File

@ -46,7 +46,7 @@ public abstract class SQL extends Database
protected String fieldPlayerName, fieldPlayerID, fieldPlayerUUID, fieldBpOwner, fieldBpIts, fieldBpVersion, fieldBpLastUpdate, fieldCdPlayer, fieldCdTime; // Table Fields
@Language("SQL") protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBp, queryUpdateBp, queryGetBP, queryDeleteOldBackpacks, queryGetUnsetOrInvalidUUIDs, queryFixUUIDs; // DB Querys
@Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys
protected boolean updatePlayer, syncCooldown;
protected boolean syncCooldown;
public SQL(@NotNull Minepacks plugin, @NotNull ConnectionProvider connectionProvider)
{
@ -57,7 +57,7 @@ public SQL(@NotNull Minepacks plugin, @NotNull ConnectionProvider connectionProv
loadSettings();
buildQuerys();
checkDB();
if(useUUIDs && updatePlayer)
if(useUUIDs)
{
checkUUIDs(); // Check if there are user accounts without UUID
}
@ -103,7 +103,6 @@ protected void loadSettings()
fieldBpLastUpdate = plugin.getConfiguration().getDBFields("Backpack.LastUpdate", "lastUpdate");
fieldCdPlayer = plugin.getConfiguration().getDBFields("Cooldown.Player_ID", "id");
fieldCdTime = plugin.getConfiguration().getDBFields("Cooldown.Time", "time");
updatePlayer = plugin.getConfiguration().getUpdatePlayer();
syncCooldown = plugin.getConfiguration().isCommandCooldownSyncEnabled();
}
@ -194,12 +193,13 @@ protected final void buildQuerys()
{
// Build the SQL querys with placeholders for the table and field names
queryGetBP = "SELECT {FieldBPOwner},{FieldBPITS},{FieldBPVersion} FROM {TableBackpacks} INNER JOIN {TablePlayers} ON {TableBackpacks}.{FieldBPOwner}={TablePlayers}.{FieldPlayerID} WHERE ";
querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) SELECT {FieldPlayerID},? FROM {TablePlayers} WHERE ";
if(useUUIDs)
{
queryUpdatePlayerAdd = "INSERT INTO {TablePlayers} ({FieldName},{FieldUUID}) VALUES (?,?) ON DUPLICATE KEY UPDATE {FieldName}=?;";
queryGetPlayerID = "SELECT {FieldPlayerID} FROM {TablePlayers} WHERE {FieldUUID}=?;";
queryGetBP += "{FieldUUID}=?;";
querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) SELECT {FieldPlayerID},? FROM {TablePlayers} WHERE {FieldUUID}=?;";
querySyncCooldown += "{FieldUUID}";
queryGetCooldown = "SELECT * FROM {TableCooldowns} WHERE {FieldCDPlayer} IN (SELECT {FieldPlayerID} FROM {TablePlayers} WHERE {FieldUUID}=?);";
}
else
@ -207,9 +207,10 @@ protected final void buildQuerys()
queryUpdatePlayerAdd = "INSERT IGNORE INTO {TablePlayers} ({FieldName}) VALUES (?);";
queryGetPlayerID = "SELECT {FieldPlayerID} FROM {TablePlayers} WHERE {FieldName}=?;";
queryGetBP += "{FieldName}=?;";
querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) SELECT {FieldPlayerID},? FROM {TablePlayers} WHERE {FieldName}=?;";
querySyncCooldown = "{FieldName}";
queryGetCooldown = "SELECT * FROM {TableCooldowns} WHERE {FieldCDPlayer} IN (SELECT {FieldPlayerID} FROM {TablePlayers} WHERE {FieldName}=?);";
}
querySyncCooldown += "=? ON DUPLICATE KEY UPDATE {FieldCDTime}=?;";
queryInsertBp = "REPLACE INTO {TableBackpacks} ({FieldBPOwner},{FieldBPITS},{FieldBPVersion}) VALUES (?,?,?);";
queryUpdateBp = "UPDATE {TableBackpacks} SET {FieldBPITS}=?,{FieldBPVersion}=?,{FieldBPLastUpdate}={NOW} WHERE {FieldBPOwner}=?;";
queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')";
@ -273,7 +274,7 @@ protected void runStatement(final String query, final Object... args)
}
catch(SQLException e)
{
System.out.print("Query: " + query);
plugin.getLogger().severe("Query: " + query);
e.printStackTrace();
}
}
@ -386,7 +387,8 @@ protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack>
@Override
public void syncCooldown(Player player, long cooldownTime)
{
runStatementAsync(querySyncCooldown, new Timestamp(cooldownTime), getPlayerNameOrUUID(player));
Timestamp ts = new Timestamp(cooldownTime);
runStatementAsync(querySyncCooldown, ts, getPlayerNameOrUUID(player), ts);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2018 GeorgH93
* Copyright (C) 2019 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
@ -60,7 +60,6 @@ protected void loadSettings()
fieldCdTime = "time";
// Set fixed settings
useUUIDSeparators = false;
updatePlayer = true;
syncCooldown = false;
}