mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
/rtp API tweaks, add timeout failsafe, add teleporting_random_generation locale
This commit is contained in:
1 parent
a0042ac4c8
commit
6efefb175f
13 files changed
+42
-9
No files matched your search
@@ -70,6 +70,8 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
||||
}
|
||||
|
||||
// Get a random position and teleport
|
||||
plugin.getLocales().getLocale("teleporting_random_generation")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
plugin.getRandomTeleportEngine().getRandomPosition(onlineUser.getPosition().world, rtpArguments).thenAccept(position -> {
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_rtp_randomization_timeout")
|
||||
|
||||
@@ -85,16 +85,15 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args) {
|
||||
protected Optional<Position> generatePosition(@NotNull World world, @NotNull String[] args) {
|
||||
Optional<Location> location = generateSafeLocation(world).join();
|
||||
int attempts = 0;
|
||||
while (location.isEmpty()) {
|
||||
location = generateSafeLocation(world).join();
|
||||
if (attempts > randomTimeout) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
return CompletableFuture.completedFuture(location.map(resolved ->
|
||||
new Position(resolved, plugin.getPluginServer())));
|
||||
return location.map(resolved -> new Position(resolved, plugin.getPluginServer()));
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Represents an engine for generating random position targets
|
||||
*/
|
||||
public abstract class RandomTeleportEngine {
|
||||
|
||||
@NotNull
|
||||
@@ -24,6 +28,12 @@ public abstract class RandomTeleportEngine {
|
||||
*/
|
||||
public long randomTimeout = 8;
|
||||
|
||||
/**
|
||||
* Constructor for a random teleport engine
|
||||
*
|
||||
* @param plugin The HuskHomes plugin instance
|
||||
* @param name The name of the implementing random teleport engine
|
||||
*/
|
||||
protected RandomTeleportEngine(@NotNull HuskHomes plugin, @NotNull String name) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
@@ -46,6 +56,18 @@ public abstract class RandomTeleportEngine {
|
||||
world, plugin.getPluginServer()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a random position in the {@link World}, or {@link Optional#empty()} if no position could be found in
|
||||
* the configured number of attempts
|
||||
*
|
||||
* @param world The world to find a random position in
|
||||
* @param args The arguments to pass to the random teleport engine
|
||||
* @return The position, optionally, which will be empty if the random teleport engine timed out after a
|
||||
* {@link #randomTimeout configured number of attempts}
|
||||
* @implNote This is run asynchronously (i.e. not on the main server thread)
|
||||
*/
|
||||
protected abstract Optional<Position> generatePosition(@NotNull World world, @NotNull String[] args);
|
||||
|
||||
/**
|
||||
* Gets a random position in the {@link World}, supplying a future to be completed with the optional position
|
||||
* is found, or empty if the operation times out after a number of attempts.
|
||||
@@ -53,8 +75,12 @@ public abstract class RandomTeleportEngine {
|
||||
* @param world The world to find a random position in
|
||||
* @param args The arguments to pass to the random teleport engine
|
||||
* @return A {@link CompletableFuture} containing the random position, if one is found in
|
||||
* {@link #randomTimeout configured number of attempts}
|
||||
* {@link #randomTimeout configured number of attempts}, or if the operation times out after 10 seconds
|
||||
*/
|
||||
public abstract CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args);
|
||||
public CompletableFuture<Optional<Position>> getRandomPosition(@NotNull World world, @NotNull String[] args) {
|
||||
return CompletableFuture.supplyAsync(() -> generatePosition(world, args))
|
||||
.orTimeout(10, TimeUnit.SECONDS)
|
||||
.exceptionally(e -> Optional.empty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[Телепортацията отказан
|
||||
teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)'
|
||||
tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)'
|
||||
tpaall_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [player(s) to teleport to you.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[Teleportation abgebrochen!](#ff7e5e)'
|
||||
teleporting_other_complete: '[%1% wurde zu %2% teleportiert.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[%1% wurde zu ⚐ x: %2%, y: %3%, z: %4% teleportiert.](#00fb9a)'
|
||||
teleporting_all_players: '[Teleportiere](#00fb9a) [%1%](#00fb9a bold) [Spieler zu deiner Position…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[Du hast](#00fb9a) [%1%](#00fb9a bold) [eine Teleportanfrage gesendet.](#00fb9a)'
|
||||
tpahere_request_sent: '[Du hast eine Teleportanfrage gestellt und](#00fb9a) [%1%](#00fb9a bold) [gebeten sich zu dir zu teleportieren.](#00fb9a)'
|
||||
tpaall_request_sent: '[Du hast eine Teleportanfrage gestellt und](#00fb9a) [%1%](#00fb9a bold) [Spieler gebeten sich zu dir zu teleportieren.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[Teleportation cancelled!](#ff7e5e)'
|
||||
teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)'
|
||||
tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)'
|
||||
tpaall_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [player(s) to teleport to you.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[¡Teleportación cancelada!](#ff7e5e)'
|
||||
teleporting_other_complete: '[Teletransportado %1% a %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[Teletransportado %1% a ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[Teletransportando a ](#00fb9a) [%1%](#00fb9a bold) [jugador(es) a su posición...](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[Has enviado una solicitud de teletransporte a](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)'
|
||||
tpahere_request_sent: '[Has enviado una solicitud de teletransporte pidiendo a](#00fb9a) [%1%](#00fb9a bold) [que se teletransporte hacia ti.](#00fb9a)'
|
||||
tpaall_request_sent: '[Has enviado una solicitud de teletransporte a](#00fb9a) [%1%](#00fb9a bold) [jugador(es) para teletransportarse hacia ti.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[Teletrasporto cancellato!](#ff7e5e)'
|
||||
teleporting_other_complete: '[Hai teletrasportato %1% da %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[Hai telerasportato %1% a ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[Stai teletrasportando](#00fb9a) [%1%](#00fb9a bold) [giocatore(i) nella tua posizione…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[Hai richiesto di teletrasportarti da](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)'
|
||||
tpahere_request_sent: '[Hai richiesto il teletrasporto a](#00fb9a) [%1%](#00fb9a bold) [ verso la tua posizione.](#00fb9a)'
|
||||
tpaall_request_sent: '[Hai chiesto a](#00fb9a) [%1%](#00fb9a bold) [ giocatore(i) di teletrasportarsi da te.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[Teleportacja anulowana!](#ff7e5e)'
|
||||
teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)'
|
||||
tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)'
|
||||
tpaall_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [player(s) to teleport to you.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[Телепортацію скасовано!
|
||||
teleporting_other_complete: '[Teleported %1% to %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[Teleported %1% to ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[Teleporting](#00fb9a) [%1%](#00fb9a bold) [player(s) to your position…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)'
|
||||
tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)'
|
||||
tpaall_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [player(s) to teleport to you.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[传送取消!](#ff7e5e)'
|
||||
teleporting_other_complete: '[将 %1% 传送到 %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[将 %1% 传送到 ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[将](#00fb9a) [%1%](#00fb9a bold) [名玩家传送到您的位置…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[已发送传送请求, 传送到](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)'
|
||||
tpahere_request_sent: '[已发送传送请求, 请求](#00fb9a) [%1%](#00fb9a bold) [传送过来.](#00fb9a)'
|
||||
tpaall_request_sent: '[已发送传送请求, 请求](#00fb9a) [%1%](#00fb9a bold) [传送过来.](#00fb9a)'
|
||||
|
||||
@@ -9,6 +9,7 @@ teleporting_action_bar_cancelled: '[傳送取消!](#ff7e5e)'
|
||||
teleporting_other_complete: '[將 %1% 傳送到 %2%.](#00fb9a)'
|
||||
teleporting_other_complete_position: '[將 %1% 傳送到 ⚐ x: %2%, y: %3%, z: %4%.](#00fb9a)'
|
||||
teleporting_all_players: '[將](#00fb9a) [%1%](#00fb9a bold) [名玩家傳送到您的位置…](#00fb9a)'
|
||||
teleporting_random_generation: '[Finding a safe random position to teleport you to…](#00fb9a)'
|
||||
tpa_request_sent: '[您發送了一個傳送請求給](#00fb9a) [%1%](#00fb9a bold)'
|
||||
tpahere_request_sent: '[您發送了一個傳送請求, 請求](#00fb9a) [%1%](#00fb9a bold) [傳送過來.](#00fb9a)'
|
||||
tpaall_request_sent: '[你向所有玩家發送了一個傳送請求,要求](#00fb9a) [%1%](#00fb9a bold) [個玩家傳送到你身邊!.](#00fb9a)'
|
||||
|
||||
Reference in new issue
Block a user