Skip to content

Commit 8498008

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 51849d1 commit 8498008

File tree

6 files changed

+80
-6
lines changed

6 files changed

+80
-6
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "net.thenextlvl.services"
8-
version = "3.0.0-pre4"
8+
version = "3.0.0-pre5"
99

1010
java {
1111
toolchain.languageVersion = JavaLanguageVersion.of(21)

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
@@ -85,12 +85,30 @@ public CompletableFuture<Boolean> deleteBank(UUID uuid, @Nullable World world) {
8585

8686
@Override
8787
public Optional<Bank> getBank(String name) {
88+
if (!economy.getBanks().contains(name)) return Optional.empty();
8889
return Optional.of(new WrappedBank(name, null, economy, plugin));
8990
}
9091

92+
@Override
93+
public Optional<Bank> getBank(OfflinePlayer player, @Nullable World world) {
94+
return economy.getBanks().stream().filter(bank ->
95+
economy.isBankOwner(bank, player).transactionSuccess()
96+
).findAny().flatMap(this::getBank);
97+
}
98+
9199
@Override
92100
public Optional<Bank> getBank(UUID uuid, @Nullable World world) {
93-
return Optional.empty();
101+
return getBank(plugin.getServer().getOfflinePlayer(uuid), world);
102+
}
103+
104+
@Override
105+
public boolean hasBank(OfflinePlayer player, @Nullable World world) {
106+
return economy.getBanks().stream().anyMatch(bank -> economy.isBankOwner(bank, player).transactionSuccess());
107+
}
108+
109+
@Override
110+
public boolean hasBank(UUID uuid, @Nullable World world) {
111+
return hasBank(plugin.getServer().getOfflinePlayer(uuid), world);
94112
}
95113

96114
@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
@@ -114,7 +114,7 @@ private static class WrappedCurrencyHolder implements CurrencyHolder {
114114
private final Currency currency;
115115

116116
private WrappedCurrencyHolder(Economy economy) {
117-
this.currency = new WrappedCurrency(economy);
117+
this.currency = new WrappedCurrency(this, economy);
118118
}
119119

120120
@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)