From cd371d594a3b8e96003acaab3ef390c7e0297012 Mon Sep 17 00:00:00 2001 From: Apehum <36326454+Apehum@users.noreply.github.com> Date: Sun, 3 Nov 2024 16:02:31 +0800 Subject: [PATCH] fix: use getter for injecting addon config --- changelog.md | 3 ++- .../su/plo/voice/discs/GoatHornManager.kt | 10 ++++++---- .../plo/voice/discs/PlasmoAudioPlayerManager.kt | 6 ++++-- .../voice/discs/crafting/BurnableDiscCraft.kt | 4 +++- .../voice/discs/event/JukeboxEventListener.kt | 9 +++++---- .../voice/discs/utils/extend/KoinComponent.kt | 17 +++++++++++++++++ .../plo/voice/discs/v1_19_4/GoatHornListener.kt | 4 +++- 7 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 core/src/main/kotlin/su/plo/voice/discs/utils/extend/KoinComponent.kt diff --git a/changelog.md b/changelog.md index e826aaf..0d516ed 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,4 @@ - Yet another lavaplayer update to fix playback issues. - Addons' permissions are now registered in Bukkit permissions. This resolves auto-complete and goat horns not working properly. -- New config option `mono_sources` to use mono sources for playing the audio. \ No newline at end of file +- New config option `mono_sources` to use mono sources for playing the audio. +- `/vreload` command is now reloading the addon's config properly. \ No newline at end of file diff --git a/core/src/main/kotlin/su/plo/voice/discs/GoatHornManager.kt b/core/src/main/kotlin/su/plo/voice/discs/GoatHornManager.kt index e802f37..d910f4a 100644 --- a/core/src/main/kotlin/su/plo/voice/discs/GoatHornManager.kt +++ b/core/src/main/kotlin/su/plo/voice/discs/GoatHornManager.kt @@ -20,6 +20,8 @@ import su.plo.voice.api.server.PlasmoVoiceServer import su.plo.voice.api.server.audio.line.ServerSourceLine import su.plo.voice.discs.utils.PluginKoinComponent import su.plo.voice.discs.utils.extend.asVoicePlayer +import su.plo.voice.discs.utils.extend.getValue +import su.plo.voice.discs.utils.extend.getter import su.plo.voice.discs.utils.extend.identifier import su.plo.voice.discs.utils.extend.sendTranslatable import su.plo.voice.discs.utils.extend.suspendSync @@ -30,11 +32,11 @@ class GoatHornManager : PluginKoinComponent { private val plugin: JavaPlugin by inject() private val keys: AddonKeys by inject() - private val config: AddonConfig by inject() + private val config: AddonConfig by getter() private val voiceServer: PlasmoVoiceServer by inject() - private val audioPlayerManager: PlasmoAudioPlayerManager by inject() - private val debugLogger: DebugLogger by inject() - private val sourceLine: ServerSourceLine by inject() + private val audioPlayerManager: PlasmoAudioPlayerManager by getter() + private val debugLogger: DebugLogger by getter() + private val sourceLine: ServerSourceLine by getter() private val jobByPlayer: MutableMap = ConcurrentHashMap() diff --git a/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt b/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt index 66ab8c2..bc8d9b4 100644 --- a/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt +++ b/core/src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt @@ -10,6 +10,8 @@ import su.plo.voice.api.server.audio.provider.AudioFrameResult import su.plo.voice.api.server.audio.source.ServerProximitySource import su.plo.voice.discs.utils.PluginKoinComponent import su.plo.voice.discs.config.YoutubeClient +import su.plo.voice.discs.utils.extend.getValue +import su.plo.voice.discs.utils.extend.getter import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager @@ -41,8 +43,8 @@ class PlasmoAudioPlayerManager : PluginKoinComponent { private val plugin: JavaPlugin by inject() private val voiceServer: PlasmoVoiceServer by inject() - private val debugLogger: DebugLogger by inject() - private val config: AddonConfig by inject() + private val debugLogger: DebugLogger by getter() + private val config: AddonConfig by getter() private val lavaPlayerManager: AudioPlayerManager = DefaultAudioPlayerManager() private val encryption = voiceServer.defaultEncryption diff --git a/core/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt b/core/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt index ba0b937..42bfe34 100644 --- a/core/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt +++ b/core/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt @@ -18,11 +18,13 @@ import su.plo.voice.discs.AddonKeys import su.plo.voice.discs.utils.MaterialUtil import su.plo.voice.discs.utils.PluginKoinComponent import su.plo.voice.discs.utils.extend.forbidGrindstone +import su.plo.voice.discs.utils.extend.getValue +import su.plo.voice.discs.utils.extend.getter class BurnableDiscCraft : PluginKoinComponent { private val plugin: JavaPlugin by inject() - private val config: AddonConfig by inject() + private val config: AddonConfig by getter() private val keys: AddonKeys by inject() private val groupKey = NamespacedKey(plugin, "burnable_record_craft") diff --git a/core/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt b/core/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt index 0069523..e8fac2f 100644 --- a/core/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt +++ b/core/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt @@ -21,6 +21,7 @@ import org.bukkit.event.world.ChunkLoadEvent import org.bukkit.event.world.ChunkUnloadEvent import org.bukkit.inventory.ItemStack import org.bukkit.plugin.java.JavaPlugin +import org.koin.core.component.get import org.koin.core.component.inject import su.plo.slib.api.chat.component.McTextComponent import su.plo.slib.api.chat.style.McTextStyle @@ -39,11 +40,11 @@ class JukeboxEventListener : Listener, PluginKoinComponent { private val keys: AddonKeys by inject() private val plugin: JavaPlugin by inject() - private val config: AddonConfig by inject() + private val config: AddonConfig by getter() private val voiceServer: PlasmoVoiceServer by inject() - private val audioPlayerManager: PlasmoAudioPlayerManager by inject() - private val debugLogger: DebugLogger by inject() - private val sourceLine: ServerSourceLine by inject() + private val audioPlayerManager: PlasmoAudioPlayerManager by getter() + private val debugLogger: DebugLogger by getter() + private val sourceLine: ServerSourceLine by getter() private val jobByBlock: MutableMap = HashMap() diff --git a/core/src/main/kotlin/su/plo/voice/discs/utils/extend/KoinComponent.kt b/core/src/main/kotlin/su/plo/voice/discs/utils/extend/KoinComponent.kt new file mode 100644 index 0000000..3d06141 --- /dev/null +++ b/core/src/main/kotlin/su/plo/voice/discs/utils/extend/KoinComponent.kt @@ -0,0 +1,17 @@ +package su.plo.voice.discs.utils.extend + +import org.koin.core.component.KoinComponent +import org.koin.core.component.get +import kotlin.reflect.KProperty + +interface Getter { + val value: T +} + +inline operator fun Getter.getValue(thisRef: Any?, property: KProperty<*>): T = value + +inline fun KoinComponent.getter(): Getter = + object : Getter { + override val value: T + get() = get() + } \ No newline at end of file diff --git a/v1_19_4/src/main/kotlin/su/plo/voice/discs/v1_19_4/GoatHornListener.kt b/v1_19_4/src/main/kotlin/su/plo/voice/discs/v1_19_4/GoatHornListener.kt index 8791c41..c3ebbc8 100644 --- a/v1_19_4/src/main/kotlin/su/plo/voice/discs/v1_19_4/GoatHornListener.kt +++ b/v1_19_4/src/main/kotlin/su/plo/voice/discs/v1_19_4/GoatHornListener.kt @@ -11,12 +11,14 @@ import su.plo.voice.discs.AddonConfig import su.plo.voice.discs.AddonKeys import su.plo.voice.discs.GoatHornManager import su.plo.voice.discs.utils.PluginKoinComponent +import su.plo.voice.discs.utils.extend.getValue +import su.plo.voice.discs.utils.extend.getter import su.plo.voice.discs.utils.extend.hasIdentifier class GoatHornListener : Listener, PluginKoinComponent { private val keys: AddonKeys by inject() - private val config: AddonConfig by inject() + private val config: AddonConfig by getter() private val hornManager: GoatHornManager by inject() @EventHandler(priority = EventPriority.MONITOR)