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 bb3de50 commit f287031
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class JukeboxEventListener(
private val scope = CoroutineScope(Dispatchers.Default)

init {
if (Bukkit.getServer().isVersionGreaterOrEqual("1.19.4")) {
if (Bukkit.getServer().getMinecraftVersionInt() >= 11904) {
Bukkit.getServer().pluginManager.registerEvents(HopperEventListener(), plugin)
}
}
Expand Down Expand Up @@ -79,7 +79,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
29 changes: 14 additions & 15 deletions src/main/kotlin/su/plo/voice/discs/utils/extend/Server.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package su.plo.voice.discs.utils.extend

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

fun Server.isVersionGreaterOrEqual(minVersion: String): Boolean {
val currentParts = minecraftVersion.split(".")
val targetParts = minVersion.split(".")

for (i in 0 until currentParts.size.coerceAtMost(targetParts.size)) {
val currentPart = currentParts[i].toInt()
val targetPart = targetParts[i].toInt()

if (currentPart < targetPart) {
return false
} else if (currentPart > targetPart) {
return true
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 true
}
return versions[0] * 10000 + versions[1] * 100 + versions[2]
}

0 comments on commit f287031

Please sign in to comment.