Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.core.configuration;

import com.eternalcode.core.configuration.migration.M0001_MoveRandomPlayerTeleportToOwnSection;
import com.eternalcode.core.configuration.serializer.LanguageSerializer;
import com.eternalcode.core.configuration.transformer.PositionTransformer;
import com.eternalcode.core.injector.annotations.Inject;
Expand Down Expand Up @@ -61,6 +62,9 @@ public <T extends OkaeriConfig & EternalConfigurationFile> T load(T config) {
config.withConfigurer(yamlConfigurer)
.withSerdesPack(serdesPack)
.withBindFile(file)
.migrate(
new M0001_MoveRandomPlayerTeleportToOwnSection()
)
.withRemoveOrphans(true)
.saveDefaults()
.load(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.eternalcode.core.configuration.migration;

import static eu.okaeri.configs.migrate.ConfigMigrationDsl.move;

import eu.okaeri.configs.migrate.builtin.NamedMigration;

public class M0001_MoveRandomPlayerTeleportToOwnSection extends NamedMigration {

public M0001_MoveRandomPlayerTeleportToOwnSection() {
super(
"0001-move-random-player-teleport-to-own-section",

move("teleport.randomPlayerNotFound", "teleportToRandomPlayer.randomPlayerNotFound"),
move("teleport.teleportedToRandomPlayer", "teleportToRandomPlayer.teleportedToRandomPlayer")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.util.concurrent.TimeUnit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;

import java.time.Instant;
import java.util.Comparator;
Expand Down Expand Up @@ -40,6 +43,22 @@ public Player findLeastRecentlyTeleportedPlayer(Player sender) {
.orElse(null);
}

@Nullable
public Player findLeastRecentlyTeleportedPlayerByY(Player sender, int minY, int maxY) {
UUID senderId = sender.getUniqueId();
return this.server.getOnlinePlayers().stream()
.filter(target -> !target.equals(sender))
.filter(target -> this.pluginConfiguration.teleport.includeOpPlayersInRandomTeleport || !target.isOp())
.filter(target -> this.isPlayerInYRange(target, minY, maxY))
.min(Comparator.comparing(target -> this.getTeleportationHistory(target, senderId)))
.orElse(null);
}

private boolean isPlayerInYRange(Player player, int minY, int maxY) {
double playerY = player.getLocation().getY();
return playerY >= minY && playerY <= maxY;
}

private Instant getTeleportationHistory(Player target, UUID senderId) {
return this.teleportationHistory.get(new HistoryKey(senderId, target.getUniqueId()), key -> Instant.EPOCH);
}
Expand All @@ -50,5 +69,4 @@ public void updateTeleportationHistory(Player sender, Player target) {

private record HistoryKey(UUID sender, UUID target) {
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
Expand Down Expand Up @@ -34,15 +35,15 @@ void execute(@Context Player player) {
if (targetPlayer != null && targetPlayer.equals(player)) {
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.teleport().randomPlayerNotFound())
.notice(translation -> translation.teleportToRandomPlayer().randomPlayerNotFound())
.send();
return;
}

if (targetPlayer == null) {
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.teleport().randomPlayerNotFound())
.notice(translation -> translation.teleportToRandomPlayer().randomPlayerNotFound())
.send();
return;
}
Expand All @@ -53,8 +54,46 @@ void execute(@Context Player player) {

this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.teleport().teleportedToRandomPlayer())
.notice(translation -> translation.teleportToRandomPlayer().teleportedToRandomPlayer())
.placeholder("{PLAYER}", targetPlayer.getName())
.send();
}
}

/**
* Teleports the player to a random player within a specific Y-level range.
* Useful for finding players in caves, spotting potential x-rayers,
* or quickly locating players in general.
*/
@Execute
@DescriptionDocs(description = "Teleport to a player who is within specified Y range and hasn't been teleported to recently")
void executeWithYRange(@Context Player player, @Arg int minY, @Arg int maxY) {
Player targetPlayer = this.teleportRandomPlayerService.findLeastRecentlyTeleportedPlayerByY(player, minY, maxY);

if (targetPlayer != null && targetPlayer.equals(player)) {
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.teleportToRandomPlayer().randomPlayerInRangeNotFound())
.send();
return;
}

if (targetPlayer == null) {
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.teleportToRandomPlayer().randomPlayerInRangeNotFound())
.send();
return;
}

this.teleportRandomPlayerService.updateTeleportationHistory(player, targetPlayer);

PaperLib.teleportAsync(player, targetPlayer.getLocation());

this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.teleportToRandomPlayer().teleportedToRandomPlayerInRange())
.placeholder("{PLAYER}", targetPlayer.getName())
.placeholder("{Y}", String.valueOf((int) targetPlayer.getLocation().getY()))
.send();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.eternalcode.core.feature.teleportrandomplayer.messages;

import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
@Accessors(fluent = true)
public class ENTeleportToRandomPlayerMessages extends OkaeriConfig implements TeleportToRandomPlayerMessages {
public Notice randomPlayerNotFound =
Notice.chat("<red>✘ <dark_red>No player found to teleport!");

public Notice teleportedToRandomPlayer =
Notice.chat("<green>► <white>Teleported to random player <green>{PLAYER}<white>!");

public Notice randomPlayerInRangeNotFound =
Notice.chat("<red>✘ <dark_red>No player found in range to teleport!");

public Notice teleportedToRandomPlayerInRange =
Notice.chat("<green>► <white>Teleported to a random player in range: <green>{PLAYER}<white>!");

public Notice teleportedToRandomPlayerInRangeNotFound =
Notice.chat("<red>✘ <dark_red>No player found in range to teleport!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eternalcode.core.feature.teleportrandomplayer.messages;

import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
@Accessors(fluent = true)
public class PLTeleportToRandomPlayerMessages extends OkaeriConfig implements TeleportToRandomPlayerMessages {

public Notice randomPlayerNotFound =
Notice.chat("<red>✘ <dark_red>Nie można odnaleźć gracza do teleportacji!");
public Notice teleportedToRandomPlayer = Notice.chat("<green>► <white>Zostałeś losowo teleportowany do "
+ "<green>{PLAYER}<white>!");
public Notice randomPlayerInRangeNotFound =
Notice.chat("<red>✘ <dark_red>Nie można odnaleźć gracza w zasięgu do teleportacji!");
public Notice teleportedToRandomPlayerInRange =
Notice.chat("<green>► <white>Zostałeś losowo teleportowany do gracza w zasięgu: "
+ "<green>{PLAYER}<white>!");
public Notice teleportedToRandomPlayerInRangeNotFound =
Notice.chat("<red>✘ <dark_red>Nie można odnaleźć gracza w zasięgu do teleportacji! ");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.eternalcode.core.feature.teleportrandomplayer.messages;

import com.eternalcode.multification.notice.Notice;

public interface TeleportToRandomPlayerMessages {
// teleport to random player command
Notice randomPlayerNotFound();
Notice teleportedToRandomPlayer();
Notice randomPlayerInRangeNotFound();
Notice teleportedToRandomPlayerInRange();
Notice teleportedToRandomPlayerInRangeNotFound();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.eternalcode.core.feature.signeditor.messages.SignEditorMessages;
import com.eternalcode.core.feature.spawn.messages.SpawnMessages;
import com.eternalcode.core.feature.sudo.messages.SudoMessages;
import com.eternalcode.core.feature.teleportrandomplayer.messages.TeleportToRandomPlayerMessages;
import com.eternalcode.core.feature.teleportrequest.messages.TeleportRequestMessages;
import com.eternalcode.core.feature.time.messages.TimeAndWeatherMessages;
import com.eternalcode.core.feature.troll.demoscreen.messages.DemoScreenMessages;
Expand Down Expand Up @@ -56,10 +57,6 @@ interface TeleportSection {
Notice teleportedToLastLocation();
Notice teleportedSpecifiedPlayerLastLocation();
Notice lastLocationNoExist();

// teleport to random player command
Notice randomPlayerNotFound();
Notice teleportedToRandomPlayer();
}

interface ChatSection {
Expand Down Expand Up @@ -211,6 +208,8 @@ interface TrollSection {
SudoMessages sudo();
// Teleport Section
TeleportSection teleport();
// teleport to random player section.
TeleportToRandomPlayerMessages teleportToRandomPlayer();
// Random Teleport Section
RandomTeleportMessages randomTeleport();
// Chat Section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.eternalcode.core.feature.signeditor.messages.ENSignEditorMessages;
import com.eternalcode.core.feature.spawn.messages.ENSpawnMessages;
import com.eternalcode.core.feature.sudo.messages.ENSudoMessages;
import com.eternalcode.core.feature.teleportrandomplayer.messages.ENTeleportToRandomPlayerMessages;
import com.eternalcode.core.feature.teleportrequest.messages.ENTeleportRequestMessages;
import com.eternalcode.core.feature.time.messages.ENTimeAndWeatherMessages;
import com.eternalcode.core.feature.troll.demoscreen.messages.ENDemoScreenMessages;
Expand Down Expand Up @@ -211,6 +212,12 @@ public static class ENTeleportSection extends OkaeriConfig implements TeleportSe
public Notice teleportedToRandomPlayer = Notice.chat("<green>► <white>Teleported to random player <green>{PLAYER}<white>!");
}

@Comment({
" ",
"# This section is responsible for the messages of the /tprp command",
})
public ENTeleportToRandomPlayerMessages teleportToRandomPlayer = new ENTeleportToRandomPlayerMessages();

@Comment({
" ",
"# This section is responsible for messages related to random teleport",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.eternalcode.core.feature.signeditor.messages.PLSignEditorMessages;
import com.eternalcode.core.feature.spawn.messages.PLSpawnMessages;
import com.eternalcode.core.feature.sudo.messages.PLSudoMessages;
import com.eternalcode.core.feature.teleportrandomplayer.messages.PLTeleportToRandomPlayerMessages;
import com.eternalcode.core.feature.teleportrequest.messages.PLTeleportRequestMessages;
import com.eternalcode.core.feature.time.messages.PLTimeAndWeatherMessages;
import com.eternalcode.core.feature.troll.demoscreen.messages.PLDemoScreenMessages;
Expand Down Expand Up @@ -205,13 +206,14 @@ public static class PLTeleportSection extends OkaeriConfig implements TeleportSe
public Notice teleportedSpecifiedPlayerLastLocation = Notice.chat("<green>► <white>Przeteleportowano gracza <green>{PLAYER} <white>do ostatniej lokalizacji!");
@Comment(" ")
public Notice lastLocationNoExist = Notice.chat("<red>✘ <dark_red>Nie ma zapisanej ostatniej lokalizacji!");

@Comment(" ")
public Notice randomPlayerNotFound = Notice.chat("<red>✘ <dark_red>Nie można odnaleźć gracza do teleportacji!");
@Comment({" ", "# {PLAYER} - Gracz do którego cię teleportowano"})
public Notice teleportedToRandomPlayer = Notice.chat("<green>► <white>Zostałeś losowo teleportowany do <green>{PLAYER}<white>!");
}

@Comment({
" ",
"# Ta sekcja odpowiada za wiadomości komendy /tprp"
})
public PLTeleportToRandomPlayerMessages teleportToRandomPlayer = new PLTeleportToRandomPlayerMessages();

@Comment({
" ",
"# Ta sekcja odpowiada za edycję komunikatów losowej teleportacji",
Expand Down