Skip to content

Commit e722729

Browse files
committed
Added canDeposit, canWithdraw, and canHold methods
Enhanced `Bank` and `Account` APIs with balance operation checks. Implemented default behaviors and updated wrappers to align with the new methods for consistent validation logic.
1 parent 8bebc8d commit e722729

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

plugin/src/main/java/net/thenextlvl/service/wrapper/service/model/WrappedAccount.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public BigDecimal setBalance(Number balance, Currency currency) {
5959
else if (difference < 0) return withdraw(-difference, currency);
6060
return BigDecimal.ZERO;
6161
}
62+
63+
@Override
64+
public boolean canHold(Currency currency) {
65+
return true;
66+
}
6267
}

plugin/src/main/java/net/thenextlvl/service/wrapper/service/model/WrappedBank.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public BigDecimal setBalance(Number balance, Currency currency) {
6969
return current;
7070
}
7171

72+
@Override
73+
public boolean canHold(Currency currency) {
74+
return false;
75+
}
76+
7277
@Override
7378
public @Unmodifiable Set<UUID> getMembers() {
7479
return Arrays.stream(plugin.getServer().getOfflinePlayers())
@@ -101,4 +106,24 @@ public boolean removeMember(UUID uuid) {
101106
public boolean setOwner(UUID uuid) {
102107
return false;
103108
}
109+
110+
@Override
111+
public boolean canDeposit(OfflinePlayer player, Number amount, Currency currency) {
112+
return economy.isBankOwner(getName(), player).transactionSuccess();
113+
}
114+
115+
@Override
116+
public boolean canDeposit(UUID uuid, Number amount, Currency currency) {
117+
return canDeposit(plugin.getServer().getOfflinePlayer(uuid), amount, currency);
118+
}
119+
120+
@Override
121+
public boolean canWithdraw(OfflinePlayer player, Number amount, Currency currency) {
122+
return economy.isBankOwner(getName(), player).transactionSuccess();
123+
}
124+
125+
@Override
126+
public boolean canWithdraw(UUID uuid, Number amount, Currency currency) {
127+
return canWithdraw(plugin.getServer().getOfflinePlayer(uuid), amount, currency);
128+
}
104129
}

src/main/java/net/thenextlvl/service/api/economy/Account.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,12 @@ default int compareTo(Account account, Currency currency) {
9191
* @since 3.0.0
9292
*/
9393
BigDecimal setBalance(Number balance, Currency currency);
94+
95+
/**
96+
* Checks if the account can hold the specified currency.
97+
*
98+
* @param currency the currency to check support for
99+
* @return {@code true} if the account can hold the specified currency, otherwise {@code false}
100+
*/
101+
boolean canHold(Currency currency);
94102
}

src/main/java/net/thenextlvl/service/api/economy/bank/Bank.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,56 @@ default boolean setOwner(OfflinePlayer player) {
109109
* @return {@code true} if the owner was successfully set, otherwise {@code false}
110110
*/
111111
boolean setOwner(UUID uuid);
112+
113+
/**
114+
* Checks whether the specified player can deposit the specified amount in the given currency.
115+
* <p>
116+
* Returns {@code false} if {@link #canHold(Currency)} returns {@code false}
117+
*
118+
* @param player the player attempting to make the deposit
119+
* @param amount the amount being attempted to deposit
120+
* @param currency the currency of the deposit
121+
* @return {@code true} if the player can deposit the specified amount, otherwise {@code false}
122+
*/
123+
default boolean canDeposit(OfflinePlayer player, Number amount, Currency currency) {
124+
return canDeposit(player.getUniqueId(), amount, currency);
125+
}
126+
127+
/**
128+
* Checks whether the specified uuid can deposit the specified amount in the given currency.
129+
* <p>
130+
* Returns {@code false} if {@link #canHold(Currency)} returns {@code false}
131+
*
132+
* @param uuid the uuid of the player attempting to make the deposit
133+
* @param amount the amount being attempted to deposit
134+
* @param currency the currency of the deposit
135+
* @return {@code true} if the player can deposit the specified amount, otherwise {@code false}
136+
*/
137+
boolean canDeposit(UUID uuid, Number amount, Currency currency);
138+
139+
/**
140+
* Checks whether the specified player can withdraw the specified amount in the given currency.
141+
* <p>
142+
* Returns {@code false} if {@link #canHold(Currency)} returns {@code false}
143+
*
144+
* @param player the player attempting to make the withdrawal
145+
* @param amount the amount being attempted to withdraw
146+
* @param currency the currency of the withdrawal
147+
* @return {@code true} if the player can withdraw the specified amount, otherwise {@code false}
148+
*/
149+
default boolean canWithdraw(OfflinePlayer player, Number amount, Currency currency) {
150+
return canWithdraw(player.getUniqueId(), amount, currency);
151+
}
152+
153+
/**
154+
* Checks whether the specified uuid can withdraw the specified amount in the given currency.
155+
* <p>
156+
* Returns {@code false} if {@link #canHold(Currency)} returns {@code false}
157+
*
158+
* @param uuid the UUID of the player attempting to make the withdrawal
159+
* @param amount the amount being attempted to withdraw
160+
* @param currency the currency of the withdrawal
161+
* @return {@code true} if the player can withdraw the specified amount, otherwise {@code false}
162+
*/
163+
boolean canWithdraw(UUID uuid, Number amount, Currency currency);
112164
}

0 commit comments

Comments
 (0)