diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerController.java index 170c93a3e..6aff519a7 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/chat/ChatManagerController.java @@ -4,6 +4,7 @@ import static com.eternalcode.core.feature.chat.ChatManagerController.CHAT_SLOWMODE_BYPASS_PERMISSION; import com.eternalcode.annotations.scan.permission.PermissionDocs; +import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.event.EventCaller; import com.eternalcode.core.feature.chat.event.restrict.ChatRestrictCause; import com.eternalcode.core.feature.chat.event.restrict.ChatRestrictEvent; @@ -13,6 +14,8 @@ import com.eternalcode.core.util.DurationUtil; import java.time.Duration; import java.util.UUID; + +import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -34,18 +37,24 @@ class ChatManagerController implements Listener { private final ChatSettings chatSettings; private final NoticeService noticeService; private final EventCaller eventCaller; + private final PluginConfiguration config; + private final Server server; @Inject ChatManagerController( ChatService chatService, ChatSettings chatSettings, NoticeService noticeService, - EventCaller eventCaller + EventCaller eventCaller, + PluginConfiguration config, + Server server ) { this.chatService = chatService; this.chatSettings = chatSettings; this.noticeService = noticeService; this.eventCaller = eventCaller; + this.config = config; + this.server = server; } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @@ -90,4 +99,21 @@ void onChatSlowMode(AsyncPlayerChatEvent event) { void markUseChat(AsyncPlayerChatEvent event) { this.chatService.markUseChat(event.getPlayer().getUniqueId()); } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + void sendSound(AsyncPlayerChatEvent event) { + PluginConfiguration.Sounds sound = this.config.sound; + + if (!sound.enableAfterChatMessage) { + return; + } + + if (!this.chatSettings.chatEnabled()) { + return; + } + + for (Player online : this.server.getOnlinePlayers()) { + online.playSound(online.getLocation(), sound.afterChatMessage, sound.afterChatMessageVolume, sound.afterChatMessagePitch); + } + } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/joinmessage/PlayerJoinMessageController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/session/PlayerJoinMessageController.java similarity index 71% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/joinmessage/PlayerJoinMessageController.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/session/PlayerJoinMessageController.java index 5632b7522..14198c43e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/joinmessage/PlayerJoinMessageController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/session/PlayerJoinMessageController.java @@ -1,11 +1,13 @@ -package com.eternalcode.core.feature.joinmessage; +package com.eternalcode.core.feature.session; import com.eternalcode.commons.RandomElementUtil; +import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.feature.vanish.VanishService; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Controller; import com.eternalcode.core.notice.NoticeService; +import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -17,11 +19,15 @@ class PlayerJoinMessageController implements Listener { private final NoticeService noticeService; private final VanishService vanishService; + private final PluginConfiguration config; + private final Server server; @Inject - PlayerJoinMessageController(NoticeService noticeService, VanishService vanishService) { + PlayerJoinMessageController(NoticeService noticeService, VanishService vanishService, PluginConfiguration config, Server server) { this.noticeService = noticeService; this.vanishService = vanishService; + this.config = config; + this.server = server; } @EventHandler @@ -42,6 +48,13 @@ void onPlayerJoin(PlayerJoinEvent event) { } event.setJoinMessage(StringUtils.EMPTY); + PluginConfiguration.Sounds sound = this.config.sound; + + if (sound.enabledAfterJoin) { + for (Player online : this.server.getOnlinePlayers()) { + online.playSound(online.getLocation(), sound.afterJoin, sound.afterJoinVolume, sound.afterJoinPitch); + } + } this.noticeService.create() .noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().joinMessage())) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/quitmessage/PlayerQuitMessageController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/session/PlayerQuitMessageController.java similarity index 67% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/quitmessage/PlayerQuitMessageController.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/session/PlayerQuitMessageController.java index d614ec8eb..31940143d 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/quitmessage/PlayerQuitMessageController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/session/PlayerQuitMessageController.java @@ -1,11 +1,13 @@ -package com.eternalcode.core.feature.quitmessage; +package com.eternalcode.core.feature.session; import com.eternalcode.commons.RandomElementUtil; +import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.feature.vanish.VanishService; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Controller; import com.eternalcode.core.notice.NoticeService; +import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -17,11 +19,15 @@ class PlayerQuitMessageController implements Listener { private final NoticeService noticeService; private final VanishService vanishService; + private final PluginConfiguration config; + private final Server server; @Inject - PlayerQuitMessageController(NoticeService noticeService, VanishService vanishService) { + PlayerQuitMessageController(NoticeService noticeService, VanishService vanishService, PluginConfiguration config, Server server) { this.noticeService = noticeService; this.vanishService = vanishService; + this.config = config; + this.server = server; } @EventHandler @@ -34,6 +40,13 @@ void onPlayerQuit(PlayerQuitEvent event) { } event.setQuitMessage(StringUtils.EMPTY); + PluginConfiguration.Sounds sound = this.config.sound; + + if (sound.enableAfterQuit) { + for (Player online : this.server.getOnlinePlayers()) { + online.playSound(online.getLocation(), sound.afterQuit, sound.afterQuitVolume, sound.afterQuitPitch); + } + } this.noticeService.create() .noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().quitMessage()))