Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/minevalley/core/api/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import minevalley.core.api.displays.BlockDisplay;
import minevalley.core.api.displays.ItemDisplay;
import minevalley.core.api.displays.TextDisplay;
import minevalley.core.api.economy.BankAccount;
import minevalley.core.api.banking.BankAccount;
import minevalley.core.api.enums.DebugType;
import minevalley.core.api.gui.FillItem;
import minevalley.core.api.gui.InventoryGui;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/minevalley/core/api/CoreProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import minevalley.core.api.displays.BlockDisplay;
import minevalley.core.api.displays.ItemDisplay;
import minevalley.core.api.displays.TextDisplay;
import minevalley.core.api.economy.BankAccount;
import minevalley.core.api.banking.BankAccount;
import minevalley.core.api.enums.DebugType;
import minevalley.core.api.gui.FillItem;
import minevalley.core.api.gui.InventoryGui;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/minevalley/core/api/Registrant.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import minevalley.core.api.corporations.companies.Aktiengesellschaft;
import minevalley.core.api.corporations.companies.Kapitalgesellschaft;
import minevalley.core.api.economy.AccountUser;
import minevalley.core.api.economy.BankAccount;
import minevalley.core.api.banking.AccountUser;
import minevalley.core.api.banking.BankAccount;
import minevalley.core.api.localization.Address;
import minevalley.core.api.mail.Parcel;
import minevalley.core.api.users.OnlineUser;
Expand Down
124 changes: 124 additions & 0 deletions src/main/java/minevalley/core/api/banking/AccountUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package minevalley.core.api.banking;

import minevalley.core.api.Registrant;
import org.jetbrains.annotations.Contract;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Set;

@SuppressWarnings("unused")
public interface AccountUser {

/**
* Gets the registrant of this account user.
*
* @return registrant of this account user
*/
@Nonnull
@Contract(pure = true)
Registrant getRegistrant();

/**
* Gets the bank account this user has access to.
*
* @return bank account this user has access to
*/
@Nonnull
@Contract(pure = true)
BankAccount getBankAccount();

/**
* Gets the maximum payout per day in cents for this user.
*
* @return maximum payout per day in cents, -1 if unlimited
*/
@Contract(pure = true)
int getMaxPayoutPerDayInCents();

/**
* Sets the maximum payout per day in cents for this user.
*
* @param maxPayoutInCents maximum payout per day in cents, -1 for unlimited
* @throws IllegalArgumentException if maxPayoutInCents is less than -1
*/
void setMaxPayoutPerDayInCents(int maxPayoutInCents) throws IllegalArgumentException;

/**
* Gets the remaining daily payout in cents for this user.
*
* @return remaining daily payout in cents
*/
@Contract(pure = true)
int getRemainingDailyPayoutInCents();

/**
* Resets the remaining daily payout to the maximum payout per day.
*/
void resetDailyPayout();

/**
* Checks if this user has a maximum payout per day.
*
* @return true if this user has a maximum payout per day, false if unlimited
*/
@Contract(pure = true)
default boolean hasMaxPayoutPerDay() {
return getMaxPayoutPerDayInCents() != -1;
}

/**
* Gets the permissions of this bank account user.
*
* @return set of permissions of this bank account user
*/
@Nonnull
@Contract(pure = true)
Set<BankAccountUserPermission> getPermissions();

/**
* Checks if this user has the specified permission.
*
* @param permission permission to check for
* @return true if this user has the specified permission, false otherwise
*/
@Contract(value = "null -> true", pure = true)
default boolean hasPermission(@Nullable BankAccountUserPermission permission) {
if (permission == null) return true;
return getPermissions().contains(permission);
}

/**
* Grants the specified permission to this bank account user.
*
* @param permission permission to grant
* @throws IllegalArgumentException if the permission is null
* @throws IllegalStateException if the user already has the permission
*/
void grantPermission(@Nonnull BankAccountUserPermission permission) throws IllegalArgumentException, IllegalStateException;

/**
* Revokes the specified permission from this bank account user.
*
* @param permission permission to revoke
* @throws IllegalArgumentException if the permission is null
* @throws IllegalStateException if the user does not have the permission
*/
void revokePermission(@Nonnull BankAccountUserPermission permission) throws IllegalArgumentException, IllegalStateException;

/**
* Removes this account user from the bank account.
* <p>
* <b>Note:</b> This revoked all access of the user to the bank account.
*/
void remove();

/**
* Permissions that can be granted to bank account users.
*/
enum BankAccountUserPermission {
CREATE_NEW_BANKING_CARDS,
ADD_NEW_USERS,
REMOVE_USERS
}
}
161 changes: 161 additions & 0 deletions src/main/java/minevalley/core/api/banking/BankAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package minevalley.core.api.banking;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import minevalley.core.api.Core;
import minevalley.core.api.Registrant;
import minevalley.core.api.users.User;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Set;
import java.util.function.Consumer;

