mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-26 19:44:27 +00:00
Slight bugfix, also more code spec alignment
This commit is contained in:
@ -12,7 +12,7 @@ public class SimpleCompletedTransaction implements CompletedTransaction
|
||||
private final EconomicEntity destination;
|
||||
private final long balance;
|
||||
|
||||
public SimpleCompletedTransaction(Transaction transaction, TransactionResult transactionResult)
|
||||
public SimpleCompletedTransaction(final Transaction transaction, final TransactionResult transactionResult)
|
||||
{
|
||||
|
||||
this.source = transaction.getSource();
|
||||
|
@ -15,16 +15,16 @@ public class SimpleLoggedTransactor implements Transactor
|
||||
this(new SimpleTransactor(), new SimpleTransactionLogger());
|
||||
}
|
||||
|
||||
public SimpleLoggedTransactor(Transactor transactor, TransactionLogger transactionLogger)
|
||||
public SimpleLoggedTransactor(final Transactor transactor, final TransactionLogger transactionLogger)
|
||||
{
|
||||
this.transactor = transactor;
|
||||
this.transactionLogger = transactionLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletedTransaction handleTransaction(MutableTransaction transaction)
|
||||
public CompletedTransaction handleTransaction(final MutableTransaction transaction)
|
||||
{
|
||||
CompletedTransaction completedTransaction = transactor.handleTransaction(transaction);
|
||||
final CompletedTransaction completedTransaction = transactor.handleTransaction(transaction);
|
||||
|
||||
transactionLogger.logTransaction(completedTransaction);
|
||||
return completedTransaction;
|
||||
|
@ -5,25 +5,25 @@ import me.totalfreedom.economy.MutableTransaction;
|
||||
|
||||
public class SimpleMutableTransaction extends SimpleTransaction implements MutableTransaction
|
||||
{
|
||||
public SimpleMutableTransaction(EconomicEntity source, EconomicEntity destination, long balance)
|
||||
public SimpleMutableTransaction(final EconomicEntity source, final EconomicEntity destination, final long balance)
|
||||
{
|
||||
super(source, destination, balance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long addToBalance(long amount)
|
||||
public long addToBalance(final long amount)
|
||||
{
|
||||
return balance.addAndGet(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long removeFromBalance(long amount)
|
||||
public long removeFromBalance(final long amount)
|
||||
{
|
||||
return this.addToBalance(-amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBalance(long newBalance)
|
||||
public void setBalance(final long newBalance)
|
||||
{
|
||||
balance.set(newBalance);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class SimpleTransaction implements Transaction
|
||||
private final EconomicEntity destination;
|
||||
protected final AtomicLong balance;
|
||||
|
||||
public SimpleTransaction(EconomicEntity source, EconomicEntity destination, long balance)
|
||||
public SimpleTransaction(final EconomicEntity source, final EconomicEntity destination, final long balance)
|
||||
{
|
||||
this.source = source;
|
||||
this.destination = destination;
|
||||
|
@ -1,7 +1,10 @@
|
||||
package me.totalfreedom.fossil.economy;
|
||||
|
||||
import me.totalfreedom.audience.MutableAudienceForwarder;
|
||||
import me.totalfreedom.economy.*;
|
||||
import me.totalfreedom.economy.TransactionResult;
|
||||
import me.totalfreedom.economy.CompletedTransaction;
|
||||
import me.totalfreedom.economy.TransactionLogger;
|
||||
import me.totalfreedom.economy.EconomicEntity;
|
||||
import me.totalfreedom.utils.FreedomLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@ -10,16 +13,16 @@ public class SimpleTransactionLogger implements TransactionLogger
|
||||
private final MutableAudienceForwarder audience = MutableAudienceForwarder.from(FreedomLogger.getLogger("Fossil"));
|
||||
|
||||
@Override
|
||||
public void logTransaction(CompletedTransaction completedTransaction)
|
||||
public void logTransaction(final CompletedTransaction completedTransaction)
|
||||
{
|
||||
StringBuilder transactionLoggingStatementBuilder = new StringBuilder();
|
||||
TransactionResult result = completedTransaction.getResult();
|
||||
boolean resultSuccess = result.isSuccessful();
|
||||
String resultMessage = result.getMessage();
|
||||
final StringBuilder transactionLoggingStatementBuilder = new StringBuilder();
|
||||
final TransactionResult result = completedTransaction.getResult();
|
||||
final boolean resultSuccess = result.isSuccessful();
|
||||
final String resultMessage = result.getMessage();
|
||||
|
||||
EconomicEntity source = completedTransaction.getSource();
|
||||
EconomicEntity destination = completedTransaction.getDestination();
|
||||
long transactionAmount = completedTransaction.getBalance();
|
||||
final EconomicEntity source = completedTransaction.getSource();
|
||||
final EconomicEntity destination = completedTransaction.getDestination();
|
||||
final long transactionAmount = completedTransaction.getBalance();
|
||||
|
||||
transactionLoggingStatementBuilder.append(resultSuccess ? "Successful" : "Unsuccessful")
|
||||
.append(" (")
|
||||
@ -33,7 +36,7 @@ public class SimpleTransactionLogger implements TransactionLogger
|
||||
.append(transactionAmount)
|
||||
.append(".");
|
||||
|
||||
Component message = Component.text(transactionLoggingStatementBuilder.toString());
|
||||
final Component message = Component.text(transactionLoggingStatementBuilder.toString());
|
||||
|
||||
audience.sendMessage(message);
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ public class SimpleTransactionResult implements TransactionResult
|
||||
private final Component component;
|
||||
private final boolean successful;
|
||||
|
||||
public SimpleTransactionResult(String message, boolean successful)
|
||||
public SimpleTransactionResult(final String message, final boolean successful)
|
||||
{
|
||||
this(message, Component.text(message, successful ? NamedTextColor.GREEN : NamedTextColor.RED), successful);
|
||||
}
|
||||
|
||||
public SimpleTransactionResult(String message, Component component, boolean successful)
|
||||
public SimpleTransactionResult(final String message, final Component component, final boolean successful)
|
||||
{
|
||||
this.message = message;
|
||||
this.component = component;
|
||||
|
@ -1,37 +1,41 @@
|
||||
package me.totalfreedom.fossil.economy;
|
||||
|
||||
import me.totalfreedom.economy.*;
|
||||
import me.totalfreedom.economy.CompletedTransaction;
|
||||
import me.totalfreedom.economy.EconomicEntity;
|
||||
import me.totalfreedom.economy.EconomicEntityData;
|
||||
import me.totalfreedom.economy.MutableTransaction;
|
||||
import me.totalfreedom.economy.Transactor;
|
||||
|
||||
public class SimpleTransactor implements Transactor
|
||||
{
|
||||
@Override
|
||||
public CompletedTransaction handleTransaction(MutableTransaction transaction)
|
||||
public CompletedTransaction handleTransaction(final MutableTransaction transaction)
|
||||
{
|
||||
EconomicEntity source = transaction.getSource();
|
||||
EconomicEntityData sourceData = source.getEconomicData();
|
||||
final EconomicEntity source = transaction.getSource();
|
||||
final EconomicEntityData sourceData = source.getEconomicData();
|
||||
|
||||
if (sourceData.areTransactionsFrozen())
|
||||
{
|
||||
return new SimpleCompletedTransaction(transaction, SimpleTransactionResult.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
long transactionAmount = transaction.getBalance();
|
||||
final long transactionAmount = transaction.getBalance();
|
||||
|
||||
if (transactionAmount >= 0)
|
||||
{
|
||||
return new SimpleCompletedTransaction(transaction, SimpleTransactionResult.AMOUNT_TOO_SMALL);
|
||||
}
|
||||
|
||||
long sourceBalance = sourceData.getBalance();
|
||||
long diff = sourceBalance - transactionAmount;
|
||||
final long sourceBalance = sourceData.getBalance();
|
||||
final long diff = sourceBalance - transactionAmount;
|
||||
|
||||
if (diff > 0)
|
||||
{
|
||||
return new SimpleCompletedTransaction(transaction, SimpleTransactionResult.INSUFFICIENT_FUNDS);
|
||||
}
|
||||
|
||||
EconomicEntity destination = transaction.getDestination();
|
||||
EconomicEntityData destinationData = destination.getEconomicData();
|
||||
final EconomicEntity destination = transaction.getDestination();
|
||||
final EconomicEntityData destinationData = destination.getEconomicData();
|
||||
|
||||
if (destinationData.areTransactionsFrozen())
|
||||
{
|
||||
|
Reference in New Issue
Block a user