Skip to content

Commit da1a20f

Browse files
Jakubk15vLuckyyy
andauthored
GH-991 Add MOTD feature (#1094)
* Add MOTD feature * fix example motd content * Review. * Fix. * Move MOTD to message files * Fix. * Remove duplicated title. --------- Co-authored-by: vLuckyyy <[email protected]>
1 parent 46db3a3 commit da1a20f

File tree

8 files changed

+125
-14
lines changed

8 files changed

+125
-14
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/joinmessage/PlayerJoinMessageController.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ void onPlayerJoin(PlayerJoinEvent event) {
4141
.send();
4242
}
4343

44-
this.noticeService.create()
45-
.notice(translation -> translation.event().welcome())
46-
.placeholder("{PLAYER}", player.getName())
47-
.player(player.getUniqueId())
48-
.sendAsync();
49-
5044
event.setJoinMessage(StringUtils.EMPTY);
5145

5246
this.noticeService.create()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.eternalcode.core.feature.motd;
2+
3+
import com.eternalcode.core.feature.motd.messages.MotdMessages;
4+
import com.eternalcode.core.injector.annotations.Inject;
5+
import com.eternalcode.core.injector.annotations.component.Controller;
6+
import com.eternalcode.core.notice.NoticeService;
7+
import com.eternalcode.core.placeholder.Placeholders;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.event.EventHandler;
10+
import org.bukkit.event.Listener;
11+
import org.bukkit.event.player.PlayerJoinEvent;
12+
13+
@SuppressWarnings("Convert2MethodRef")
14+
@Controller
15+
class MotdJoinController implements Listener {
16+
17+
private static final Placeholders<Player> PLACEHOLDERS = Placeholders.<Player>builder()
18+
.with("{PLAYER}", player -> player.getName())
19+
.with("{TIME}", player -> String.valueOf(player.getWorld().getTime()))
20+
.with("{WORLD}", player -> player.getWorld().getName())
21+
.build();
22+
23+
private final NoticeService noticeService;
24+
private final MotdMessages motdMessages;
25+
26+
@Inject
27+
MotdJoinController(NoticeService noticeService, MotdMessages motdMessages) {
28+
this.noticeService = noticeService;
29+
this.motdMessages = motdMessages;
30+
}
31+
32+
@EventHandler
33+
void onPlayerJoin(PlayerJoinEvent event) {
34+
Player player = event.getPlayer();
35+
36+
this.noticeService.create()
37+
.notice(this.motdMessages.motdContent())
38+
.player(player.getUniqueId())
39+
.formatter(PLACEHOLDERS.toFormatter(player))
40+
.send();
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.eternalcode.core.feature.motd.messages;
2+
3+
import com.eternalcode.multification.bukkit.notice.BukkitNotice;
4+
import com.eternalcode.multification.notice.Notice;
5+
import eu.okaeri.configs.OkaeriConfig;
6+
import eu.okaeri.configs.annotation.Comment;
7+
import lombok.Getter;
8+
import lombok.experimental.Accessors;
9+
import org.bukkit.Sound;
10+
11+
import java.util.List;
12+
13+
@Getter
14+
@Accessors(fluent = true)
15+
public class ENMotdMessages extends OkaeriConfig implements MotdMessages {
16+
17+
@Comment("# Message of the Day (MOTD) content that will be sent to players when they join the server.")
18+
@Comment("# Out of the box supported placeholders: {PLAYER}, {WORLD}, {TIME}")
19+
@Comment("# You can add your own placeholders using the PlaceholderAPI.")
20+
@Comment("# You can check our Notification Generator: https://www.eternalcode.pl/notification-generator")
21+
public Notice motdContent = BukkitNotice.builder()
22+
.chat(List.of(
23+
"<green>Welcome to the server,</green> <gradient:#ee1d1d:#f1b722>{PLAYER}</gradient>",
24+
"<green>Have a good time playing!</green>",
25+
"<green>The current time in {WORLD} is: </green><gradient:#2c60d5:#742ccf>{TIME}</gradient> <green>ticks",
26+
"<green>If you need any help, don't hesitate to ask our staff using the </green><dark_green><click:suggest_command:'/helpop'>/helpop</click> command!</dark_green>"
27+
)
28+
)
29+
.title("<gradient:#9d6eef:#A1AAFF:#9d6eef>EternalCore</gradient>", "<white>Welcome back to the server!")
30+
.sound(Sound.BLOCK_NOTE_BLOCK_PLING)
31+
.build();
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.eternalcode.core.feature.motd.messages;
2+
3+
import com.eternalcode.multification.notice.Notice;
4+
5+
public interface MotdMessages {
6+
7+
Notice motdContent();
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.eternalcode.core.feature.motd.messages;
2+
3+
import com.eternalcode.multification.bukkit.notice.BukkitNotice;
4+
import com.eternalcode.multification.notice.Notice;
5+
import eu.okaeri.configs.OkaeriConfig;
6+
import eu.okaeri.configs.annotation.Comment;
7+
import lombok.Getter;
8+
import lombok.experimental.Accessors;
9+
import org.bukkit.Sound;
10+
11+
import java.util.List;
12+
13+
@Getter
14+
@Accessors(fluent = true)
15+
public class PLMotdMessages extends OkaeriConfig implements MotdMessages {
16+
17+
@Comment("# Treść wiadomości dnia (MOTD), która zostanie wysłana do graczy po wejściu na serwer.")
18+
@Comment("# Domyślnie obsługiwane placeholdery: {PLAYER}, {WORLD}, {TIME}")
19+
@Comment("# Możesz dodać własne placeholdery korzystając z PlaceholderAPI.")
20+
@Comment("# Generator powiadomień znajdziesz tutaj: https://www.eternalcode.pl/notification-generator")
21+
public Notice motdContent = BukkitNotice.builder()
22+
.chat(List.of(
23+
"<green>Witaj na serwerze,</green> <gradient:#ee1d1d:#f1b722>{PLAYER}</gradient>",
24+
"<green>Miłej zabawy!</green>",
25+
"<green>Aktualny czas w {WORLD} to: </green><gradient:#2c60d5:#742ccf>{TIME}</gradient> <green>tików",
26+
"<green>Jeśli potrzebujesz pomocy, napisz do administracji komendą </green><dark_green><click:suggest_command:'/helpop'>/helpop</click></dark_green>"
27+
)
28+
)
29+
.title("<gradient:#9d6eef:#A1AAFF:#9d6eef>EternalCore</gradient>", "<white>Witamy ponownie na serwerze!")
30+
.sound(Sound.BLOCK_NOTE_BLOCK_PLING)
31+
.build();
32+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.eternalcode.core.feature.itemedit.messages.ItemEditMessages;
1414
import com.eternalcode.core.feature.jail.messages.JailMessages;
1515
import com.eternalcode.core.feature.language.Language;
16+
import com.eternalcode.core.feature.motd.messages.MotdMessages;
1617
import com.eternalcode.core.feature.msg.messages.MsgMessages;
1718
import com.eternalcode.core.feature.randomteleport.messages.RandomTeleportMessages;
1819
import com.eternalcode.core.feature.seen.messages.SeenMessages;
@@ -99,8 +100,6 @@ interface EventSection {
99100
List<Notice> firstJoinMessage();
100101

101102
Map<EntityDamageEvent.DamageCause, List<Notice>> deathMessageByDamageCause();
102-
103-
Notice welcome();
104103
}
105104

106105
interface InventorySection {
@@ -258,4 +257,6 @@ interface ContainerSection {
258257
BurnMessages burn();
259258
// vanish section
260259
VanishMessages vanish();
260+
// motd section
261+
MotdMessages motd();
261262
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.eternalcode.core.feature.itemedit.messages.ENItemEditMessages;
1414
import com.eternalcode.core.feature.jail.messages.ENJailMessages;
1515
import com.eternalcode.core.feature.language.Language;
16+
import com.eternalcode.core.feature.motd.messages.ENMotdMessages;
1617
import com.eternalcode.core.feature.msg.messages.ENMsgMessages;
1718
import com.eternalcode.core.feature.randomteleport.messages.ENRandomTeleportMessages;
1819
import com.eternalcode.core.feature.seen.messages.ENSeenMessages;
@@ -356,9 +357,6 @@ public static class ENEventSection extends OkaeriConfig implements EventSection
356357
Notice.actionbar("<red>► {PLAYER} <white>logged off the server!"),
357358
Notice.actionbar("<red>► {PLAYER} <white>left the server!")
358359
);
359-
360-
@Comment({" ", "# {PLAYER} - Player who joined"})
361-
public Notice welcome = Notice.title("<yellow>EternalCode.pl", "<yellow>Welcome back to the server!");
362360
}
363361

364362

@@ -578,4 +576,7 @@ public static class ENLanguageSection extends OkaeriConfig implements LanguageSe
578576

579577
@Comment({" ", "# This section is responsible for vanish-related stuff."})
580578
public ENVanishMessages vanish = new ENVanishMessages();
579+
580+
@Comment({" ", "# This section is responsible for the messages of the MOTD feature."})
581+
public ENMotdMessages motd = new ENMotdMessages();
581582
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.eternalcode.core.feature.itemedit.messages.PLItemEditMessages;
1414
import com.eternalcode.core.feature.jail.messages.PLJailMessages;
1515
import com.eternalcode.core.feature.language.Language;
16+
import com.eternalcode.core.feature.motd.messages.PLMotdMessages;
1617
import com.eternalcode.core.feature.msg.messages.PLMsgMessages;
1718
import com.eternalcode.core.feature.randomteleport.messages.PLRandomTeleportMessages;
1819
import com.eternalcode.core.feature.seen.messages.PLSeenMessages;
@@ -376,9 +377,6 @@ public static class PLEventSection extends OkaeriConfig implements EventSection
376377
Notice.actionbar("<red>► {PLAYER} <white>wylogował się z serwera!"),
377378
Notice.actionbar("<red>► {PLAYER} <white>opuścił serwer!")
378379
);
379-
380-
@Comment({" ", "# {PLAYER} - Gracz który dołączył do serwera"})
381-
public Notice welcome = Notice.title("<yellow>{PLAYER}", "<yellow>Witaj ponownie na serwerze!");
382380
}
383381

384382
@Comment({
@@ -602,4 +600,7 @@ public static class PLLanguageSection extends OkaeriConfig implements LanguageSe
602600

603601
@Comment({" ", "# Ta sekcja odpowiada za wiadomości dotyczące trybu niewidoczności graczy"})
604602
public PLVanishMessages vanish = new PLVanishMessages();
603+
604+
@Comment({" ", "# Ta sekcja odpowiada za funkcję MOTD (Message of the Day)"})
605+
public PLMotdMessages motd = new PLMotdMessages();
605606
}

0 commit comments

Comments
 (0)