Skip to content

Commit

Permalink
v1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum authored Aug 23, 2024
2 parents e33d6ca + 90c27d8 commit 3b901de
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
1.20.4
1.20.6
1.21
1.21.1
- name: Publish to GitHub
uses: Apehum/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**Requires [pv-addon-lavaplayer-lib 1.0.8+](https://modrinth.com/plugin/pv-addon-lavaplayer-lib/version/1.0.8) to work**
**Requires [pv-addon-lavaplayer-lib 1.0.12+](https://modrinth.com/plugin/pv-addon-lavaplayer-lib/version/1.0.12)**

Changelog:
- Config option to change lore burn method
- 1.21 support
- Fixed an issue where inserting a disc with shift-click caused it to start playing on 1.21
- Reintroduced YouTube authorization
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
paperVersion=1.20.1-R0.1-SNAPSHOT
foliaVersion=1.20.1-R0.1-SNAPSHOT
plasmoVoiceVersion=2.0.3
lavaplayerLibVersion=1.0.8
lavaplayerLibVersion=1.0.11

# Version
mavenGroup=su.plo.voice.discs
mavenArtifactId=discs
pluginVersion=1.0.7
pluginVersion=1.0.8
21 changes: 21 additions & 0 deletions src/main/kotlin/su/plo/voice/discs/AddonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ class AddonConfig {
@ConfigField
val httpSource = HttpSourceConfig()

@Config
class YouTubeSourceConfig {
@ConfigField(
comment = """
If you see a error like "Sign in to confirm you're not a bot",
you can try using YouTube oauth2 authorization.
On the first start with authorization enabled,
you will see "OAUTH INTEGRATION" in your console.
Follow the instructions in this prompt.
If you do everything right, you will see "Token retrieved successfully" in your console.
You only need to do this once;
the token will be stored in "pv-addon-discs/.youtube-token" on plugin shutdown.
"""
)
val useOauth2: Boolean = false
}

@ConfigField
val youtubeSource = YouTubeSourceConfig()

@Config
class BurnableTag {
@ConfigField(
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import su.plo.voice.discs.utils.extend.debug
@Addon(
id = "pv-addon-discs",
scope = AddonLoaderScope.SERVER,
version = "1.0.7",
version = "1.0.8",
authors = ["KPidS", "Apehum"]
)
class DiscsPlugin : JavaPlugin() {
Expand Down Expand Up @@ -66,7 +66,6 @@ class DiscsPlugin : JavaPlugin() {
loadConfig()
}

@EventSubscribe
override fun onEnable() {
loadConfig()

Expand Down Expand Up @@ -100,6 +99,10 @@ class DiscsPlugin : JavaPlugin() {

override fun onDisable() {
PlasmoVoiceServer.getAddonsLoader().unload(this)

if (::audioPlayerManager.isInitialized) {
audioPlayerManager.save()
}
}

private fun loadConfig() {
Expand Down
25 changes: 24 additions & 1 deletion src/main/kotlin/su/plo/voice/discs/PlasmoAudioPlayerManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import su.plo.voice.lavaplayer.libs.com.sedmelluq.discord.lavaplayer.track.*
import su.plo.voice.lavaplayer.libs.dev.lavalink.youtube.YoutubeAudioSourceManager
import su.plo.voice.proto.packets.tcp.clientbound.SourceAudioEndPacket
import su.plo.voice.proto.packets.udp.clientbound.SourceAudioPacket
import java.io.File
import java.net.URI
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
Expand All @@ -34,6 +35,17 @@ class PlasmoAudioPlayerManager(
registerSources()
}

fun save() {
lavaPlayerManager.sourceManagers
.filterIsInstance<YoutubeAudioSourceManager>()
.firstOrNull()
?.takeIf { it.oauth2RefreshToken != null }
?.let {
val refreshTokenFile = File(plugin.dataFolder, ".youtube-token")
refreshTokenFile.writeText(it.oauth2RefreshToken!!)
}
}

fun startTrackJob(track: AudioTrack, source: ServerStaticSource, distance: Short) = scope.launch {

val player = lavaPlayerManager.createPlayer()
Expand Down Expand Up @@ -136,7 +148,18 @@ class PlasmoAudioPlayerManager(
}

private fun registerSources() {
lavaPlayerManager.registerSourceManager(YoutubeAudioSourceManager(true))
lavaPlayerManager.registerSourceManager(
YoutubeAudioSourceManager(true)
.also { source ->
if (plugin.addonConfig.youtubeSource.useOauth2) {
val refreshToken = File(plugin.dataFolder, ".youtube-token")
.takeIf { it.isFile && it.exists() }
?.readText()
?.trim()
source.useOauth2(refreshToken, false)
}
}
)
lavaPlayerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault())
lavaPlayerManager.registerSourceManager(BandcampAudioSourceManager())
lavaPlayerManager.registerSourceManager(VimeoAudioSourceManager())
Expand Down
25 changes: 22 additions & 3 deletions src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package su.plo.voice.discs.event

import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.delay
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
import net.kyori.adventure.text.TextComponent
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.Block
Expand All @@ -25,7 +31,14 @@ import su.plo.lib.api.server.world.ServerPos3d
import su.plo.voice.api.server.player.VoicePlayer
import su.plo.voice.discs.DiscsPlugin
import su.plo.voice.discs.utils.SchedulerUtil.suspendSync
import su.plo.voice.discs.utils.extend.*
import su.plo.voice.discs.utils.extend.asJukebox
import su.plo.voice.discs.utils.extend.asVoicePlayer
import su.plo.voice.discs.utils.extend.customDiscIdentifier
import su.plo.voice.discs.utils.extend.getMinecraftVersionInt
import su.plo.voice.discs.utils.extend.isBeaconBaseBlock
import su.plo.voice.discs.utils.extend.isCustomDisc
import su.plo.voice.discs.utils.extend.isJukebox
import su.plo.voice.discs.utils.extend.stopPlayingWithUpdate

class JukeboxEventListener(
private val plugin: DiscsPlugin
Expand Down Expand Up @@ -83,7 +96,12 @@ class JukeboxEventListener(

val item = event.item?.takeIf { it.isCustomDisc(plugin) } ?: return

val voicePlayer = event.player.asVoicePlayer(plugin.voiceServer) ?: return
val player = event.player
.takeIf {
Bukkit.getServer().getMinecraftVersionInt() < 12100 || !it.isSneaking
} ?: return

val voicePlayer = player.asVoicePlayer(plugin.voiceServer) ?: return

if (!voicePlayer.instance.hasPermission("pv.addon.discs.play")) return

Expand Down Expand Up @@ -181,6 +199,7 @@ class JukeboxEventListener(
}
plugin.addonConfig.distance.beaconLikeDistanceList[beaconLevel]
}

false -> plugin.addonConfig.distance.jukeboxDistance
}

Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/su/plo/voice/discs/utils/extend/Server.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package su.plo.voice.discs.utils.extend

import org.bukkit.Bukkit
import org.bukkit.Server

fun Server.getMinecraftVersionInt(): Int {
val versions = Bukkit.getVersion()
.substring(version.lastIndexOf(" ") + 1, version.length - 1)
.split(".")
.mapNotNull { it.toIntOrNull() }
.let {
listOf(
it.getOrNull(0) ?: 0,
it.getOrNull(1) ?: 0,
it.getOrNull(2) ?: 0
)
}

return versions[0] * 10000 + versions[1] * 100 + versions[2]
}

0 comments on commit 3b901de

Please sign in to comment.