Skip to content

Commit ffd4fe6

Browse files
committed
Added hasBank methods and improved Currency linkage
Expanded `BankController` with multiple `hasBank` overloads for better account-checking flexibility. Updated `Currency` to include `getHolder`, improving association tracking. Adjusted wrappers to align with these changes.
1 parent cf2a278 commit ffd4fe6

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

plugin/src/main/java/net/thenextlvl/service/wrapper/service/BankServiceWrapper.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,30 @@ public CompletableFuture<Boolean> deleteBank(UUID uuid, @Nullable World world) {
8383

8484
@Override
8585
public Optional<Bank> getBank(String name) {
86+
if (!economy.getBanks().contains(name)) return Optional.empty();
8687
return Optional.of(new WrappedBank(this, name, null, economy, provider));
8788
}
8889

90+
@Override
91+
public Optional<Bank> getBank(OfflinePlayer player, @Nullable World world) {
92+
return economy.getBanks().stream().filter(bank ->
93+
economy.isBankOwner(bank, player).transactionSuccess()
94+
).findAny().flatMap(this::getBank);
95+
}
96+
8997
@Override
9098
public Optional<Bank> getBank(UUID uuid, @Nullable World world) {
91-
return Optional.empty();
99+
return getBank(plugin.getServer().getOfflinePlayer(uuid), world);
100+
}
101+
102+
@Override
103+
public boolean hasBank(OfflinePlayer player, @Nullable World world) {
104+
return economy.getBanks().stream().anyMatch(bank -> economy.isBankOwner(bank, player).transactionSuccess());
105+
}
106+
107+
@Override
108+
public boolean hasBank(UUID uuid, @Nullable World world) {
109+
return hasBank(plugin.getServer().getOfflinePlayer(uuid), world);
92110
}
93111

94112
@Override

plugin/src/main/java/net/thenextlvl/service/wrapper/service/EconomyServiceWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private static class WrappedCurrencyHolder implements CurrencyHolder {
110110
private final Currency currency;
111111

112112
private WrappedCurrencyHolder(Economy economy) {
113-
this.currency = new WrappedCurrency(economy);
113+
this.currency = new WrappedCurrency(this, economy);
114114
}
115115

116116
@Override

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.kyori.adventure.text.Component;
44
import net.milkbowl.vault.economy.Economy;
55
import net.thenextlvl.service.api.economy.currency.Currency;
6+
import net.thenextlvl.service.api.economy.currency.CurrencyHolder;
67
import org.jetbrains.annotations.Unmodifiable;
78
import org.jspecify.annotations.NullMarked;
89
import org.jspecify.annotations.Nullable;
@@ -15,10 +16,17 @@
1516

1617
@NullMarked
1718
public class WrappedCurrency implements Currency {
19+
private final CurrencyHolder holder;
1820
private final Economy economy;
1921

20-
public WrappedCurrency(Economy economy) {
22+
public WrappedCurrency(CurrencyHolder holder, Economy economy) {
2123
this.economy = economy;
24+
this.holder = holder;
25+
}
26+
27+
@Override
28+
public CurrencyHolder getHolder() {
29+
return holder;
2230
}
2331

2432
@Override

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface BankController extends Controller {
2828
*/
2929
@Contract(pure = true)
3030
CurrencyHolder getCurrencyHolder();
31-
31+
3232
/**
3333
* Creates a bank for the specified player with the given name.
3434
* <p>
@@ -335,6 +335,46 @@ default Optional<Bank> getBank(UUID uuid) {
335335
*/
336336
Optional<Bank> getBank(UUID uuid, @Nullable World world);
337337

338+
/**
339+
* Checks if the specified player has a bank account.
340+
*
341+
* @param player the player to check for an associated bank account
342+
* @return {@code true} if the player has a bank account, otherwise {@code false}
343+
*/
344+
default boolean hasBank(OfflinePlayer player) {
345+
return hasBank(player, null);
346+
}
347+
348+
/**
349+
* Checks if the specified player has a bank account in the given world.
350+
*
351+
* @param player the player to check for an associated bank account
352+
* @param world the world in which to check for the bank account
353+
* @return {@code true} if the player has a bank account in the specified world, otherwise {@code false}
354+
*/
355+
default boolean hasBank(OfflinePlayer player, @Nullable World world) {
356+
return hasBank(player.getUniqueId(), world);
357+
}
358+
359+
/**
360+
* Checks if the specified uuid is associated with a bank account.
361+
*
362+
* @param uuid the uuid of a player to check for an associated bank account
363+
* @return {@code true} if the uuid is associated with a bank account, otherwise {@code false}
364+
*/
365+
default boolean hasBank(UUID uuid) {
366+
return hasBank(uuid, null);
367+
}
368+
369+
/**
370+
* Checks if the specified uuid is associated with a bank account in the given world.
371+
*
372+
* @param uuid the uuid of a player to check for an associated bank account
373+
* @param world the world in which to check for the bank account
374+
* @return {@code true} if the uuid is associated with a bank account in the specified world, otherwise {@code false}
375+
*/
376+
boolean hasBank(UUID uuid, @Nullable World world);
377+
338378
/**
339379
* Determines whether the controller supports handling of multiple worlds.
340380
*

src/main/java/net/thenextlvl/service/api/economy/currency/Currency.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
*/
2222
@NullMarked
2323
public interface Currency {
24+
/**
25+
* Retrieves the {@code CurrencyHolder} associated with this currency.
26+
*
27+
* @return the {@code CurrencyHolder} instance that manages this currency
28+
*/
29+
@Contract(pure = true)
30+
CurrencyHolder getHolder();
31+
2432
/**
2533
* Retrieves the name of the currency.
2634
*
@@ -121,7 +129,7 @@ default Component format(Number amount, Audience audience) {
121129
* @return a {@code Builder} instance initialized with the properties of the current {@code Currency}
122130
*/
123131
Builder toBuilder();
124-
132+
125133
/**
126134
* A builder interface for constructing instances of {@link Currency}.
127135
* The {@code Builder} allows for the configuration of currency properties such as

0 commit comments

Comments
 (0)