mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Correct unsafe future joining
This commit is contained in:
1 parent
adac00ea47
commit
950a51c140
14 files changed
+29
-29
No files matched your search
@@ -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
|
* @return the {@link Position} of the spawn, or an empty {@link Optional} if it has not been set
|
||||||
*/
|
*/
|
||||||
default Optional<? extends Position> getSpawn() {
|
default CompletableFuture<Optional<? extends Position>> getSpawn() {
|
||||||
return getSettings().crossServer && getSettings().globalSpawn
|
return CompletableFuture.supplyAsync(() -> getSettings().crossServer && getSettings().globalSpawn
|
||||||
? getDatabase().getWarp(getSettings().globalSpawnName).join()
|
? getDatabase().getWarp(getSettings().globalSpawnName).join()
|
||||||
: getLocalCachedSpawn().flatMap(spawn -> spawn.getPosition(getPluginServer()));
|
: getLocalCachedSpawn().flatMap(spawn -> spawn.getPosition(getPluginServer())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ public abstract class BaseHuskHomesAPI {
|
|||||||
* @return A {@link CompletableFuture} that will complete with the {@link Position} of the spawn point
|
* @return A {@link CompletableFuture} that will complete with the {@link Position} of the spawn point
|
||||||
*/
|
*/
|
||||||
public final CompletableFuture<Optional<? extends Position>> getSpawn() {
|
public final CompletableFuture<Optional<? extends Position>> getSpawn() {
|
||||||
return CompletableFuture.supplyAsync(plugin::getSpawn);
|
return plugin.getSpawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
for (final Home toDelete : homes) {
|
for (final Home toDelete : homes) {
|
||||||
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteHome(homeOwner, toDelete.meta.name));
|
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()))
|
plugin.getLocales().getLocale("delete_all_homes_success", Integer.toString(homeDeletionFuture.size()))
|
||||||
.ifPresent(deleter::sendMessage)).join();
|
.ifPresent(deleter::sendMessage)).join();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
for (final Warp toDelete : warps) {
|
for (final Warp toDelete : warps) {
|
||||||
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteWarp(toDelete.meta.name));
|
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()))
|
plugin.getLocales().getLocale("delete_all_warps_success", Integer.toString(homeDeletionFuture.size()))
|
||||||
.ifPresent(deleter::sendMessage)).join();
|
.ifPresent(deleter::sendMessage)).join();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plugin.getDatabase().getHome(userData.user(), homeIdentifier.homeName()).thenAccept(optionalHome -> {
|
plugin.getDatabase().getHome(userData.user(), homeIdentifier.homeName()).thenAcceptAsync(optionalHome -> {
|
||||||
if (optionalHome.isEmpty()) {
|
if (optionalHome.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_home_invalid_other",
|
plugin.getLocales().getLocale("error_home_invalid_other",
|
||||||
homeIdentifier.ownerName(), homeIdentifier.homeName())
|
homeIdentifier.ownerName(), homeIdentifier.homeName())
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
|||||||
@Override
|
@Override
|
||||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||||
switch (args.length) {
|
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
|
// Display the public home list if there are any public home set
|
||||||
if (publicHomes.size() == 0) {
|
if (publicHomes.size() == 0) {
|
||||||
plugin.getLocales().getLocale("error_no_public_homes_set").ifPresent(onlineUser::sendMessage);
|
plugin.getLocales().getLocale("error_no_public_homes_set").ifPresent(onlineUser::sendMessage);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class PublicHomeListCommand extends CommandBase implements ConsoleExecuta
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getDatabase().getPublicHomes().thenAccept(publicHomes -> {
|
plugin.getDatabase().getPublicHomes().thenAcceptAsync(publicHomes -> {
|
||||||
if (publicHomes.isEmpty()) {
|
if (publicHomes.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_no_public_homes_set").ifPresent(onlineUser::sendMessage);
|
plugin.getLocales().getLocale("error_no_public_homes_set").ifPresent(onlineUser::sendMessage);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.william278.huskhomes.config.Settings;
|
|||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.player.UserData;
|
import net.william278.huskhomes.player.UserData;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
|
import net.william278.huskhomes.teleport.TeleportResult;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -70,15 +71,17 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get a random position and teleport
|
// Get a random position and teleport
|
||||||
plugin.getRandomTeleportEngine().getRandomPosition(onlineUser, rtpArguments)
|
plugin.getRandomTeleportEngine().getRandomPosition(onlineUser, rtpArguments).thenAccept(position -> {
|
||||||
.thenAccept(position -> {
|
|
||||||
if (position.isEmpty()) {
|
if (position.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_rtp_randomization_timeout")
|
plugin.getLocales().getLocale("error_rtp_randomization_timeout")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(isExecutorTeleporting ? plugin.getTeleportManager().timedTeleport(userToTeleport, position.get(), Settings.EconomyAction.RANDOM_TELEPORT)
|
|
||||||
: plugin.getTeleportManager().teleport(userToTeleport, position.get())).thenAccept(result -> {
|
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 &&
|
if (isExecutorTeleporting &&
|
||||||
result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
|
result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
|
||||||
plugin.getDatabase().updateUserData(new UserData(onlineUser,
|
plugin.getDatabase().updateUserData(new UserData(onlineUser,
|
||||||
@@ -87,8 +90,8 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
|||||||
}
|
}
|
||||||
plugin.getTeleportManager().finishTeleport(userToTeleport, result,
|
plugin.getTeleportManager().finishTeleport(userToTeleport, result,
|
||||||
Settings.EconomyAction.RANDOM_TELEPORT);
|
Settings.EconomyAction.RANDOM_TELEPORT);
|
||||||
}).join();
|
});
|
||||||
}).join();
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import net.william278.huskhomes.player.OnlineUser;
|
|||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class SpawnCommand extends CommandBase {
|
public class SpawnCommand extends CommandBase {
|
||||||
|
|
||||||
protected SpawnCommand(@NotNull HuskHomes implementor) {
|
protected SpawnCommand(@NotNull HuskHomes implementor) {
|
||||||
@@ -21,7 +19,7 @@ public class SpawnCommand extends CommandBase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture.supplyAsync(plugin::getSpawn).thenAccept(position -> {
|
plugin.getSpawn().thenAccept(position -> {
|
||||||
if (position.isEmpty()) {
|
if (position.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_spawn_not_set")
|
plugin.getLocales().getLocale("error_spawn_not_set")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class TpIgnoreCommand extends CommandBase {
|
|||||||
plugin.getRequestManager().setIgnoringRequests(onlineUser, isIgnoringRequests);
|
plugin.getRequestManager().setIgnoringRequests(onlineUser, isIgnoringRequests);
|
||||||
|
|
||||||
// Update value on the database and send a message
|
// 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,
|
userData -> userData.ifPresent(data -> plugin.getDatabase().updateUserData(new UserData(onlineUser,
|
||||||
data.homeSlots(), isIgnoringRequests, data.rtpCooldown())).join())).thenRun(
|
data.homeSlots(), isIgnoringRequests, data.rtpCooldown())).join())).thenRun(
|
||||||
() -> plugin.getLocales().getRawLocale("tpignore_toggle_" + (isIgnoringRequests ? "on" : "off"),
|
() -> 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)
|
plugin.getLocales().getLocale("teleporting_offline_player", targetUser)
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
plugin.getTeleportManager().teleport(onlineUser, offlinePosition.get()).thenAccept(
|
plugin.getTeleportManager().teleport(onlineUser, offlinePosition.get()).thenAccept(
|
||||||
result -> plugin.getTeleportManager().finishTeleport(onlineUser, result)).join();
|
result -> plugin.getTeleportManager().finishTeleport(onlineUser, result));
|
||||||
}).join();
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class EventListener {
|
|||||||
firstUser = false;
|
firstUser = false;
|
||||||
plugin.fetchServer(onlineUser).join();
|
plugin.fetchServer(onlineUser).join();
|
||||||
}
|
}
|
||||||
}).thenRun(() -> {
|
}).thenRunAsync(() -> {
|
||||||
// Ensure the player is present on the database first
|
// Ensure the player is present on the database first
|
||||||
plugin.getDatabase().ensureUser(onlineUser).join();
|
plugin.getDatabase().ensureUser(onlineUser).join();
|
||||||
}).thenRun(() -> {
|
}).thenRun(() -> {
|
||||||
@@ -58,9 +58,8 @@ public class EventListener {
|
|||||||
} else {
|
} else {
|
||||||
onlineUser.teleport(bedPosition.get(), plugin.getSettings().asynchronousTeleports);
|
onlineUser.teleport(bedPosition.get(), plugin.getSettings().asynchronousTeleports);
|
||||||
}
|
}
|
||||||
plugin.getDatabase().setCurrentTeleport(onlineUser, null).thenRun(() ->
|
plugin.getDatabase().setCurrentTeleport(onlineUser, null).thenRunAsync(() ->
|
||||||
plugin.getDatabase().setRespawnPosition(onlineUser, bedPosition.orElse(null))
|
plugin.getDatabase().setRespawnPosition(onlineUser, bedPosition.orElse(null)).join());
|
||||||
.join()).join();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +80,7 @@ public class EventListener {
|
|||||||
}).thenRun(() -> {
|
}).thenRun(() -> {
|
||||||
// Update the cached player list
|
// Update the cached player list
|
||||||
plugin.getCache().updatePlayerListCache(plugin, onlineUser);
|
plugin.getCache().updatePlayerListCache(plugin, onlineUser);
|
||||||
}).thenRun(() -> {
|
}).thenRunAsync(() -> {
|
||||||
// Get this user's tp-ignore state and set locally
|
// Get this user's tp-ignore state and set locally
|
||||||
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> {
|
plugin.getDatabase().getUserData(onlineUser.uuid).thenAccept(userData -> {
|
||||||
if (userData.isPresent()) {
|
if (userData.isPresent()) {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class RequestManager {
|
|||||||
// If the player couldn't be found locally, send the request cross-server
|
// If the player couldn't be found locally, send the request cross-server
|
||||||
if (plugin.getSettings().crossServer) {
|
if (plugin.getSettings().crossServer) {
|
||||||
// Find the matching networked target
|
// Find the matching networked target
|
||||||
return plugin.getNetworkMessenger().findPlayer(requester, targetUser).thenApply(networkedTarget -> {
|
return plugin.getNetworkMessenger().findPlayer(requester, targetUser).thenApplyAsync(networkedTarget -> {
|
||||||
if (networkedTarget.isEmpty()) {
|
if (networkedTarget.isEmpty()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class TeleportManager {
|
|||||||
*/
|
*/
|
||||||
public CompletableFuture<Optional<TeleportResult>> teleportNamedPlayers(@NotNull String playerName, @NotNull String targetPlayer,
|
public CompletableFuture<Optional<TeleportResult>> teleportNamedPlayers(@NotNull String playerName, @NotNull String targetPlayer,
|
||||||
@NotNull OnlineUser requester, final boolean timed) {
|
@NotNull OnlineUser requester, final boolean timed) {
|
||||||
return getPlayerPositionByName(requester, targetPlayer).thenApply(position -> {
|
return getPlayerPositionByName(requester, targetPlayer).thenApplyAsync(position -> {
|
||||||
if (position.isEmpty()) {
|
if (position.isEmpty()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@@ -375,7 +375,7 @@ public class TeleportManager {
|
|||||||
private CompletableFuture<TeleportResult> teleportCrossServer(@NotNull OnlineUser onlineUser, @NotNull Teleport teleport) {
|
private CompletableFuture<TeleportResult> teleportCrossServer(@NotNull OnlineUser onlineUser, @NotNull Teleport teleport) {
|
||||||
|
|
||||||
return plugin.getDatabase().setCurrentTeleport(teleport.player, 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 :
|
.thenApply(completed -> completed ? TeleportResult.COMPLETED_CROSS_SERVER :
|
||||||
TeleportResult.FAILED_INVALID_SERVER)
|
TeleportResult.FAILED_INVALID_SERVER)
|
||||||
.join());
|
.join());
|
||||||
|
|||||||
Reference in new issue
Block a user