Skip to content

Commit

Permalink
fix: ignore disc insert if player is sneaking on 1.21+
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Jul 5, 2024
1 parent 38f62ed commit 32f4329
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
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 32f4329

Please sign in to comment.