Skip to content

Commit

Permalink
fix: use getter for injecting addon config
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Nov 3, 2024
1 parent a75a10f commit cd371d5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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.
- New config option `mono_sources` to use mono sources for playing the audio.
- `/vreload` command is now reloading the addon's config properly.
10 changes: 6 additions & 4 deletions core/src/main/kotlin/su/plo/voice/discs/GoatHornManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Player, Job> = ConcurrentHashMap()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Block, Job> = HashMap()

Expand Down
Original file line number Diff line number Diff line change
@@ -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<out T> {
val value: T
}

inline operator fun <T> Getter<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value

inline fun <reified T : Any> KoinComponent.getter(): Getter<T> =
object : Getter<T> {
override val value: T
get() = get()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cd371d5

Please sign in to comment.