mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2024-11-13 04:33:33 +00:00
Add transaction logging classes
This commit is contained in:
parent
bdd8c1fb68
commit
f366a91b36
@ -0,0 +1,37 @@
|
||||
package me.totalfreedom.fossil.economy;
|
||||
|
||||
import me.totalfreedom.economy.CompletedTransaction;
|
||||
import me.totalfreedom.economy.Transaction;
|
||||
import me.totalfreedom.economy.TransactionLogger;
|
||||
import me.totalfreedom.economy.Transactor;
|
||||
|
||||
public class SimpleLoggedTransactor implements Transactor
|
||||
{
|
||||
private final Transactor transactor;
|
||||
private final TransactionLogger transactionLogger;
|
||||
|
||||
public SimpleLoggedTransactor()
|
||||
{
|
||||
this(new SimpleTransactor(), new SimpleTransactionLogger());
|
||||
}
|
||||
|
||||
public SimpleLoggedTransactor(Transactor transactor, TransactionLogger transactionLogger)
|
||||
{
|
||||
this.transactor = transactor;
|
||||
this.transactionLogger = transactionLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletedTransaction handleTransaction(Transaction transaction)
|
||||
{
|
||||
CompletedTransaction completedTransaction = transactor.handleTransaction(transaction);
|
||||
|
||||
transactionLogger.logTransaction(completedTransaction);
|
||||
return completedTransaction;
|
||||
}
|
||||
|
||||
public TransactionLogger getTransactionLogger()
|
||||
{
|
||||
return this.transactionLogger;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package me.totalfreedom.fossil.economy;
|
||||
|
||||
import me.totalfreedom.audience.MutableAudienceForwarder;
|
||||
import me.totalfreedom.economy.*;
|
||||
import me.totalfreedom.utils.FreedomLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class SimpleTransactionLogger implements TransactionLogger
|
||||
{
|
||||
private MutableAudienceForwarder audience = MutableAudienceForwarder.from(FreedomLogger.getLogger("Fossil"), Bukkit.getConsoleSender());
|
||||
|
||||
@Override
|
||||
public void logTransaction(CompletedTransaction completedTransaction)
|
||||
{
|
||||
StringBuilder transactionLoggingStatementBuilder = new StringBuilder();
|
||||
TransactionResult result = completedTransaction.getResult();
|
||||
boolean resultSuccess = result.isSuccessful();
|
||||
String resultMessage = result.getMessage();
|
||||
|
||||
Transaction transaction = completedTransaction.getTransaction();
|
||||
EconomicEntity source = transaction.getSource();
|
||||
EconomicEntity destination = transaction.getDestination();
|
||||
long transactionAmount = transaction.getTransferAmount();
|
||||
|
||||
transactionLoggingStatementBuilder.append(resultSuccess ? "Successful" : "Unsuccessful")
|
||||
.append(" (")
|
||||
.append(resultMessage)
|
||||
.append(") ")
|
||||
.append(" transaction between ")
|
||||
.append(source.getName())
|
||||
.append(" ")
|
||||
.append(destination.getName())
|
||||
.append(" where the volume of currency transferred was ")
|
||||
.append("$")
|
||||
.append(transactionAmount)
|
||||
.append(".");
|
||||
|
||||
Component message = Component.text(transactionLoggingStatementBuilder.toString());
|
||||
|
||||
audience.sendMessage(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package me.totalfreedom.economy;
|
||||
|
||||
public interface TransactionLogger
|
||||
{
|
||||
void logTransaction(CompletedTransaction completedTransaction);
|
||||
}
|
Loading…
Reference in New Issue
Block a user