1515import t .me .p1azmer .engine .api .manager .AbstractListener ;
1616import t .me .p1azmer .engine .api .manager .AbstractManager ;
1717import t .me .p1azmer .engine .config .EngineConfig ;
18- import t .me .p1azmer .engine .utils .EntityUtil ;
1918import t .me .p1azmer .engine .utils .PlayerUtil ;
2019
2120import java .util .*;
@@ -133,36 +132,32 @@ public void getUserDataAndPerform(@NotNull String name, Consumer<U> consumer) {
133132 U user = this .getUserLoaded (name );
134133 if (user != null ) {
135134 consumer .accept (user );
136- }
137- else this .getUserDataAsync (name ).thenAccept (user2 -> this .plugin .runTask (task -> consumer .accept (user2 )));
135+ } else this .getUserDataAsync (name ).thenAccept (user2 -> this .plugin .runTask (task -> consumer .accept (user2 )));
138136 }
139137
140138 public void getUserDataAndPerform (@ NotNull UUID uuid , Consumer <U > consumer ) {
141139 U user = this .getUserLoaded (uuid );
142140 if (user != null ) {
143141 consumer .accept (user );
144- }
145- else this .getUserDataAsync (uuid ).thenAccept (user2 -> this .plugin .runTask (task -> consumer .accept (user2 )));
142+ } else this .getUserDataAsync (uuid ).thenAccept (user2 -> this .plugin .runTask (task -> consumer .accept (user2 )));
146143 }
147144
148145 public void getUserDataAndPerformAsync (@ NotNull String name , Consumer <U > consumer ) {
149146 U user = this .getUserLoaded (name );
150147 if (user != null ) {
151148 consumer .accept (user );
152- }
153- else this .getUserDataAsync (name ).thenAccept (consumer );
149+ } else this .getUserDataAsync (name ).thenAccept (consumer );
154150 }
155151
156152 public void getUserDataAndPerformAsync (@ NotNull UUID uuid , Consumer <U > consumer ) {
157153 U user = this .getUserLoaded (uuid );
158154 if (user != null ) {
159155 consumer .accept (user );
160- }
161- else this .getUserDataAsync (uuid ).thenAccept (consumer );
156+ } else this .getUserDataAsync (uuid ).thenAccept (consumer );
162157 }
163158
164159 public final void unloadUser (@ NotNull Player player ) {
165- this .unloadUser (player .getUniqueId ());
160+ CompletableFuture . runAsync (() -> this .unloadUser (player .getUniqueId () ));
166161 }
167162
168163 public final void unloadUser (@ NotNull UUID uuid ) {
@@ -183,7 +178,7 @@ public void unloadUser(@NotNull U user) {
183178 }
184179
185180 public void saveUser (@ NotNull U user ) {
186- this . plugin . runTaskAsync ( task -> this .dataHolder .getData ().saveUser (user ));
181+ CompletableFuture . runAsync (() -> this .dataHolder .getData ().saveUser (user ));
187182 }
188183
189184 @ NotNull
@@ -225,7 +220,7 @@ public U getUserLoaded(@NotNull UUID uuid) {
225220 @ Nullable
226221 public U getUserLoaded (@ NotNull String name ) {
227222 return this .getUsersLoaded ().stream ().filter (user -> user .getName ().equalsIgnoreCase (name ))
228- .findFirst ().orElse (null );
223+ .findFirst ().orElse (null );
229224 }
230225
231226 public boolean isUserLoaded (@ NotNull Player player ) {
@@ -243,13 +238,11 @@ public boolean isUserExists(@NotNull UUID uuid) {
243238 public void cacheTemporary (@ NotNull U user ) {
244239 user .setCachedUntil (System .currentTimeMillis () + EngineConfig .USER_CACHE_LIFETIME .get () * 1000L );
245240 this .cache (user );
246- //this.plugin.debug("Temp user cache: " + user.getName());
247241 }
248242
249243 public void cachePermanent (@ NotNull U user ) {
250244 user .setCachedUntil (-1 );
251245 this .cache (user );
252- //this.plugin.debug("Permanent user cache: " + user.getName());
253246 }
254247
255248 private void cache (@ NotNull U user ) {
@@ -286,31 +279,25 @@ public void onUserLogin(AsyncPlayerPreLoginEvent event) {
286279
287280 @ EventHandler (priority = EventPriority .MONITOR )
288281 public void onUserQuit (PlayerQuitEvent event ) {
289- // slow down the process without loading the main thread so that the data is saved without loss
290- // for Proxy switching
291- CompletableFuture .runAsync (() -> {
292- plugin .runTask (sync -> unloadUser (event .getPlayer ()));
293- }).join ();
282+ unloadUser (event .getPlayer ());
294283 }
295284
296285 @ EventHandler (priority = EventPriority .MONITOR )
297286 public void onUserQuit (PlayerKickEvent event ) {
298- CompletableFuture .runAsync (() -> {
299- plugin .runTask (sync -> unloadUser (event .getPlayer ()));
300- }).join ();
287+ unloadUser (event .getPlayer ());
301288 }
302289
303290 @ EventHandler (priority = EventPriority .MONITOR , ignoreCancelled = true )
304291 public void onDisable (PluginDisableEvent event ) {
305292 if (event .getPlugin ().equals (this .plugin )) {
306- CompletableFuture . runAsync (() -> getUsersLoaded ().forEach (AbstractUserManager .this ::saveUser ) );
293+ getUsersLoaded ().forEach (AbstractUserManager .this ::saveUser );
307294 }
308295 }
309296
310297 @ EventHandler (priority = EventPriority .MONITOR , ignoreCancelled = true )
311298 public void onDisable (WorldUnloadEvent event ) {
312299 if (event .getWorld ().getEnvironment ().equals (World .Environment .NORMAL )) {
313- CompletableFuture . runAsync (() -> getUsersLoaded ().forEach (AbstractUserManager .this ::saveUser ) );
300+ getUsersLoaded ().forEach (AbstractUserManager .this ::saveUser );
314301 }
315302 }
316303 }
0 commit comments