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 24d294272..27066d831 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 @@ -94,6 +94,9 @@ public static class Teleport implements SpawnSettings { @Description("# Time of teleportation to spawn") public Duration teleportTimeToSpawn = Duration.ofSeconds(5); + @Description("# Include players with op in teleport to random player") + public boolean includeOpPlayersInRandomTeleport = false; + @Override public Duration teleportationTimeToSpawn() { return this.teleportTimeToSpawn; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/teleport/command/TeleportToRandomPlayerCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/teleport/command/TeleportToRandomPlayerCommand.java new file mode 100644 index 000000000..5101afe12 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/teleport/command/TeleportToRandomPlayerCommand.java @@ -0,0 +1,58 @@ +package com.eternalcode.core.feature.teleport.command; + +import com.eternalcode.annotations.scan.command.DescriptionDocs; +import com.eternalcode.core.configuration.implementation.PluginConfiguration; +import com.eternalcode.core.notice.NoticeService; +import com.eternalcode.core.util.RandomUtil; +import dev.rollczi.litecommands.command.execute.Execute; +import dev.rollczi.litecommands.command.permission.Permission; +import dev.rollczi.litecommands.command.route.Route; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import panda.std.Option; + +import java.util.List; +import java.util.stream.Collectors; + +@Route(name = "teleportorandomplayer", aliases = { "tprp" }) +@Permission("eternalcore.tprp") +public class TeleportToRandomPlayerCommand { + + private final Server server; + private final PluginConfiguration pluginConfiguration; + private final NoticeService noticeService; + + public TeleportToRandomPlayerCommand(Server server, PluginConfiguration pluginConfiguration, NoticeService noticeService) { + this.server = server; + this.pluginConfiguration = pluginConfiguration; + this.noticeService = noticeService; + } + + + @Execute + @DescriptionDocs(description = "Teleport to a random player on the server, with the option to filter op players") + void execute(Player player) { + List possibleTargetPlayers = this.server.getOnlinePlayers().stream() + .filter(target -> this.pluginConfiguration.teleport.includeOpPlayersInRandomTeleport || !target.isOp()) + .collect(Collectors.toList()); + + Option randomPlayerOption = RandomUtil.randomElement(possibleTargetPlayers); + + if (randomPlayerOption.isEmpty()) { + this.noticeService.create() + .player(player.getUniqueId()) + .notice(translation -> translation.teleport().randomPlayerNotFound()) + .send(); + return; + } + + Player randomPlayer = randomPlayerOption.get(); + + player.teleport(randomPlayer); + this.noticeService.create() + .player(player.getUniqueId()) + .notice(translation -> translation.teleport().teleportedToRandomPlayer()) + .placeholder("{PLAYER}", randomPlayer.getName()) + .send(); + } +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java index 2ed0dd1d8..1344e10ed 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java @@ -86,6 +86,10 @@ interface TeleportSection { Notice teleportedToLastLocation(); Notice teleportedSpecifiedPlayerLastLocation(); Notice lastLocationNoExist(); + + // teleport to random player command + Notice randomPlayerNotFound(); + Notice teleportedToRandomPlayer(); } // Random Teleport Section diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java index b6136d8ff..e7790e38e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java @@ -209,6 +209,11 @@ public static class ENTeleportSection implements TeleportSection { public Notice teleportedSpecifiedPlayerLastLocation = Notice.chat("Teleported {PLAYER} to the last location!"); @Description(" ") public Notice lastLocationNoExist = Notice.chat("Last location is not exist!"); + + @Description(" ") + public Notice randomPlayerNotFound = Notice.chat("No player found to teleport!"); + @Description({ " ", "# {PLAYER} - The player you were teleported" }) + public Notice teleportedToRandomPlayer = Notice.chat("Teleported to random player {PLAYER}!"); } @Description({ diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java index 81a66d3c5..686796b35 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java @@ -209,6 +209,11 @@ public static class PLTeleportSection implements TeleportSection { public Notice teleportedSpecifiedPlayerLastLocation = Notice.chat("Przeteleportowano gracza {PLAYER} do ostatniej lokalizacji!"); @Description(" ") public Notice lastLocationNoExist = Notice.chat("Nie ma zapisanej ostatniej lokalizacji!"); + + @Description(" ") + public Notice randomPlayerNotFound = Notice.chat("Nie można odnaleźć gracza do teleportacji!"); + @Description({ " ", "# {PLAYER} - Gracz do którego cię teleportowano" }) + public Notice teleportedToRandomPlayer = Notice.chat("Zostałeś losowo teleportowany do {PLAYER}!"); } @Description({