Skip to content

Commit 8482ae3

Browse files
committed
Improve UX - Add configurable formats for home list entries and integrate TranslationManager into HomeCommand and HomeAdminCommand for better customization.
1 parent c58bea3 commit 8482ae3

File tree

5 files changed

+52
-27
lines changed

5 files changed

+52
-27
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.eternalcode.core.feature.home.HomesSettings;
99
import com.eternalcode.core.injector.annotations.Inject;
1010
import com.eternalcode.core.notice.NoticeService;
11+
import com.eternalcode.core.translation.TranslationManager;
1112
import dev.rollczi.litecommands.annotations.argument.Arg;
1213
import dev.rollczi.litecommands.annotations.command.Command;
1314
import dev.rollczi.litecommands.annotations.context.Sender;
@@ -22,27 +23,28 @@
2223
@Permission("eternalcore.home")
2324
class HomeCommand {
2425

25-
private static final String CLICK_COMMAND_FORMATTED_LIST = "<click:run_command:'/home %s'>%s</click>";
26-
2726
private final HomesSettings homesSettings;
2827
private final NoticeService noticeService;
2928
private final HomeService homeService;
3029
private final HomeTeleportService homeTeleportService;
3130
private final PluginConfiguration pluginConfiguration;
31+
private final TranslationManager translationManager;
3232

3333
@Inject
3434
HomeCommand(
3535
HomesSettings homesSettings,
3636
NoticeService noticeService,
3737
HomeService homeService,
3838
HomeTeleportService homeTeleportService,
39-
PluginConfiguration pluginConfiguration
39+
PluginConfiguration pluginConfiguration,
40+
TranslationManager translationManager
4041
) {
4142
this.homesSettings = homesSettings;
4243
this.noticeService = noticeService;
4344
this.homeService = homeService;
4445
this.homeTeleportService = homeTeleportService;
4546
this.pluginConfiguration = pluginConfiguration;
47+
this.translationManager = translationManager;
4648
}
4749

4850
@Execute
@@ -59,8 +61,6 @@ void execute(@Sender Player player) {
5961
}
6062

6163
if (playerHomes.size() > 1) {
62-
String homes = this.formatHomeList(playerHomes);
63-
6464
Optional<Home> mainHome = playerHomes.stream()
6565
.filter(home -> home.getName().equals(this.homesSettings.defaultName()))
6666
.findFirst();
@@ -70,6 +70,8 @@ void execute(@Sender Player player) {
7070
return;
7171
}
7272

73+
String homes = this.formatHomeList(playerHomes);
74+
7375
this.noticeService.create()
7476
.player(player.getUniqueId())
7577
.notice(translation -> translation.home().homeList())
@@ -90,14 +92,12 @@ void execute(@Sender Player player, @Arg Home home) {
9092
}
9193

9294
private String formatHomeList(Collection<Home> homes) {
95+
String format = this.translationManager.getMessages().home().homeListEntryFormat();
9396
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-
));
97+
.map(home -> {
98+
String homeName = home.getName();
99+
return format.replace("{HOME}", homeName);
100+
})
101+
.collect(Collectors.joining(this.pluginConfiguration.format.separator));
102102
}
103103
}

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.eternalcode.core.feature.home.HomeManager;
77
import com.eternalcode.core.injector.annotations.Inject;
88
import com.eternalcode.core.notice.NoticeService;
9+
import com.eternalcode.core.translation.TranslationManager;
910
import com.eternalcode.core.viewer.Viewer;
1011
import dev.rollczi.litecommands.annotations.argument.Arg;
1112
import dev.rollczi.litecommands.annotations.command.Command;
@@ -25,21 +26,22 @@
2526
@Permission("eternalcore.home.admin")
2627
class HomeAdminCommand {
2728

28-
private static final String CLICK_SUGGEST_COMMAND_FORMATTED_LIST = "<click:run_command:'/homeadmin home %s %s'>%s</click>";
29-
3029
private final HomeManager homeManager;
3130
private final NoticeService noticeService;
3231
private final PluginConfiguration pluginConfiguration;
32+
private final TranslationManager translationManager;
3333

3434
@Inject
3535
public HomeAdminCommand(
3636
HomeManager homeManager,
3737
NoticeService noticeService,
38-
PluginConfiguration pluginConfiguration
38+
PluginConfiguration pluginConfiguration,
39+
TranslationManager translationManager
3940
) {
4041
this.homeManager = homeManager;
4142
this.noticeService = noticeService;
4243
this.pluginConfiguration = pluginConfiguration;
44+
this.translationManager = translationManager;
4345
}
4446

4547
@Execute(name = "sethome")
@@ -180,15 +182,12 @@ private void sendHomeListNotice(Viewer viewer, Collection<Home> homes, OfflinePl
180182
}
181183

182184
private String formatHomeList(Collection<Home> homes, String playerName) {
185+
String format = this.translationManager.getMessages().home().homeListEntryFormatAsAdmin();
186+
183187
return homes.stream()
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-
));
188+
.map(home -> format
189+
.replace("{HOME}", home.getName())
190+
.replace("{PLAYER}", playerName))
191+
.collect(Collectors.joining(this.pluginConfiguration.format.separator));
193192
}
194193
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/home/messages/ENHomeMessages.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
public class ENHomeMessages extends OkaeriConfig implements HomeMessages {
1212
@Comment("# {HOMES} - List of homes (separated by commas)")
1313
Notice homeList = Notice.chat("<color:#9d6eef>► <white>Available homes: <color:#9d6eef>{HOMES}");
14+
@Comment({
15+
" ",
16+
"# Format for single home entry in user's home list. Set to \"\" if you don't want this feature.",
17+
"# {HOME} - Home name"
18+
})
19+
String homeListEntryFormat = "<hover:show_text:'<gray>Click to teleport'><click:run_command:'/home {HOME}'>{HOME}</click></hover>";
1420

1521
@Comment({ " ", "# {HOME} - Home name" })
1622
Notice create = Notice.chat("<color:#9d6eef>► <white>Home <color:#9d6eef>{HOME} <white>has been created.");
@@ -33,8 +39,13 @@ public class ENHomeMessages extends OkaeriConfig implements HomeMessages {
3339
Notice createAsAdmin = Notice.chat("<color:#9d6eef>► <white>Home <color:#9d6eef>{HOME} <white>has been created for <color:#9d6eef>{PLAYER}<white>.");
3440
Notice deleteAsAdmin = Notice.chat("<color:#9d6eef>► <white>Home <color:#9d6eef>{HOME} <white>has been deleted for <color:#9d6eef>{PLAYER}<white>.");
3541
Notice homeListAsAdmin = Notice.chat("<color:#9d6eef>► <white>Available homes for <color:#9d6eef>{PLAYER}<white>: <color:#9d6eef>{HOMES}");
36-
Notice noHomesOnListAsAdmin =
37-
Notice.chat("<red>► <dark_red>Player <red>{PLAYER} <dark_red>does not have any homes!");
42+
@Comment({
43+
" ",
44+
"# Format for single home entry in admin's home list. Set to \"\" if you don't want this feature.",
45+
"# {HOME} - Home name, {PLAYER} - Player name"
46+
})
47+
String homeListEntryFormatAsAdmin = "<hover:show_text:'<gray>Click to teleport'><click:run_command:'/homeadmin home {PLAYER} {HOME}'>{HOME}</click></hover>";
48+
Notice noHomesOnListAsAdmin = Notice.chat("<red>► <dark_red>Player <red>{PLAYER} <dark_red>does not have any homes!");
3849

3950
@Comment({
4051
" ",

eternalcore-core/src/main/java/com/eternalcode/core/feature/home/messages/HomeMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
public interface HomeMessages {
66
Notice homeList();
7+
String homeListEntryFormat();
78
Notice create();
89
Notice delete();
910
Notice limit();
@@ -16,6 +17,7 @@ public interface HomeMessages {
1617
Notice createAsAdmin();
1718
Notice deleteAsAdmin();
1819
Notice homeListAsAdmin();
20+
String homeListEntryFormatAsAdmin();
1921
Notice noHomesOnListAsAdmin();
2022
Notice teleportedAsAdmin();
2123
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/home/messages/PLHomeMessages.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
public class PLHomeMessages extends OkaeriConfig implements HomeMessages {
1212
@Comment({ " ", "# {HOMES} - Lista domów" })
1313
Notice homeList = Notice.chat("<color:#9d6eef>► <white>Lista domów: <color:#9d6eef>{HOMES}!");
14+
@Comment({
15+
" ",
16+
"# Format pojedynczego wpisu w liście domów gracza. Ustaw na \"\" jeśli nie chcesz tego feature'a.",
17+
"# {HOME} - Nazwa domu"
18+
})
19+
String homeListEntryFormat = "<hover:show_text:'<gray>Kliknij aby się teleportować'><click:run_command:'/home {HOME}'>{HOME}</click></hover>";
20+
1421

1522
@Comment({ " ", "# {HOME} - Nazwa domu" })
1623
Notice create = Notice.chat("<color:#9d6eef>► <white>Stworzono dom o nazwie <color:#9d6eef>{HOME}<white>!");
@@ -39,6 +46,12 @@ public class PLHomeMessages extends OkaeriConfig implements HomeMessages {
3946
"<color:#9d6eef>► <white>Usunięto dom <color:#9d6eef>{HOME} <white>dla gracza <color:#9d6eef>{PLAYER}<white>!");
4047
Notice homeListAsAdmin = Notice
4148
.chat("<color:#9d6eef>► <white>Lista domów gracza <color:#9d6eef>{PLAYER}<white>: <color:#9d6eef>{HOMES}!");
49+
@Comment({
50+
" ",
51+
"# Format pojedynczego wpisu w liście domów (widok admina). Ustaw na \"\" jeśli nie chcesz tego feature'a.",
52+
"# {HOME} - Nazwa domu, {PLAYER} - Nick gracza"
53+
})
54+
String homeListEntryFormatAsAdmin = "<hover:show_text:'<gray>Kliknij aby się teleportować'><click:run_command:'/homeadmin home {PLAYER} {HOME}'>{HOME}</click></hover>";
4255
Notice noHomesOnListAsAdmin = Notice.chat("<red>► <dark_red>Gracz <red>{PLAYER} <dark_red>nie posiada domów.");
4356

4457
@Comment({

0 commit comments

Comments
 (0)