-
-
Notifications
You must be signed in to change notification settings - Fork 20
GH-1196 Refactor sound sending system #1196
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
Comment on lines
+54
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic for iterating over all online players to play a sound is duplicated in This would centralize the sound playing logic, making it easier to manage and modify in the future. Here's an example of how such a service could look: @Service
public class SoundService {
private final Server server;
@Inject
public SoundService(Server server) {
this.server = server;
}
public void playSoundToAll(Sound sound, float volume, float pitch) {
if (sound == null) {
return;
}
for (Player online : this.server.getOnlinePlayers()) {
online.playSound(online.getLocation(), sound, volume, pitch);
}
}
} You could then inject |
||
} | ||
|
||
this.noticeService.create() | ||
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.event().joinMessage())) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check
if (!this.chatSettings.chatEnabled())
appears to be redundant and might cause unintended behavior. The event handler is already set toignoreCancelled = true
, so it won't run if the chat event is cancelled (for example, when chat is disabled for a user without bypass permissions).However, for a user with bypass permissions, their message will go through, but this check will prevent the sound from playing. It seems more consistent to play the sound if the message is successfully sent. I recommend removing this conditional block to fix this.