Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter Account & Transaction and fix TownyTransactionEvent. #7431

Merged
merged 4 commits into from
Jul 12, 2024

Conversation

LlmDl
Copy link
Member

@LlmDl LlmDl commented May 22, 2024

Description:

Deprecates the original Transaction and creates a new Transaction class in its own package within the object.economy package.

The new Transaction uses a amount, TransactionType and two accounts (sender and receiver.) Transactions are made using a factory pattern which makes it clearer who is paying and who is being paid. This builder can create Transactions as well as TownyTransactionEvents (for which Transactions are usually being used.)

Additionally, this PR makes it so that TownyTransactionEvents are thrown much more frequently, rather than only under very limited circumstances.

Additionally, this PR adds an EconomyHandler to the Account class, reducing the importance of an Account's Name field.

Additionally, this PR alters the TownyServerAccount to now also implement EconomyHandler so that it can behave correctly with the new Account change.

Should make things easier to switch from our use of Account.getName()to Account.getUUID() when #7425 is ready to merge.

Post Testing, found the following plugins require updating:

  • EventWar
  • FlagWar

New Nodes/Commands/ConfigOptions:


Relevant Towny Issue ticket:


  • I have tested this pull request for defects on a server.

By making this pull request, I represent that I have the right to waive copyright and related rights to my contribution, and agree that all copyright and related rights in my contributions are waived, and I acknowledge that the TownyAdvanced organization has the copyright to use and modify my contribution under the Towny License for perpetuity.

@LlmDl LlmDl added this to the 0.100.3.0 milestone May 22, 2024
@LlmDl LlmDl changed the title Fix the TownyTransactionEvent assuming a player is involved. Alter Transaction and fix TownyTransactionEvent. May 22, 2024
@LlmDl LlmDl changed the title Alter Transaction and fix TownyTransactionEvent. Alter Account & Transaction and fix TownyTransactionEvent. May 30, 2024
@LlmDl LlmDl marked this pull request as ready for review May 30, 2024 16:00
@LlmDl LlmDl requested a review from Warriorrrr May 30, 2024 16:00
@LlmDl LlmDl modified the milestones: 0.100.3.0, 0.100.4.0 Jun 1, 2024
@LlmDl LlmDl force-pushed the fix/TownyTransactionEvent branch from d4c9ca8 to bfc77f7 Compare June 3, 2024 16:55
LlmDl added 2 commits June 3, 2024 11:56
Alters Transactions to no longer use a Player and instead try to use a
TownyObject.
Rethink Transaction to adopt a Account instead of a TownyObject and
Name.
Fix javadoc
Fix Account initializing TownyObject null.
Add helper method to Transaction.
Clean up EconomyAccount, move the TownyServerAccount instance to
Account.
Alter Transaction again in order to add both Receiving and Sending
accounts.
Remove getName/getTownyObject from Transaction, change TownyObject in
Account over to EconomyHandler. Return government field to BankAccount.
Throw the TownyTransactionEvent earlier, so that we can better support
the new sender and receiver fields in the Transaction.
Fix flipped sender/receiver.
Notify observers of payTo/payFromServer only when the transaction is a
success.
A very hacky way to get the TownyServerAccount to implement
EconomyHandler.
Change transaction package, adopt new builder pattern, deprecate
existing Transaction and TransactionType classes.
Reduce diff and a couple better javadocs
annotations and helper methods to Transaction.
Comment on lines +15 to +20
public Transaction(TransactionBuilder builder) {
this.type = builder.type;
this.receivingAccount = builder.receivingAccount;
this.sendingAccount = builder.sendingAccount;
this.amount = builder.amount;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this a normal constructor instead of requiring the use of the builder

Suggested change
public Transaction(TransactionBuilder builder) {
this.type = builder.type;
this.receivingAccount = builder.receivingAccount;
this.sendingAccount = builder.sendingAccount;
this.amount = builder.amount;
}
@Contract("_, null, null, _ -> fail")
public Transaction(@NotNull TransactionType type, Account receivingAccount, Account sendingAccount, double amount) {
Preconditions.checkNotNull(type, "type");
Preconditions.checkState(receivingAccount != null || sendingAccount != null, "receivingAccount and sendingAccount cannot both be null");
Preconditions.checkState(amount > 0, "amount must be greater than 0");
this.type = type;
this.receivingAccount = receivingAccount;
this.sendingAccount = sendingAccount;
this.amount = amount;
}

@LlmDl LlmDl merged commit 46ee594 into master Jul 12, 2024
4 checks passed
@LlmDl LlmDl deleted the fix/TownyTransactionEvent branch July 12, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants