Skip to content

GH-991 Add MOTD feature #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
Expand Up @@ -41,12 +41,6 @@ void onPlayerJoin(PlayerJoinEvent event) {
.send();
}

this.noticeService.create()
.notice(translation -> translation.event().welcome())
.placeholder("{PLAYER}", player.getName())
.player(player.getUniqueId())
.sendAsync();

event.setJoinMessage(StringUtils.EMPTY);

this.noticeService.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.eternalcode.core.feature.motd;

import com.eternalcode.core.feature.motd.messages.MotdMessages;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Controller;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.placeholder.Placeholders;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

@SuppressWarnings("Convert2MethodRef")
@Controller
class MotdJoinController implements Listener {

private static final Placeholders<Player> PLACEHOLDERS = Placeholders.<Player>builder()
.with("{PLAYER}", player -> player.getName())
.with("{TIME}", player -> String.valueOf(player.getWorld().getTime()))
.with("{WORLD}", player -> player.getWorld().getName())
.build();

private final NoticeService noticeService;
private final MotdMessages motdMessages;

@Inject
MotdJoinController(NoticeService noticeService, MotdMessages motdMessages) {
this.noticeService = noticeService;
this.motdMessages = motdMessages;
}

@EventHandler
void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();

this.noticeService.create()
.notice(this.motdMessages.motdContent())
.player(player.getUniqueId())
.formatter(PLACEHOLDERS.toFormatter(player))
.send();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.eternalcode.core.feature.motd.messages;

import com.eternalcode.multification.bukkit.notice.BukkitNotice;
import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.bukkit.Sound;

import java.util.List;

@Getter
@Accessors(fluent = true)
public class ENMotdMessages extends OkaeriConfig implements MotdMessages {

@Comment("# Message of the Day (MOTD) content that will be sent to players when they join the server.")
@Comment("# Out of the box supported placeholders: {PLAYER}, {WORLD}, {TIME}")
@Comment("# You can add your own placeholders using the PlaceholderAPI.")
@Comment("# You can check our Notification Generator: https://www.eternalcode.pl/notification-generator")
public Notice motdContent = BukkitNotice.builder()
.chat(List.of(
"<green>Welcome to the server,</green> <gradient:#ee1d1d:#f1b722>{PLAYER}</gradient>",
"<green>Have a good time playing!</green>",
"<green>The current time in {WORLD} is: </green><gradient:#2c60d5:#742ccf>{TIME}</gradient> <green>ticks",
"<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>"
)
)
.title("<gradient:#9d6eef:#A1AAFF:#9d6eef>EternalCore</gradient>", "<white>Welcome back to the server!")
.sound(Sound.BLOCK_NOTE_BLOCK_PLING)
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.eternalcode.core.feature.motd.messages;

import com.eternalcode.multification.notice.Notice;

public interface MotdMessages {

Notice motdContent();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.eternalcode.core.feature.motd.messages;

import com.eternalcode.multification.bukkit.notice.BukkitNotice;
import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.bukkit.Sound;

import java.util.List;

@Getter
@Accessors(fluent = true)
public class PLMotdMessages extends OkaeriConfig implements MotdMessages {

@Comment("# Treść wiadomości dnia (MOTD), która zostanie wysłana do graczy po wejściu na serwer.")
@Comment("# Domyślnie obsługiwane placeholdery: {PLAYER}, {WORLD}, {TIME}")
@Comment("# Możesz dodać własne placeholdery korzystając z PlaceholderAPI.")
@Comment("# Generator powiadomień znajdziesz tutaj: https://www.eternalcode.pl/notification-generator")
public Notice motdContent = BukkitNotice.builder()
.chat(List.of(
"<green>Witaj na serwerze,</green> <gradient:#ee1d1d:#f1b722>{PLAYER}</gradient>",
"<green>Miłej zabawy!</green>",
"<green>Aktualny czas w {WORLD} to: </green><gradient:#2c60d5:#742ccf>{TIME}</gradient> <green>tików",
"<green>Jeśli potrzebujesz pomocy, napisz do administracji komendą </green><dark_green><click:suggest_command:'/helpop'>/helpop</click></dark_green>"
)
)
.title("<gradient:#9d6eef:#A1AAFF:#9d6eef>EternalCore</gradient>", "<white>Witamy ponownie na serwerze!")
.sound(Sound.BLOCK_NOTE_BLOCK_PLING)
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.eternalcode.core.feature.itemedit.messages.ItemEditMessages;
import com.eternalcode.core.feature.jail.messages.JailMessages;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.motd.messages.MotdMessages;
import com.eternalcode.core.feature.privatechat.messages.PrivateChatMessages;
import com.eternalcode.core.feature.randomteleport.messages.RandomTeleportMessages;
import com.eternalcode.core.feature.seen.messages.SeenMessages;
Expand All @@ -24,9 +25,10 @@
import com.eternalcode.core.feature.vanish.messages.VanishMessages;
import com.eternalcode.core.feature.warp.messages.WarpMessages;
import com.eternalcode.multification.notice.Notice;
import org.bukkit.event.entity.EntityDamageEvent;

import java.util.List;
import java.util.Map;
import org.bukkit.event.entity.EntityDamageEvent;

public interface Translation {

Expand Down Expand Up @@ -97,8 +99,6 @@ interface EventSection {
List<Notice> firstJoinMessage();

Map<EntityDamageEvent.DamageCause, List<Notice>> deathMessageByDamageCause();

Notice welcome();
}

interface InventorySection {
Expand Down Expand Up @@ -254,4 +254,6 @@ interface ContainerSection {
JailMessages jailSection();
// vanish section
VanishMessages vanish();
// motd section
MotdMessages motd();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import com.eternalcode.core.feature.adminchat.messages.ENAdminChatMessages;
import com.eternalcode.core.feature.afk.messages.ENAfkMessages;
import com.eternalcode.core.feature.automessage.messages.ENAutoMessageMessages;
import com.eternalcode.core.feature.fun.demoscreen.messages.ENDemoScreenMessages;
import com.eternalcode.core.feature.fun.elderguardian.messages.ENElderGuardianMessages;
import com.eternalcode.core.feature.helpop.messages.ENHelpOpMessages;
import com.eternalcode.core.feature.home.messages.ENHomeMessages;
import com.eternalcode.core.feature.itemedit.messages.ENItemEditMessages;
import com.eternalcode.core.feature.jail.messages.ENJailMessages;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.motd.messages.ENMotdMessages;
import com.eternalcode.core.feature.privatechat.messages.ENPrivateMessages;
import com.eternalcode.core.feature.randomteleport.messages.ENRandomTeleportMessages;
import com.eternalcode.core.feature.seen.messages.ENSeenMessages;
Expand All @@ -19,8 +22,6 @@
import com.eternalcode.core.feature.sudo.messages.ENSudoMessages;
import com.eternalcode.core.feature.teleportrequest.messages.ENTeleportRequestMessages;
import com.eternalcode.core.feature.time.messages.ENTimeAndWeatherMessages;
import com.eternalcode.core.feature.fun.demoscreen.messages.ENDemoScreenMessages;
import com.eternalcode.core.feature.fun.elderguardian.messages.ENElderGuardianMessages;
import com.eternalcode.core.feature.vanish.messages.ENVanishMessages;
import com.eternalcode.core.feature.warp.messages.ENWarpMessages;
import com.eternalcode.core.translation.AbstractTranslation;
Expand Down Expand Up @@ -355,9 +356,6 @@ public static class ENEventSection extends OkaeriConfig implements EventSection
Notice.actionbar("<red>► {PLAYER} <white>logged off the server!"),
Notice.actionbar("<red>► {PLAYER} <white>left the server!")
);

@Comment({" ", "# {PLAYER} - Player who joined"})
public Notice welcome = Notice.title("<yellow>EternalCode.pl", "<yellow>Welcome back to the server!");
}


Expand Down Expand Up @@ -575,4 +573,7 @@ public static class ENLanguageSection extends OkaeriConfig implements LanguageSe
@Comment({" ", "# This section is responsible for vanish-related stuff."})
public ENVanishMessages vanish = new ENVanishMessages();

@Comment({" ", "# This section is responsible for the messages of the MOTD feature."})
public ENMotdMessages motd = new ENMotdMessages();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import com.eternalcode.core.feature.adminchat.messages.PLAdminChatMessages;
import com.eternalcode.core.feature.afk.messages.PLAfkMessages;
import com.eternalcode.core.feature.automessage.messages.PLAutoMessageMessages;
import com.eternalcode.core.feature.fun.demoscreen.messages.PLDemoScreenMessages;
import com.eternalcode.core.feature.fun.elderguardian.messages.PLElderGuardianMessages;
import com.eternalcode.core.feature.helpop.messages.PLHelpOpMessages;
import com.eternalcode.core.feature.home.messages.PLHomeMessages;
import com.eternalcode.core.feature.itemedit.messages.PLItemEditMessages;
import com.eternalcode.core.feature.jail.messages.PLJailMessages;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.motd.messages.PLMotdMessages;
import com.eternalcode.core.feature.privatechat.messages.PLPrivateChatMessages;
import com.eternalcode.core.feature.randomteleport.messages.PLRandomTeleportMessages;
import com.eternalcode.core.feature.seen.messages.PLSeenMessages;
Expand All @@ -19,8 +22,6 @@
import com.eternalcode.core.feature.sudo.messages.PLSudoMessages;
import com.eternalcode.core.feature.teleportrequest.messages.PLTeleportRequestMessages;
import com.eternalcode.core.feature.time.messages.PLTimeAndWeatherMessages;
import com.eternalcode.core.feature.fun.demoscreen.messages.PLDemoScreenMessages;
import com.eternalcode.core.feature.fun.elderguardian.messages.PLElderGuardianMessages;
import com.eternalcode.core.feature.vanish.messages.PLVanishMessages;
import com.eternalcode.core.feature.warp.messages.PLWarpMessages;
import com.eternalcode.core.translation.AbstractTranslation;
Expand Down Expand Up @@ -375,9 +376,6 @@ public static class PLEventSection extends OkaeriConfig implements EventSection
Notice.actionbar("<red>► {PLAYER} <white>wylogował się z serwera!"),
Notice.actionbar("<red>► {PLAYER} <white>opuścił serwer!")
);

@Comment({" ", "# {PLAYER} - Gracz który dołączył do serwera"})
public Notice welcome = Notice.title("<yellow>{PLAYER}", "<yellow>Witaj ponownie na serwerze!");
}

@Comment({
Expand Down Expand Up @@ -599,4 +597,7 @@ public static class PLLanguageSection extends OkaeriConfig implements LanguageSe
@Comment({" ", "# Ta sekcja odpowiada za wiadomości dotyczące trybu niewidoczności graczy"})
public PLVanishMessages vanish = new PLVanishMessages();

@Comment({" ", "# Ta sekcja odpowiada za funkcję MOTD (Message of the Day)"})
public PLMotdMessages motd = new PLMotdMessages();

}