mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Correct unsafe future joining
This commit is contained in:
1 parent
adac00ea47
commit
950a51c140
14 files changed
+42
-42
No files matched your search
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<TeleportResult> 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user