mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
De-nest futures on teleport and timedTeleport, fix crash, tweak SpawnCommand logic
This commit is contained in:
1 parent
4832d69131
commit
973ae90905
4 files changed
+43
-48
No files matched your search
@@ -2,11 +2,9 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SpawnCommand extends CommandBase {
|
||||
@@ -23,16 +21,16 @@ public class SpawnCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
final Optional<? extends Position> position = (plugin.getSettings().crossServer && plugin.getSettings().globalSpawn
|
||||
? plugin.getDatabase().getWarp(plugin.getSettings().globalSpawnName).join()
|
||||
: plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getPluginServer())));
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_spawn_not_set").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getTeleportManager().timedTeleport(onlineUser, position.get()).join();
|
||||
});
|
||||
CompletableFuture.supplyAsync(() -> plugin.getSettings().crossServer && plugin.getSettings().globalSpawn
|
||||
? plugin.getDatabase().getWarp(plugin.getSettings().globalSpawnName).join()
|
||||
: plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getPluginServer())))
|
||||
.thenAccept(position -> {
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_spawn_not_set")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().timedTeleport(onlineUser, position.get());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class EventListener {
|
||||
.ifPresent(position -> onlineUser.teleport(position, plugin.getSettings().asynchronousTeleports));
|
||||
onlineUser.sendMinecraftMessage("block.minecraft.spawn.not_valid");
|
||||
} else {
|
||||
onlineUser.teleport(bedPosition.get(), plugin.getSettings().asynchronousTeleports).join();
|
||||
onlineUser.teleport(bedPosition.get(), plugin.getSettings().asynchronousTeleports);
|
||||
}
|
||||
plugin.getDatabase().setCurrentTeleport(onlineUser, null).thenRun(() ->
|
||||
plugin.getDatabase().setRespawnPosition(onlineUser, bedPosition.orElse(null))
|
||||
@@ -75,9 +75,8 @@ public class EventListener {
|
||||
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_COMPLETE)
|
||||
.ifPresent(onlineUser::playSound);
|
||||
}
|
||||
}).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null))
|
||||
.join();
|
||||
})).join();
|
||||
}).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null));
|
||||
}));
|
||||
}
|
||||
}).thenRun(() -> {
|
||||
// Update the cached player list
|
||||
|
||||
@@ -261,19 +261,19 @@ public class TeleportManager {
|
||||
|
||||
final int teleportWarmupTime = plugin.getSettings().teleportWarmupTime;
|
||||
if (!onlineUser.hasPermission(Permission.BYPASS_TELEPORT_WARMUP.node) && teleportWarmupTime > 0) {
|
||||
return CompletableFuture.supplyAsync(() -> processTeleportWarmup(new TimedTeleport(onlineUser, position, teleportWarmupTime))
|
||||
.thenApply(teleport -> {
|
||||
if (!teleport.cancelled) {
|
||||
for (final Settings.EconomyAction action : economyActions) {
|
||||
if (!plugin.validateEconomyCheck(onlineUser, action)) {
|
||||
return TeleportResult.CANCELLED;
|
||||
}
|
||||
}
|
||||
return teleport(onlineUser, position).join();
|
||||
} else {
|
||||
final TimedTeleport timedTeleport = new TimedTeleport(onlineUser, position, teleportWarmupTime);
|
||||
return processTeleportWarmup(timedTeleport).thenApplyAsync(teleport -> {
|
||||
if (!teleport.cancelled) {
|
||||
for (final Settings.EconomyAction action : economyActions) {
|
||||
if (!plugin.validateEconomyCheck(onlineUser, action)) {
|
||||
return TeleportResult.CANCELLED;
|
||||
}
|
||||
}).join());
|
||||
}
|
||||
return teleport(onlineUser, position).join();
|
||||
} else {
|
||||
return TeleportResult.CANCELLED;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return teleport(onlineUser, position);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user