diff --git a/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt b/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt index 36b9a3b..97013e3 100644 --- a/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt +++ b/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt @@ -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) } } @@ -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 diff --git a/src/main/kotlin/su/plo/voice/discs/utils/extend/Server.kt b/src/main/kotlin/su/plo/voice/discs/utils/extend/Server.kt index e8502b8..c499b07 100644 --- a/src/main/kotlin/su/plo/voice/discs/utils/extend/Server.kt +++ b/src/main/kotlin/su/plo/voice/discs/utils/extend/Server.kt @@ -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] +} \ No newline at end of file