diff --git a/common/src/main/java/net/william278/huskhomes/HuskHomes.java b/common/src/main/java/net/william278/huskhomes/HuskHomes.java index 2d99e668..23def3f7 100644 --- a/common/src/main/java/net/william278/huskhomes/HuskHomes.java +++ b/common/src/main/java/net/william278/huskhomes/HuskHomes.java @@ -174,10 +174,10 @@ public interface HuskHomes { * * @return the {@link Position} of the spawn, or an empty {@link Optional} if it has not been set */ - default Optional getSpawn() { - return getSettings().crossServer && getSettings().globalSpawn + default CompletableFuture> getSpawn() { + return CompletableFuture.supplyAsync(() -> getSettings().crossServer && getSettings().globalSpawn ? getDatabase().getWarp(getSettings().globalSpawnName).join() - : getLocalCachedSpawn().flatMap(spawn -> spawn.getPosition(getPluginServer())); + : getLocalCachedSpawn().flatMap(spawn -> spawn.getPosition(getPluginServer()))); } /** diff --git a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java index 98a7790f..bfe03725 100644 --- a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java +++ b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java @@ -203,7 +203,7 @@ public abstract class BaseHuskHomesAPI { * @return A {@link CompletableFuture} that will complete with the {@link Position} of the spawn point */ public final CompletableFuture> getSpawn() { - return CompletableFuture.supplyAsync(plugin::getSpawn); + return plugin.getSpawn(); } /** diff --git a/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java index c710d8dc..c58a59ad 100644 --- a/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java @@ -121,7 +121,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable { for (final Home toDelete : homes) { homeDeletionFuture.add(plugin.getSavedPositionManager().deleteHome(homeOwner, toDelete.meta.name)); } - CompletableFuture.allOf(homeDeletionFuture.toArray(new CompletableFuture[0])).thenRun(() -> + CompletableFuture.allOf(homeDeletionFuture.toArray(new CompletableFuture[0])).thenRunAsync(() -> plugin.getLocales().getLocale("delete_all_homes_success", Integer.toString(homeDeletionFuture.size())) .ifPresent(deleter::sendMessage)).join(); }); diff --git a/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java index 1e71fafe..0027de33 100644 --- a/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/DelWarpCommand.java @@ -68,7 +68,7 @@ public class DelWarpCommand extends CommandBase implements TabCompletable { for (final Warp toDelete : warps) { homeDeletionFuture.add(plugin.getSavedPositionManager().deleteWarp(toDelete.meta.name)); } - CompletableFuture.allOf(homeDeletionFuture.toArray(new CompletableFuture[0])).thenRun(() -> + CompletableFuture.allOf(homeDeletionFuture.toArray(new CompletableFuture[0])).thenRunAsync(() -> plugin.getLocales().getLocale("delete_all_warps_success", Integer.toString(homeDeletionFuture.size())) .ifPresent(deleter::sendMessage)).join(); }); diff --git a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java index 32dfd72d..eb0a53ee 100644 --- a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java @@ -44,7 +44,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable { return; } } - plugin.getDatabase().getHome(userData.user(), homeIdentifier.homeName()).thenAccept(optionalHome -> { + plugin.getDatabase().getHome(userData.user(), homeIdentifier.homeName()).thenAcceptAsync(optionalHome -> { if (optionalHome.isEmpty()) { plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName()) diff --git a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java index a4da23c0..423e65e6 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java @@ -26,7 +26,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co @Override public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { switch (args.length) { - case 0 -> plugin.getDatabase().getPublicHomes().thenAccept(publicHomes -> { + case 0 -> plugin.getDatabase().getPublicHomes().thenAcceptAsync(publicHomes -> { // Display the public home list if there are any public home set if (publicHomes.size() == 0) { plugin.getLocales().getLocale("error_no_public_homes_set").ifPresent(onlineUser::sendMessage); diff --git a/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java b/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java index 7ef42c5f..15cb28d3 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java @@ -47,7 +47,7 @@ public class PublicHomeListCommand extends CommandBase implements ConsoleExecuta return; } - plugin.getDatabase().getPublicHomes().thenAccept(publicHomes -> { + plugin.getDatabase().getPublicHomes().thenAcceptAsync(publicHomes -> { if (publicHomes.isEmpty()) { plugin.getLocales().getLocale("error_no_public_homes_set").ifPresent(onlineUser::sendMessage); return; diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index 356e6fb0..f4737068 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -5,6 +5,7 @@ import net.william278.huskhomes.config.Settings; import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.player.UserData; import net.william278.huskhomes.position.Position; +import net.william278.huskhomes.teleport.TeleportResult; import net.william278.huskhomes.util.Permission; import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; @@ -70,25 +71,27 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable { } // Get a random position and teleport - plugin.getRandomTeleportEngine().getRandomPosition(onlineUser, rtpArguments) - .thenAccept(position -> { - if (position.isEmpty()) { - plugin.getLocales().getLocale("error_rtp_randomization_timeout") - .ifPresent(onlineUser::sendMessage); - return; - } - (isExecutorTeleporting ? plugin.getTeleportManager().timedTeleport(userToTeleport, position.get(), Settings.EconomyAction.RANDOM_TELEPORT) - : plugin.getTeleportManager().teleport(userToTeleport, position.get())).thenAccept(result -> { - if (isExecutorTeleporting && - result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) { - plugin.getDatabase().updateUserData(new UserData(onlineUser, - userData.get().homeSlots(), userData.get().ignoringTeleports(), - Instant.now().plus(plugin.getSettings().rtpCooldownLength, ChronoUnit.MINUTES))); - } - plugin.getTeleportManager().finishTeleport(userToTeleport, result, - Settings.EconomyAction.RANDOM_TELEPORT); - }).join(); - }).join(); + plugin.getRandomTeleportEngine().getRandomPosition(onlineUser, rtpArguments).thenAccept(position -> { + if (position.isEmpty()) { + plugin.getLocales().getLocale("error_rtp_randomization_timeout") + .ifPresent(onlineUser::sendMessage); + return; + } + + final CompletableFuture randomTeleport = isExecutorTeleporting ? plugin.getTeleportManager() + .timedTeleport(userToTeleport, position.get(), Settings.EconomyAction.RANDOM_TELEPORT) + : plugin.getTeleportManager().teleport(userToTeleport, position.get()); + randomTeleport.thenAccept(result -> { + if (isExecutorTeleporting && + result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) { + plugin.getDatabase().updateUserData(new UserData(onlineUser, + userData.get().homeSlots(), userData.get().ignoringTeleports(), + Instant.now().plus(plugin.getSettings().rtpCooldownLength, ChronoUnit.MINUTES))); + } + plugin.getTeleportManager().finishTeleport(userToTeleport, result, + Settings.EconomyAction.RANDOM_TELEPORT); + }); + }); }); } diff --git a/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java b/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java index 6baa3d93..f7770ad3 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java @@ -5,8 +5,6 @@ import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; -import java.util.concurrent.CompletableFuture; - public class SpawnCommand extends CommandBase { protected SpawnCommand(@NotNull HuskHomes implementor) { @@ -21,7 +19,7 @@ public class SpawnCommand extends CommandBase { return; } - CompletableFuture.supplyAsync(plugin::getSpawn).thenAccept(position -> { + plugin.getSpawn().thenAccept(position -> { if (position.isEmpty()) { plugin.getLocales().getLocale("error_spawn_not_set") .ifPresent(onlineUser::sendMessage); diff --git a/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java index 67487e23..2f27bdb5 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpIgnoreCommand.java @@ -26,7 +26,7 @@ public class TpIgnoreCommand extends CommandBase { plugin.getRequestManager().setIgnoringRequests(onlineUser, isIgnoringRequests); // Update value on the database and send a message - plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept( + plugin.getDatabase().getUserData(onlineUser.uuid).thenAcceptAsync( userData -> userData.ifPresent(data -> plugin.getDatabase().updateUserData(new UserData(onlineUser, data.homeSlots(), isIgnoringRequests, data.rtpCooldown())).join())).thenRun( () -> plugin.getLocales().getRawLocale("tpignore_toggle_" + (isIgnoringRequests ? "on" : "off"), diff --git a/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java index 087485f1..46af1c21 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpOfflineCommand.java @@ -39,8 +39,8 @@ public class TpOfflineCommand extends CommandBase implements TabCompletable { plugin.getLocales().getLocale("teleporting_offline_player", targetUser) .ifPresent(onlineUser::sendMessage); plugin.getTeleportManager().teleport(onlineUser, offlinePosition.get()).thenAccept( - result -> plugin.getTeleportManager().finishTeleport(onlineUser, result)).join(); - }).join(); + result -> plugin.getTeleportManager().finishTeleport(onlineUser, result)); + }); }); } diff --git a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java index e94bc7f0..b25e053e 100644 --- a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java +++ b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java @@ -41,7 +41,7 @@ public class EventListener { firstUser = false; plugin.fetchServer(onlineUser).join(); } - }).thenRun(() -> { + }).thenRunAsync(() -> { // Ensure the player is present on the database first plugin.getDatabase().ensureUser(onlineUser).join(); }).thenRun(() -> { @@ -58,9 +58,8 @@ public class EventListener { } else { onlineUser.teleport(bedPosition.get(), plugin.getSettings().asynchronousTeleports); } - plugin.getDatabase().setCurrentTeleport(onlineUser, null).thenRun(() -> - plugin.getDatabase().setRespawnPosition(onlineUser, bedPosition.orElse(null)) - .join()).join(); + plugin.getDatabase().setCurrentTeleport(onlineUser, null).thenRunAsync(() -> + plugin.getDatabase().setRespawnPosition(onlineUser, bedPosition.orElse(null)).join()); return; } @@ -81,7 +80,7 @@ public class EventListener { }).thenRun(() -> { // Update the cached player list plugin.getCache().updatePlayerListCache(plugin, onlineUser); - }).thenRun(() -> { + }).thenRunAsync(() -> { // Get this user's tp-ignore state and set locally plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> { if (userData.isPresent()) { diff --git a/common/src/main/java/net/william278/huskhomes/request/RequestManager.java b/common/src/main/java/net/william278/huskhomes/request/RequestManager.java index cede72e4..1639d41b 100644 --- a/common/src/main/java/net/william278/huskhomes/request/RequestManager.java +++ b/common/src/main/java/net/william278/huskhomes/request/RequestManager.java @@ -139,7 +139,7 @@ public class RequestManager { // If the player couldn't be found locally, send the request cross-server if (plugin.getSettings().crossServer) { // Find the matching networked target - return plugin.getNetworkMessenger().findPlayer(requester, targetUser).thenApply(networkedTarget -> { + return plugin.getNetworkMessenger().findPlayer(requester, targetUser).thenApplyAsync(networkedTarget -> { if (networkedTarget.isEmpty()) { return Optional.empty(); } diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java index dae8482f..0da76fbe 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java @@ -197,7 +197,7 @@ public class TeleportManager { */ public CompletableFuture> teleportNamedPlayers(@NotNull String playerName, @NotNull String targetPlayer, @NotNull OnlineUser requester, final boolean timed) { - return getPlayerPositionByName(requester, targetPlayer).thenApply(position -> { + return getPlayerPositionByName(requester, targetPlayer).thenApplyAsync(position -> { if (position.isEmpty()) { return Optional.empty(); } @@ -375,7 +375,7 @@ public class TeleportManager { private CompletableFuture teleportCrossServer(@NotNull OnlineUser onlineUser, @NotNull Teleport teleport) { return plugin.getDatabase().setCurrentTeleport(teleport.player, teleport) - .thenApply(ignored -> plugin.getNetworkMessenger().sendPlayer(onlineUser, teleport.target.server) + .thenApplyAsync(ignored -> plugin.getNetworkMessenger().sendPlayer(onlineUser, teleport.target.server) .thenApply(completed -> completed ? TeleportResult.COMPLETED_CROSS_SERVER : TeleportResult.FAILED_INVALID_SERVER) .join());