mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-26 20:16:18 +01:00
Transaction logging seems to work, kind of.
This commit is contained in:
parent
92350e6d25
commit
d1b302e779
@ -142,9 +142,9 @@ public class EconomyManager {
|
||||
|
||||
if (saneEconomy.shouldLogTransactions() && reason != TransactionReason.PLAYER_PAY) { // Player pay is handled in the transfer() method.
|
||||
if (oldAmount > amount) { // Lower amount now
|
||||
saneEconomy.getTransactionLogger().logSubtraction(targetPlayer, amount, reason);
|
||||
saneEconomy.getTransactionLogger().logSubtraction(targetPlayer, oldAmount - amount, reason);
|
||||
} else if (oldAmount < amount) { // Higher amount now
|
||||
saneEconomy.getTransactionLogger().logAddition(targetPlayer, amount, reason);
|
||||
saneEconomy.getTransactionLogger().logAddition(targetPlayer, amount - oldAmount, reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.appledash.saneeconomy.economy.economable.Economable;
|
||||
import org.appledash.saneeconomy.utils.DatabaseCredentials;
|
||||
import org.appledash.saneeconomy.utils.MySQLConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@ -41,6 +42,7 @@ public class TransactionLoggerMySQL implements TransactionLogger {
|
||||
ps.setString(1, from);
|
||||
ps.setString(2, to);
|
||||
ps.setDouble(3, change);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Error occurred logging addition", e);
|
||||
}
|
||||
@ -48,6 +50,20 @@ public class TransactionLoggerMySQL implements TransactionLogger {
|
||||
}
|
||||
|
||||
public boolean testConnection() {
|
||||
return dbConn.testConnection();
|
||||
if (dbConn.testConnection()) {
|
||||
createTables();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void createTables() {
|
||||
try (Connection conn = dbConn.openConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("CREATE TABLE IF NOT EXISTS `transaction_logs` (`source` VARCHAR(128), `destination` VARCHAR(128), `amount` DECIMAL(18, 2))");
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Failed to create transaction logger tables", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,11 @@ public class SaneEconomyConfiguration {
|
||||
|
||||
logger.info("Attempting to load transaction logger...");
|
||||
|
||||
if (rootConfig.getConfigurationSection("logger-database") == null) {
|
||||
logger.severe("No transaction logger database defined, cannot possibly connect!");
|
||||
return null;
|
||||
}
|
||||
|
||||
DatabaseCredentials credentials = loadCredentials(rootConfig.getConfigurationSection("logger-database"));
|
||||
|
||||
TransactionLoggerMySQL transactionLoggerMySQL = new TransactionLoggerMySQL(credentials);
|
||||
|
Loading…
Reference in New Issue
Block a user