mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-09-28 06:27:27 +02:00
Merge branch 'master' of github.com:AppleDash/SaneEconomy
This commit is contained in:
commit
2ccd25cce4
@ -3,27 +3,25 @@ package org.appledash.saneeconomy;
|
||||
import org.appledash.saneeconomy.economy.EconomyManager;
|
||||
import org.appledash.saneeconomy.economy.logger.TransactionLogger;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Created by appledash on 9/18/16.
|
||||
* Blackjack is best pony.
|
||||
*
|
||||
* This interface represent's SaneEconomy's public API.
|
||||
* Anything not exposed in some way by this interface should be considered unstable, and may change at any time.
|
||||
*/
|
||||
public interface ISaneEconomy {
|
||||
/**
|
||||
* Get the active EconomyManager.
|
||||
* Get the active EconomyManager
|
||||
* @return EconomyManager
|
||||
*/
|
||||
EconomyManager getEconomyManager();
|
||||
|
||||
/**
|
||||
* Check whether transactions should be logged.
|
||||
* @return True if transactions should be logged, false otherwise.
|
||||
* Get the active TransactionLogger
|
||||
* @return TransactionLogger, if there is one. Otherwise, Optional.empty()
|
||||
*/
|
||||
boolean shouldLogTransactions();
|
||||
|
||||
/**
|
||||
* Get the active TransactionLogger.
|
||||
* @return TransactionLogger, if there is one.
|
||||
* @throws IllegalStateException if shouldLogTransactions() is false.
|
||||
*/
|
||||
TransactionLogger getTransactionLogger();
|
||||
Optional<TransactionLogger> getTransactionLogger();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
@ -125,7 +126,7 @@ public class SaneEconomy extends JavaPlugin implements ISaneEconomy {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active EconomyManager.
|
||||
* Get the active EconomyManager
|
||||
* @return EconomyManager
|
||||
*/
|
||||
@Override
|
||||
@ -134,25 +135,12 @@ public class SaneEconomy extends JavaPlugin implements ISaneEconomy {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether transactions should be logged.
|
||||
* @return True if transactions should be logged, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldLogTransactions() {
|
||||
return transactionLogger != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active TransactionLogger.
|
||||
* Get the active TransactionLogger
|
||||
* @return TransactionLogger, if there is one.
|
||||
*/
|
||||
@Override
|
||||
public TransactionLogger getTransactionLogger() {
|
||||
if (!shouldLogTransactions()) {
|
||||
throw new IllegalStateException("TransactionLogger should not be retrieved if we aren't logging transactions!");
|
||||
}
|
||||
|
||||
return transactionLogger;
|
||||
public Optional<TransactionLogger> getTransactionLogger() {
|
||||
return Optional.ofNullable(transactionLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,18 +111,18 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
ecoMan.setBalance(economable, amount);
|
||||
MessageUtils.sendMessage(sender, "Balance for {1} set to {2}.", sTargetPlayer, ecoMan.getCurrency().formatAmount(amount));
|
||||
|
||||
if (saneEconomy.shouldLogTransactions()) {
|
||||
saneEconomy.getTransactionLogger().ifPresent((logger) -> {
|
||||
// FIXME: This is a silly hack to get it to log.
|
||||
if (oldBal > 0.0) {
|
||||
saneEconomy.getTransactionLogger().logTransaction(new Transaction(
|
||||
logger.logTransaction(new Transaction(
|
||||
economable, Economable.CONSOLE, oldBal, TransactionReason.ADMIN_GIVE
|
||||
));
|
||||
}
|
||||
|
||||
saneEconomy.getTransactionLogger().logTransaction(new Transaction(
|
||||
logger.logTransaction(new Transaction(
|
||||
Economable.CONSOLE, economable, amount, TransactionReason.ADMIN_GIVE
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -174,9 +174,7 @@ public class EconomyManager {
|
||||
addBalance(receiver, amount);
|
||||
}
|
||||
|
||||
if (saneEconomy.shouldLogTransactions()) {
|
||||
saneEconomy.getTransactionLogger().logTransaction(transaction);
|
||||
}
|
||||
saneEconomy.getTransactionLogger().ifPresent((logger) -> logger.logTransaction(transaction));
|
||||
|
||||
return new TransactionResult(transaction, getBalance(sender), getBalance(receiver));
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class TransactionLoggerMySQL implements TransactionLogger {
|
||||
|
||||
private void createTables() {
|
||||
try (Connection conn = dbConn.openConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement(String.format("CREATE TABLE IF NOT EXISTS `%s` (`source` VARCHAR(128), `destination` VARCHAR(128), `amount` DECIMAL(18, 2), `reason` VARCHAR(128))", dbConn.getTable("transaction_logs")));
|
||||
PreparedStatement ps = conn.prepareStatement(String.format("CREATE TABLE IF NOT EXISTS `%s` (`source` VARCHAR(128), `destination` VARCHAR(128), `amount` DECIMAL(18, 2), `reason` VARCHAR(128), `logged` TIMESTAMP NOT NULL default CURRENT_TIMESTAMP)", dbConn.getTable("transaction_logs")));
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Failed to create transaction logger tables", e);
|
||||
|
@ -4,6 +4,8 @@ import org.appledash.saneeconomy.ISaneEconomy;
|
||||
import org.appledash.saneeconomy.economy.EconomyManager;
|
||||
import org.appledash.saneeconomy.economy.logger.TransactionLogger;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Created by appledash on 9/18/16.
|
||||
* Blackjack is best pony.
|
||||
@ -15,12 +17,7 @@ public class MockSaneEconomy implements ISaneEconomy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldLogTransactions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionLogger getTransactionLogger() {
|
||||
return null;
|
||||
public Optional<TransactionLogger> getTransactionLogger() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user