@SuppressWarnings("unused")
public interface BankAccount {

/**
* Gets the holder of this bank account.
*
* @return holder of this bank account
*/
@Nonnull
@Contract(pure = true)
Registrant getHolder();

/**
* Gets this accounts banking id.
* <b>Note:</b> the IBAN already contains the prefix (DE00/01/02/03)
*
* @return this accounts banking id
*/
@Nonnull
@Contract(pure = true)
String getIban();

/**
* Gets the amount of money in this bank account.
*
* @return amount of money in cents as integer.
*/
@Nonnegative
@Contract(pure = true)
int getAmountInCents();

/**
* Gets a set of all account users associated with this account.
*
* @return set of all account users.
*/
@Nonnull
@Contract(pure = true)
Set<AccountUser> getAccountUsers();

/**
* @param registrant registrant to get account user from
* @return account user that is associated with the given registrant and this bank account, if existing.
*/
@Nullable
@Contract(value = "null -> null", pure = true)
AccountUser getAccountUser(@Nullable Registrant registrant);

/**
* Gets whether the specific user has the permission to use this bank account.
*
* @param user user to check
* @return true, if the specific user has the permission to use this bank account
*/
@Contract(value = "null->false", pure = true)
boolean hasPermission(@Nullable User user);

/**
* Gets the type of this bank account.
*
* @return type of this bank account
*/
@Nonnull
@Contract(pure = true)
AccountType getType();

/**
* Transfers the given amount of money to another bank account.
* <p>
* <b>Note:</b> Always check the transfer result!
*
* @param target account to transfer the money to
* @param accountUser user who initiated the transfer
* @param amountInCents amount of money to transfer in cents
* @param usage a small text that describes the context of the transferal
* @param callback logic that will be executed after the transferal was executed
* @throws IllegalArgumentException if the target, the account user or the callback is null, or the amount in cents are negative
*/
void transfer(@Nonnull BankAccount target, @Nonnull AccountUser accountUser, int amountInCents,
@Nullable String usage, @Nonnull Consumer<TransferResult> callback) throws IllegalArgumentException;

/**
* Transfers the given amount of money to another bank account.
* <p>
* <b>Note:</b> Always check the transfer result!
*
* @param target account to transfer the money to
* @param amountInCents amount of money to transfer in cents
* @param usage a small text that describes the context of the transferal
* @param callback logic that will be executed after the transferal was executed
* @throws IllegalArgumentException if the target, the account user or the callback is null, or the amount in cents are negative
*/
void transfer(@Nonnull BankAccount target, int amountInCents, @Nullable String usage,
@Nonnull Consumer<TransferResult> callback) throws IllegalArgumentException;

/**
* Gets the bank card item of this account.
*
* @return the bank card item as ItemStack
*/
@Nonnull
@Contract(pure = true)
ItemStack getBankCard();

/**
* The type of bank account: Whether it is a main or second account of a player, or the bank account of a company or an association
*/
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
enum AccountType {
USER_MAIN_ACCOUNT("DE00-"),
USER_SECOND_ACCOUNT("DE01-"),
COMPANY_ACCOUNT("DE02-"),
ASSOCIATION_ACCOUNT("DE03-");

private final String prefix;

/**
* Gets the associated account type to the iban
* <p>
* <b>Note:</b> This method neither checks the iban for correctness, nor if there is a bank account associated with it.
*
* @param iban iban to get account type of
* @return account type
* @throws IllegalArgumentException if iban is null, or malformatted
* @see Core#getBankAccount(String)
*/
@Nonnull
@Contract(pure = true)
public static AccountType getAccountType(@Nonnull String iban) throws IllegalArgumentException {
//noinspection ConstantValue
if (iban == null) {
throw new IllegalArgumentException("iban is null");
}
return switch (iban.charAt(3)) {
case '0' -> USER_MAIN_ACCOUNT;
case '1' -> USER_SECOND_ACCOUNT;
case '2' -> COMPANY_ACCOUNT;
case '3' -> ASSOCIATION_ACCOUNT;
default -> throw new IllegalArgumentException("Given string does not match the required iban standard");
};
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/minevalley/core/api/banking/TransferResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package minevalley.core.api.banking;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@SuppressWarnings("unused")
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum TransferResult {
SUCCESS,
NO_PERMISSION,
NOT_ENOUGH_MONEY,
MAX_PAYOUT_EXCEEDED;

public boolean wasSuccessful() {
return this == SUCCESS;
}
}
2 changes: 1 addition & 1 deletion src/main/java/minevalley/core/api/corporations/Group.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package minevalley.core.api.corporations;

import minevalley.core.api.Registrant;
import minevalley.core.api.economy.BankAccount;
import minevalley.core.api.banking.BankAccount;
import minevalley.core.api.users.User;
import org.jetbrains.annotations.Contract;

Expand Down
50 changes: 0 additions & 50 deletions src/main/java/minevalley/core/api/economy/AccountUser.java

This file was deleted.

Loading