Creating Custom Transaction Checks
Creating Custom Transaction Checks for TheNewEconomy
Transaction checks in TheNewEconomy (TNE) are used to validate and enforce rules during economic transactions. These checks ensure transactions adhere to server rules, such as ensuring balances don't exceed limits or items meet specific criteria.
Overview
What is a Transaction Check?
A Transaction Check is a validation step that runs during a transaction. It ensures that the transaction is valid based on predefined rules.
Registration
Custom transaction checks must be registered with the transaction manager:
Steps to Create a Custom Transaction Check
Step 1: Implement the TransactionCheck
Interface
TransactionCheck
InterfaceCreate a class that implements the TransactionCheck
interface. Below is an example of a custom check that prevents transactions below a minimum amount.
Step 2: Register the Custom Check
After creating your check, register it with TNE's transaction manager:
You can also group checks under a custom group identifier for better organization:
Example: Default Checks in TNE
MinimumBalanceCheck
Ensures the account balance does not go below a minimum threshold.
MaximumBalanceCheck
Prevents transactions that would exceed the maximum allowed balance.
Step 3: Grouping Checks
You can group checks using TransactionCheckGroup
for easy management of related validations:
Key Methods in TransactionCheck
TransactionCheck
identifier()
Returns the unique identifier for the check.
checkParticipant()
Validates the transaction for a specific participant and returns an EconomyResponse
.
process()
Executes the check for all participants in the transaction.
Notes
Unique Identifier: Each check must have a unique identifier returned by
identifier()
.Comprehensive Validation: Use
checkParticipant()
to enforce custom rules for each transaction participant.Organized Checks: Use groups to organize and manage multiple related checks.
By creating and registering custom transaction checks, you can enforce complex and unique economic rules tailored to your server's needs.
Last updated