From d78a49a2fdab24af15be624a5ebdf0fcabe52bbc Mon Sep 17 00:00:00 2001 From: Chudy#1294 <111442524+ChudziudgiToJa@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:39:36 +0000 Subject: [PATCH] add option to set specific world to random teleport feature --- .../implementation/PluginConfiguration.java | 8 ++++++++ .../randomteleport/RandomTeleportService.java | 20 +++++++++++-------- .../RandomTeleportSettings.java | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java index 4f7fd03d1..24d294272 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java @@ -108,6 +108,9 @@ public static class RandomTeleport implements RandomTeleportSettings { @Description("# Radius of random teleportation") public int randomTeleportRadius = 1000; + @Description("# Teleport to a specific world, if left empty it will teleport to the player's current world") + public String randomTeleportWorld = "world"; + @Description("# Number of attempts to teleport to a random location") public int randomTeleportAttempts = 10; @@ -116,6 +119,11 @@ public int randomTeleportRadius() { return this.randomTeleportRadius; } + @Override + public String randomTeleportWorld() { + return this.randomTeleportWorld; + } + @Override public int randomTeleportAttempts() { return this.randomTeleportAttempts; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportService.java index dae3d3479..8d6b70656 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportService.java @@ -3,11 +3,7 @@ import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import io.papermc.lib.PaperLib; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.WorldBorder; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; @@ -43,16 +39,24 @@ class RandomTeleportService { private static final int NETHER_MAX_HEIGHT = 127; private final RandomTeleportSettings randomTeleportSettings; - + private final Server server; private final Random random = new Random(); @Inject - RandomTeleportService(RandomTeleportSettings randomTeleportSettings) { + RandomTeleportService(RandomTeleportSettings randomTeleportSettings, Server server) { this.randomTeleportSettings = randomTeleportSettings; + this.server = server; } + CompletableFuture teleport(Player player) { - return this.getSafeRandomLocation(player.getWorld(), this.randomTeleportSettings.randomTeleportAttempts()) + World world = player.getWorld(); + + if (!this.randomTeleportSettings.randomTeleportWorld().isBlank()) { + world = this.server.getWorld(this.randomTeleportSettings.randomTeleportWorld()); + } + + return this.getSafeRandomLocation(world, this.randomTeleportSettings.randomTeleportAttempts()) .thenCompose(location -> PaperLib.teleportAsync(player, location).thenApply(success -> new TeleportResult(success, location))); } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettings.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettings.java index b113d764a..be0d5d5ef 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettings.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettings.java @@ -4,5 +4,7 @@ public interface RandomTeleportSettings { int randomTeleportRadius(); + String randomTeleportWorld(); + int randomTeleportAttempts(); }