Skip to content

Commit d405285

Browse files
authored
GH-1034 Add teleport-here all and teleport-here ask-to-all functionality (#1074)
* Add teleport-here all and teleport-here ask-to-all functionality, add missing @DescriptionDocs annotation * Align with Gemini's suggestions * Fix double placeholder in tpaSentMessage * Change @context annotation to @sender, remove misleading shortcut * Update TeleportHereCommand.java * Update TpaHereCommand.java
1 parent 5ea44e7 commit d405285

File tree

8 files changed

+75
-7
lines changed

8 files changed

+75
-7
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/teleport/command/TeleportHereCommand.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.eternalcode.core.feature.teleport.command;
22

33
import com.eternalcode.annotations.scan.command.DescriptionDocs;
4+
import com.eternalcode.core.feature.teleport.TeleportService;
45
import com.eternalcode.core.injector.annotations.Inject;
56
import com.eternalcode.core.notice.NoticeService;
6-
import com.eternalcode.core.feature.teleport.TeleportService;
77
import dev.rollczi.litecommands.annotations.argument.Arg;
8-
import dev.rollczi.litecommands.annotations.context.Context;
8+
import dev.rollczi.litecommands.annotations.command.Command;
9+
import dev.rollczi.litecommands.annotations.context.Sender;
910
import dev.rollczi.litecommands.annotations.execute.Execute;
1011
import dev.rollczi.litecommands.annotations.permission.Permission;
11-
import dev.rollczi.litecommands.annotations.command.Command;
12+
import dev.rollczi.litecommands.annotations.shortcut.Shortcut;
1213
import org.bukkit.entity.Player;
1314

1415
@Command(name = "tphere", aliases = { "s" })
@@ -26,7 +27,7 @@ class TeleportHereCommand {
2627

2728
@Execute
2829
@DescriptionDocs(description = "Teleport player to you", arguments = "<player>")
29-
void tpHere(@Context Player sender, @Arg Player target) {
30+
void tpHere(@Sender Player sender, @Arg Player target) {
3031
this.teleportService.teleport(target, sender.getLocation());
3132
this.noticeService.create()
3233
.notice(translation -> translation.teleport().teleportedPlayerToPlayer())
@@ -36,4 +37,22 @@ void tpHere(@Context Player sender, @Arg Player target) {
3637
.send();
3738
}
3839

40+
@Execute(name = "-all", aliases = { "*" })
41+
@Shortcut("tpall")
42+
@Permission("eternalcore.tphere.all")
43+
@DescriptionDocs(description = "Teleport all players to you")
44+
void tpHereAll(@Sender Player sender) {
45+
for (Player player : sender.getServer().getOnlinePlayers()) {
46+
if (player.getUniqueId().equals(sender.getUniqueId())) {
47+
continue;
48+
}
49+
this.teleportService.teleport(player, sender.getLocation());
50+
}
51+
52+
this.noticeService.create()
53+
.notice(translation -> translation.teleport().teleportedAllToPlayer())
54+
.player(sender.getUniqueId())
55+
.send();
56+
}
57+
3958
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/messages/ENTeleportRequestMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public class ENTeleportRequestMessages extends OkaeriConfig implements TeleportR
1313
public Notice tpaAlreadySentMessage =
1414
Notice.chat("<red>✘ <dark_red>You have already sent a teleportation request!");
1515
public Notice tpaSentMessage =
16-
Notice.chat("<green>► <white>You have sent a request for player <green>{PLAYER}<white>{PLAYER} to teleport to you!");
16+
Notice.chat("<green>► <white>You have sent a request for player <green>{PLAYER}<white> to teleport to you!");
1717

1818
public Notice tpaHereSent = Notice.chat("<green>► <white>You have sent a request for teleportation to you for a player: <green>{PLAYER}<white>!");
19+
public Notice tpaHereSentToAll = Notice.chat("<green>► <white>You have sent a request for teleportation to all players!");
1920
public Notice tpaHereReceived = Notice.builder()
2021
.chat("<green>► <white>You have received a request for teleportation TO a player: <gray>{PLAYER}<green>!")
2122
.chat(

eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/messages/PLTeleportRequestMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class PLTeleportRequestMessages extends OkaeriConfig implements TeleportR
1616
Notice.chat("<green>► <white>Wysłałeś prośbę o teleportację do gracza: <green>{PLAYER}<white>!");
1717

1818
public Notice tpaHereSent = Notice.chat("<green>► <white>Wysłałeś prośbę o teleportację gracza <green>{PLAYER}<white> do twojej lokalizacji!");
19+
public Notice tpaHereSentToAll = Notice.chat("<green>► <white>Wysłano prośbę o teleportację do wszystkich graczy!");
1920
public Notice tpaHereReceived = Notice.builder()
2021
.chat("<green>► <white>Otrzymałeś prośbę o teleportację do gracza: <green>{PLAYER}<white>!")
2122
.chat(

eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/messages/TeleportRequestMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface TeleportRequestMessages {
1010
Notice tpaTargetIgnoresYou();
1111

1212
Notice tpaHereSent();
13+
Notice tpaHereSentToAll();
1314
Notice tpaHereReceived();
1415

1516
Notice tpaDenyNoRequestMessage();

eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/self/TpaHereCommand.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.eternalcode.core.feature.teleportrequest.self;
22

3+
import com.eternalcode.annotations.scan.command.DescriptionDocs;
34
import com.eternalcode.core.feature.ignore.IgnoreService;
45
import com.eternalcode.core.injector.annotations.Inject;
56
import com.eternalcode.core.notice.NoticeService;
67
import dev.rollczi.litecommands.annotations.argument.Arg;
78
import dev.rollczi.litecommands.annotations.command.Command;
8-
import dev.rollczi.litecommands.annotations.context.Context;
9+
import dev.rollczi.litecommands.annotations.context.Sender;
910
import dev.rollczi.litecommands.annotations.execute.Execute;
1011
import dev.rollczi.litecommands.annotations.permission.Permission;
1112
import org.bukkit.entity.Player;
@@ -28,7 +29,8 @@ class TpaHereCommand {
2829
}
2930

3031
@Execute
31-
void execute(@Context Player sender, @Arg Player target) {
32+
@DescriptionDocs(description = "Send teleport request to player to teleport to you", arguments = "<player>")
33+
void execute(@Sender Player sender, @Arg Player target) {
3234
if (sender.equals(target)) {
3335
this.noticeService.player(sender.getUniqueId() , translation -> translation.tpa().tpaSelfMessage());
3436

@@ -68,6 +70,43 @@ void execute(@Context Player sender, @Arg Player target) {
6870
});
6971
}
7072

73+
@Execute(name = "-all", aliases = { "*" })
74+
@Permission("eternalcore.tpahere.all")
75+
@DescriptionDocs(description = "Send teleport request to all online players to teleport to you")
76+
void executeAll(@Sender Player sender) {
77+
for (Player target : sender.getServer().getOnlinePlayers()) {
78+
if (target.getUniqueId().equals(sender.getUniqueId())) {
79+
continue;
80+
}
81+
82+
if (this.requestService.hasRequest(sender.getUniqueId(), target.getUniqueId())) {
83+
continue;
84+
}
85+
86+
this.isIgnoring(target, sender).thenAccept(isIgnoring -> {
87+
if (isIgnoring) {
88+
return;
89+
}
90+
91+
this.noticeService.create()
92+
.player(target.getUniqueId())
93+
.notice(translation -> translation.tpa().tpaHereReceived())
94+
.placeholder("{PLAYER}", sender.getName())
95+
.send();
96+
97+
this.requestService.createRequest(sender.getUniqueId(), target.getUniqueId());
98+
99+
});
100+
}
101+
102+
this.noticeService.create()
103+
.player(sender.getUniqueId())
104+
.notice(translation -> translation.tpa().tpaHereSentToAll())
105+
.send();
106+
}
107+
108+
109+
71110
private CompletableFuture<Boolean> isIgnoring(Player target, Player sender) {
72111
return this.ignoreService.isIgnored(target.getUniqueId(), sender.getUniqueId());
73112
}

eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface TeleportSection {
4040
Notice teleportedToPlayer();
4141
Notice teleportedPlayerToPlayer();
4242
Notice teleportedToHighestBlock();
43+
Notice teleportedAllToPlayer();
4344

4445
// Task
4546
Notice teleportTimerFormat();

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ public static class ENTeleportSection extends OkaeriConfig implements TeleportSe
182182
@Comment({"# {Y} - Y coordinate of the highest block"})
183183
public Notice teleportedToHighestBlock = Notice.chat("<green>► <white>Teleported successfully to the highest block! (Y: {Y})");
184184

185+
@Comment(" ")
186+
public Notice teleportedAllToPlayer = Notice.chat("<green>► <white>All players have been teleported to you!");
187+
185188
// Task
186189
@Comment({"# {TIME} - Teleportation time"})
187190
public Notice teleportTimerFormat = Notice.actionbar("<green>► <white>Teleporting in <green>{TIME}");

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ public static class PLTeleportSection extends OkaeriConfig implements TeleportSe
179179
@Comment({"# {Y} - Koordynat Y najwyżej położonego bloku"})
180180
public Notice teleportedToHighestBlock = Notice.chat("<green>► <white>Pomyślnie przeteleportowano do najwyższego bloku! (Y: {Y})");
181181

182+
@Comment(" ")
183+
public Notice teleportedAllToPlayer = Notice.chat("<green>► <white>Przeteleportowano wszystkich graczy do ciebie!");
184+
182185
// Task
183186
@Comment({"# {TIME} - Czas teleportacji"})
184187
public Notice teleportTimerFormat = Notice.actionbar("<green>► <white>Teleportacja za <green>{TIME}");

0 commit comments

Comments
 (0)