diff --git a/SaneEconomyCore/pom.xml b/SaneEconomyCore/pom.xml
index 866f379..643e4a5 100644
--- a/SaneEconomyCore/pom.xml
+++ b/SaneEconomyCore/pom.xml
@@ -9,7 +9,7 @@
0
SaneEconomyCore
- 0.17.1-SNAPSHOT
+ 0.17.2-SNAPSHOT
diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java
index 78f252e..1a7fe17 100644
--- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java
+++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/backend/type/EconomyStorageBackendMySQL.java
@@ -121,13 +121,13 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
this.dbConn.executeAsyncOperation("set_balance_" + economable.getUniqueIdentifier(), (conn) -> {
try {
this.ensureAccountExists(economable, conn);
- conn.prepareStatement("LOCK TABLE " + this.dbConn.getTable(SANEECONOMY_BALANCES) + " WRITE").execute();
+ this.dbConn.lockTable(conn, SANEECONOMY_BALANCES);
PreparedStatement statement = this.dbConn.prepareStatement(conn, String.format("UPDATE `%s` SET balance = ?, last_name = ? WHERE `unique_identifier` = ?", this.dbConn.getTable(SANEECONOMY_BALANCES)));
statement.setString(1, newBalance.toString());
statement.setString(2, economable.getName());
statement.setString(3, economable.getUniqueIdentifier());
statement.executeUpdate();
- conn.prepareStatement("UNLOCK TABLES").execute();
+ this.dbConn.unlockTables(conn);
} catch (Exception e) {
this.balances.put(economable.getUniqueIdentifier(), oldBalance);
throw new RuntimeException("SQL error has occurred.", e);
diff --git a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java
index c7e3736..e0f0ba1 100644
--- a/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java
+++ b/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/database/MySQLConnection.java
@@ -18,10 +18,17 @@ public class MySQLConnection {
public static final int FIVE_SECONDS = 5000;
private final DatabaseCredentials dbCredentials;
private final SaneDatabase saneDatabase;
+ private boolean canLockTables = true;
public MySQLConnection(DatabaseCredentials dbCredentials) {
this.dbCredentials = dbCredentials;
this.saneDatabase = new SaneDatabase(dbCredentials);
+
+ try (Connection conn = this.saneDatabase.getConnection()){
+
+ } catch (SQLException e) {
+ this.canLockTables = false;
+ }
}
public Connection openConnection() {
@@ -49,6 +56,27 @@ public class MySQLConnection {
}
}
+ public void lockTable(Connection conn, String tableName) throws SQLException {
+ if (!this.canLockTables) {
+ return;
+ }
+
+ try {
+ conn.prepareStatement("LOCK TABLE " + this.getTable(tableName) + " WRITE").execute();
+ this.canLockTables = true;
+ } catch (SQLException e) {
+ this.canLockTables = false;
+ }
+ }
+
+ public void unlockTables(Connection conn) throws SQLException {
+ if (!this.canLockTables) {
+ return;
+ }
+
+ conn.prepareStatement("UNLOCK TABLES").execute();
+ }
+
public void executeAsyncOperation(String tag, Consumer callback) {
this.saneDatabase.runDatabaseOperationAsync(tag, () -> this.doExecuteAsyncOperation(1, callback));
}
diff --git a/SaneEconomyCore/src/main/resources/messages.yml b/SaneEconomyCore/src/main/resources/messages.yml
index d726826..de0b01a 100644
--- a/SaneEconomyCore/src/main/resources/messages.yml
+++ b/SaneEconomyCore/src/main/resources/messages.yml
@@ -7,6 +7,9 @@
# The order of placeholders can be changed. Anything after the :, like the '02d' in {1:02d} is a Java String.format specifier. If you don't know what that is, I recommend leaving it as-is.
# IMPORTANT: If your translation has a colon ( : ) character inside of it, you must enclose the entire part after "translation: " in single quotes ( ' ).
# If this file doesn't work for some reason, check your console for errors with "SnakeYAML" included in them.
+####################################################################################################
+########## READ ABOVE IF YOU INTEND TO EDIT THIS FILE, BEFORE ASKING FOR HELP! #####################
+####################################################################################################
messages:
- message: "You don't have permission to check the balance of {1}."
- message: "That player is not online."
diff --git a/SaneEconomyMobKills/pom.xml b/SaneEconomyMobKills/pom.xml
index 15d7502..a05c194 100644
--- a/SaneEconomyMobKills/pom.xml
+++ b/SaneEconomyMobKills/pom.xml
@@ -16,7 +16,7 @@
org.appledash
SaneEconomyCore
- 0.17.1-SNAPSHOT
+ 0.17.2-SNAPSHOT
diff --git a/SaneEconomyOnlineTime/pom.xml b/SaneEconomyOnlineTime/pom.xml
index 40bbb9f..fb4b485 100644
--- a/SaneEconomyOnlineTime/pom.xml
+++ b/SaneEconomyOnlineTime/pom.xml
@@ -17,7 +17,7 @@
org.appledash
SaneEconomyCore
- 0.17.1-SNAPSHOT
+ 0.17.2-SNAPSHOT
diff --git a/SaneEconomySignShop/pom.xml b/SaneEconomySignShop/pom.xml
index aef295c..436ebd9 100644
--- a/SaneEconomySignShop/pom.xml
+++ b/SaneEconomySignShop/pom.xml
@@ -16,7 +16,7 @@
org.appledash
SaneEconomyCore
- 0.17.1-SNAPSHOT
+ 0.17.2-SNAPSHOT