-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add teleport to random player feature * Remove Player#getLocation from teleport method and add missing translations in PlTranslation. * Update TeleportToRandomPlayerCommand.java * Follow @imDMK sugggestions. * Random class was replaced with a RandomUtil function for randomly selecting a player. * Rename 'NoPlayerToRandomTeleport' notice to 'RandomPlayerNotFound'
- Loading branch information
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ain/java/com/eternalcode/core/feature/teleport/command/TeleportToRandomPlayerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Player> possibleTargetPlayers = this.server.getOnlinePlayers().stream() | ||
.filter(target -> this.pluginConfiguration.teleport.includeOpPlayersInRandomTeleport || !target.isOp()) | ||
.collect(Collectors.toList()); | ||
|
||
Option<Player> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters