Skip to content

Commit c58bea3

Browse files
committed
Add auto click command formatting as private static fields.
1 parent 2475b64 commit c58bea3

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/home/command/HomeCommand.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.eternalcode.core.feature.home.command;
22

33
import com.eternalcode.annotations.scan.command.DescriptionDocs;
4+
import com.eternalcode.core.configuration.implementation.PluginConfiguration;
45
import com.eternalcode.core.feature.home.Home;
56
import com.eternalcode.core.feature.home.HomeService;
67
import com.eternalcode.core.feature.home.HomeTeleportService;
@@ -14,28 +15,34 @@
1415
import dev.rollczi.litecommands.annotations.permission.Permission;
1516
import java.util.Collection;
1617
import java.util.Optional;
18+
import java.util.stream.Collectors;
1719
import org.bukkit.entity.Player;
1820

1921
@Command(name = "home")
2022
@Permission("eternalcore.home")
2123
class HomeCommand {
2224

25+
private static final String CLICK_COMMAND_FORMATTED_LIST = "<click:run_command:'/home %s'>%s</click>";
26+
2327
private final HomesSettings homesSettings;
2428
private final NoticeService noticeService;
2529
private final HomeService homeService;
2630
private final HomeTeleportService homeTeleportService;
31+
private final PluginConfiguration pluginConfiguration;
2732

2833
@Inject
2934
HomeCommand(
3035
HomesSettings homesSettings,
3136
NoticeService noticeService,
3237
HomeService homeService,
33-
HomeTeleportService homeTeleportService
38+
HomeTeleportService homeTeleportService,
39+
PluginConfiguration pluginConfiguration
3440
) {
3541
this.homesSettings = homesSettings;
3642
this.noticeService = noticeService;
3743
this.homeService = homeService;
3844
this.homeTeleportService = homeTeleportService;
45+
this.pluginConfiguration = pluginConfiguration;
3946
}
4047

4148
@Execute
@@ -52,11 +59,7 @@ void execute(@Sender Player player) {
5259
}
5360

5461
if (playerHomes.size() > 1) {
55-
String homes = String.join(
56-
", ",
57-
playerHomes.stream()
58-
.map(Home::getName)
59-
.toList());
62+
String homes = this.formatHomeList(playerHomes);
6063

6164
Optional<Home> mainHome = playerHomes.stream()
6265
.filter(home -> home.getName().equals(this.homesSettings.defaultName()))
@@ -85,4 +88,16 @@ void execute(@Sender Player player) {
8588
void execute(@Sender Player player, @Arg Home home) {
8689
this.homeTeleportService.teleport(player, home);
8790
}
91+
92+
private String formatHomeList(Collection<Home> homes) {
93+
return homes.stream()
94+
.map(home -> String.format(
95+
CLICK_COMMAND_FORMATTED_LIST,
96+
home.getName(),
97+
home.getName()
98+
))
99+
.collect(Collectors.joining(
100+
this.pluginConfiguration.format.separator
101+
));
102+
}
88103
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/home/homeadmin/HomeAdminCommand.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
@Permission("eternalcore.home.admin")
2626
class HomeAdminCommand {
2727

28+
private static final String CLICK_SUGGEST_COMMAND_FORMATTED_LIST = "<click:run_command:'/homeadmin home %s %s'>%s</click>";
29+
2830
private final HomeManager homeManager;
2931
private final NoticeService noticeService;
3032
private final PluginConfiguration pluginConfiguration;
@@ -45,7 +47,7 @@ public HomeAdminCommand(
4547
void setHome(
4648
@Sender Player sender,
4749
@Arg("target") OfflinePlayer targetPlayer,
48-
@Arg("home name") String homeName,
50+
@Arg("home") String homeName,
4951
@Arg Optional<Location> location
5052
) {
5153
if (!this.hasPlayerEverJoined(targetPlayer)) {
@@ -166,19 +168,27 @@ private void sendNoHomesNotice(Viewer viewer, OfflinePlayer targetPlayer) {
166168
}
167169

168170
private void sendHomeListNotice(Viewer viewer, Collection<Home> homes, OfflinePlayer targetPlayer) {
169-
String formattedHomes = this.formatHomeList(homes);
171+
String playerName = targetPlayer.getName();
172+
String formattedHomes = this.formatHomeList(homes, playerName);
170173

171174
this.noticeService.create()
172175
.notice(translation -> translation.home().homeListAsAdmin())
173176
.placeholder("{HOMES}", formattedHomes)
174-
.placeholder("{PLAYER}", targetPlayer.getName())
177+
.placeholder("{PLAYER}", playerName)
175178
.viewer(viewer)
176179
.send();
177180
}
178181

179-
private String formatHomeList(Collection<Home> homes) {
182+
private String formatHomeList(Collection<Home> homes, String playerName) {
180183
return homes.stream()
181-
.map(Home::getName)
182-
.collect(Collectors.joining(this.pluginConfiguration.format.separator));
184+
.map(home -> String.format(
185+
CLICK_SUGGEST_COMMAND_FORMATTED_LIST,
186+
playerName,
187+
home.getName(),
188+
home.getName()
189+
))
190+
.collect(Collectors.joining(
191+
this.pluginConfiguration.format.separator
192+
));
183193
}
184194
}

0 commit comments

Comments
 (0)