22
33import net .milkbowl .vault .economy .Economy ;
44import net .thenextlvl .service .api .economy .Account ;
5- import net .thenextlvl .service .api .economy .currency .Currency ;
65import net .thenextlvl .service .api .economy .EconomyController ;
7- import net .thenextlvl .service .wrapper .Wrapper ;
86import net .thenextlvl .service .wrapper .service .model .WrappedAccount ;
97import org .bukkit .OfflinePlayer ;
108import org .bukkit .World ;
119import org .bukkit .plugin .Plugin ;
1210import org .jetbrains .annotations .Unmodifiable ;
1311import org .jspecify .annotations .NullMarked ;
12+ import org .jspecify .annotations .Nullable ;
1413
1514import java .util .Arrays ;
15+ import java .util .List ;
1616import java .util .Optional ;
1717import java .util .Set ;
1818import java .util .UUID ;
@@ -32,90 +32,67 @@ public EconomyServiceWrapper(Economy economy, Plugin provider) {
3232 }
3333
3434 @ Override
35- public CompletableFuture <@ Unmodifiable Set <Account >> loadAccounts () {
36- return CompletableFuture .completedFuture (getAccounts ());
35+ public CompletableFuture <@ Unmodifiable Set <Account >> loadAccounts (@ Nullable World world ) {
36+ return CompletableFuture .completedFuture (getAccounts (world ));
3737 }
3838
3939 @ Override
40- public @ Unmodifiable Set <Account > getAccounts () {
40+ public @ Unmodifiable Set <Account > getAccounts (@ Nullable World world ) {
4141 return Arrays .stream (provider .getServer ().getOfflinePlayers ())
42- .filter (economy :: hasAccount )
43- .map (player -> new WrappedAccount (this , null , economy , player ))
42+ .filter (player -> economy . hasAccount ( player , world != null ? world . getName () : null ) )
43+ .map (player -> new WrappedAccount (this , world , economy , player ))
4444 .collect (Collectors .toUnmodifiableSet ());
4545 }
4646
4747 @ Override
48- public Optional <Account > getAccount (OfflinePlayer player ) {
49- if (!economy .hasAccount (player )) return Optional .empty ();
50- return Optional .of (new WrappedAccount (this , null , economy , player ));
51- }
52-
53- @ Override
54- public Optional <Account > getAccount (OfflinePlayer player , World world ) {
55- if (!economy .hasAccount (player , world .getName ())) return Optional .empty ();
48+ public Optional <Account > getAccount (OfflinePlayer player , @ Nullable World world ) {
49+ if (!economy .hasAccount (player , world != null ? world .getName () : null )) return Optional .empty ();
5650 return Optional .of (new WrappedAccount (this , world , economy , player ));
5751 }
5852
5953 @ Override
60- public Optional <Account > getAccount (UUID uuid ) {
61- return getAccount (provider .getServer ().getOfflinePlayer (uuid ));
62- }
63-
64- @ Override
65- public Optional <Account > getAccount (UUID uuid , World world ) {
54+ public Optional <Account > getAccount (UUID uuid , @ Nullable World world ) {
6655 return getAccount (provider .getServer ().getOfflinePlayer (uuid ), world );
6756 }
6857
6958 @ Override
70- public CompletableFuture <Account > createAccount (OfflinePlayer player ) {
71- return CompletableFuture .completedFuture (economy .createPlayerAccount (player ))
72- .thenApply (account -> getAccount (player ).orElseThrow ());
59+ public CompletableFuture <Account > createAccount (OfflinePlayer player , @ Nullable World world ) {
60+ var created = economy .createPlayerAccount (player , world != null ? world .getName () : null );
61+ if (created ) loadAccount (player , world ).thenApply (account -> account .orElseThrow (() ->
62+ new IllegalStateException ("Could not find player account after creation" )));
63+ return CompletableFuture .failedFuture (new IllegalStateException (
64+ "Similar account already exists"
65+ ));
7366 }
7467
7568 @ Override
76- public CompletableFuture <Account > createAccount (OfflinePlayer player , World world ) {
77- return CompletableFuture .completedFuture (economy .createPlayerAccount (player , world .getName ()))
78- .thenApply (account -> getAccount (player , world ).orElseThrow ());
69+ public CompletableFuture <Account > createAccount (UUID uuid , @ Nullable World world ) {
70+ return createAccount (plugin .getServer ().getOfflinePlayer (uuid ), world );
7971 }
8072
8173 @ Override
82- public CompletableFuture <Account > createAccount (UUID uuid ) {
83- return createAccount (provider .getServer ().getOfflinePlayer (uuid ));
84- }
85-
86- @ Override
87- public CompletableFuture <Account > createAccount (UUID uuid , World world ) {
88- return createAccount (provider .getServer ().getOfflinePlayer (uuid ), world );
89- }
90-
91- @ Override
92- public CompletableFuture <Optional <Account >> loadAccount (OfflinePlayer player ) {
93- return CompletableFuture .completedFuture (getAccount (player ));
94- }
95-
96- @ Override
97- public CompletableFuture <Optional <Account >> loadAccount (OfflinePlayer player , World world ) {
74+ public CompletableFuture <Optional <Account >> loadAccount (OfflinePlayer player , @ Nullable World world ) {
9875 return CompletableFuture .completedFuture (getAccount (player , world ));
9976 }
10077
10178 @ Override
102- public CompletableFuture <Optional <Account >> loadAccount (UUID uuid ) {
103- return loadAccount (provider .getServer ().getOfflinePlayer (uuid ));
79+ public CompletableFuture <Optional <Account >> loadAccount (UUID uuid , @ Nullable World world ) {
80+ return loadAccount (provider .getServer ().getOfflinePlayer (uuid ), world );
10481 }
10582
10683 @ Override
107- public CompletableFuture <Optional < Account >> loadAccount (UUID uuid , World world ) {
108- return loadAccount ( provider . getServer (). getOfflinePlayer ( uuid ), world );
84+ public CompletableFuture <Boolean > deleteAccount (UUID uuid , @ Nullable World world ) {
85+ return CompletableFuture . completedFuture ( false );
10986 }
11087
11188 @ Override
112- public CompletableFuture <Boolean > deleteAccount ( UUID uuid ) {
89+ public CompletableFuture <Boolean > deleteAccounts ( List < UUID > accounts , @ Nullable World world ) {
11390 return CompletableFuture .completedFuture (false );
11491 }
11592
11693 @ Override
117- public CompletableFuture < Boolean > deleteAccount ( UUID uuid , World world ) {
118- return CompletableFuture . completedFuture ( false ) ;
94+ public boolean hasMultiWorldSupport ( ) {
95+ return false ;
11996 }
12097
12198 @ Override
0 commit comments