1
1
package com .eternalcode .core .feature .warp ;
2
2
3
3
import com .eternalcode .commons .adventure .AdventureUtil ;
4
+ import com .eternalcode .commons .scheduler .Scheduler ;
4
5
import com .eternalcode .core .configuration .ConfigurationManager ;
5
6
import com .eternalcode .core .configuration .contextual .ConfigItem ;
6
7
import com .eternalcode .core .configuration .implementation .PluginConfiguration ;
7
8
import com .eternalcode .core .feature .language .Language ;
8
9
import com .eternalcode .core .feature .language .LanguageService ;
10
+ import com .eternalcode .core .feature .warp .messages .WarpMessages ;
11
+ import com .eternalcode .core .feature .warp .messages .WarpMessages .WarpInventorySection ;
9
12
import com .eternalcode .core .injector .annotations .Inject ;
10
13
import com .eternalcode .core .injector .annotations .component .Service ;
11
14
import com .eternalcode .core .translation .AbstractTranslation ;
12
15
import com .eternalcode .core .translation .Translation ;
13
- import com .eternalcode .core .feature .warp .messages .WarpMessages ;
14
- import com .eternalcode .core .feature .warp .messages .WarpMessages .WarpInventorySection ;
15
16
import com .eternalcode .core .translation .TranslationManager ;
17
+ import static com .eternalcode .core .util .FutureHandler .whenSuccess ;
16
18
import dev .triumphteam .gui .builder .item .BaseItemBuilder ;
17
19
import dev .triumphteam .gui .builder .item .ItemBuilder ;
18
20
import dev .triumphteam .gui .guis .Gui ;
19
21
import dev .triumphteam .gui .guis .GuiItem ;
22
+ import java .util .Collections ;
23
+ import java .util .Comparator ;
24
+ import java .util .List ;
25
+ import java .util .Optional ;
20
26
import net .kyori .adventure .text .Component ;
21
27
import net .kyori .adventure .text .minimessage .MiniMessage ;
22
28
import org .bukkit .Material ;
23
29
import org .bukkit .Server ;
24
30
import org .bukkit .entity .Player ;
25
31
26
- import java .util .Collections ;
27
- import java .util .Comparator ;
28
- import java .util .List ;
29
- import java .util .Optional ;
30
-
31
32
@ Service
32
33
public class WarpInventory {
33
34
@@ -50,6 +51,7 @@ public class WarpInventory {
50
51
private final WarpTeleportService warpTeleportService ;
51
52
private final ConfigurationManager configurationManager ;
52
53
private final PluginConfiguration config ;
54
+ private final Scheduler scheduler ;
53
55
54
56
@ Inject
55
57
WarpInventory (
@@ -60,7 +62,8 @@ public class WarpInventory {
60
62
MiniMessage miniMessage ,
61
63
WarpTeleportService warpTeleportService ,
62
64
ConfigurationManager configurationManager ,
63
- PluginConfiguration config
65
+ PluginConfiguration config ,
66
+ Scheduler scheduler
64
67
) {
65
68
this .translationManager = translationManager ;
66
69
this .languageService = languageService ;
@@ -70,17 +73,13 @@ public class WarpInventory {
70
73
this .warpTeleportService = warpTeleportService ;
71
74
this .configurationManager = configurationManager ;
72
75
this .config = config ;
76
+ this .scheduler = scheduler ;
73
77
}
74
78
75
79
public void openInventory (Player player ) {
76
- this .languageService .getLanguage (player .getUniqueId ()).whenComplete ((language , throwable ) -> {
77
- if (language == null ) {
78
- language = Language .DEFAULT ;
79
- }
80
-
81
- this .createInventory (player , language )
82
- .open (player );
83
- });
80
+ this .languageService .getLanguage (player .getUniqueId ())
81
+ .thenApply (language -> this .createInventory (player , language ))
82
+ .whenComplete (whenSuccess (gui -> this .scheduler .run (() -> gui .open (player ))));
84
83
}
85
84
86
85
private Gui createInventory (Player player , Language language ) {
@@ -229,7 +228,8 @@ public void addWarp(Warp warp) {
229
228
WarpMessages .WarpInventorySection warpSection = translation .warp ().warpInventory ();
230
229
int slot = getSlot (warpSection );
231
230
232
- warpSection .addItem (warp .getName (),
231
+ warpSection .addItem (
232
+ warp .getName (),
233
233
WarpInventoryItem .builder ()
234
234
.withWarpName (warp .getName ())
235
235
.withWarpItem (ConfigItem .builder ()
@@ -243,7 +243,6 @@ public void addWarp(Warp warp) {
243
243
.build ());
244
244
245
245
this .configurationManager .save (translation );
246
-
247
246
}
248
247
}
249
248
@@ -293,5 +292,4 @@ private void shiftWarpItems(WarpInventoryItem removed, WarpMessages.WarpInventor
293
292
currentShift = nextShift ;
294
293
}
295
294
}
296
-
297
295
}
0 commit comments