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 2 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 @@ -10,6 +10,8 @@
import com.eternalcode.core.feature.home.HomesConfig;
import com.eternalcode.core.feature.jail.JailConfig;
import com.eternalcode.core.feature.lightning.LightningConfig;
import com.eternalcode.core.feature.motd.MotdConfig;
import com.eternalcode.core.feature.motd.MotdSettings;
import com.eternalcode.core.feature.randomteleport.RandomTeleportSettingsImpl;
import com.eternalcode.core.feature.repair.RepairConfig;
import com.eternalcode.core.feature.serverlinks.ServerLinksConfig;
Expand Down Expand Up @@ -224,6 +226,11 @@ public static class Items extends OkaeriConfig {
@Comment("# Settings responsible for player vanish functionality")
VanishConfig vanish = new VanishConfig();

@Bean(proxied = MotdSettings.class)
@Comment("")
@Comment("# Message of the Day (MOTD) Configuration")
MotdConfig motd = new MotdConfig();

@Override
public File getConfigFile(File dataFolder) {
return new File(dataFolder, "config.yml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eternalcode.core.feature.motd;

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 java.util.List;

@Getter
@Accessors(fluent = true)
public class MotdConfig extends OkaeriConfig implements MotdSettings {

@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.")
public Notice motdContent = Notice.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>"
)
);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.eternalcode.core.feature.motd;

import com.eternalcode.multification.notice.Notice;

public interface MotdSettings {

Notice motdContent();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.eternalcode.core.feature.motd;

import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Controller;
import com.eternalcode.core.notice.NoticeService;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

@Controller
class PlayerJoinMotdController implements Listener {

private final NoticeService noticeService;
private final MotdSettings motdSettings;

@Inject
PlayerJoinMotdController(NoticeService noticeService, MotdSettings motdSettings) {
this.noticeService = noticeService;
this.motdSettings = motdSettings;
}

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

this.noticeService.create()
.notice(this.motdSettings.motdContent())
.player(player.getUniqueId())
.placeholder("{PLAYER}", player.getName())
.placeholder("{TIME}", String.valueOf(player.getWorld().getTime()))
.placeholder("{WORLD}", player.getWorld().getName())
.send();
}

}