Skip to content

Commit

Permalink
fix: disallow burning custom goat horn with tracks exceeding the maxi…
Browse files Browse the repository at this point in the history
…mum duration
  • Loading branch information
Apehum committed Oct 7, 2024
1 parent 56dd43c commit 60e338a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fix `/disc burn` produces broken goat horns in 1.20.1. This fix will not repair broken horns, so you need to do it manually by using command: `/item replace entity @p weapon.mainhand with minecraft:goat_horn{instrument:"empty"}`.
- Disallow burning custom goat horn with tracks exceeding the maximum duration defined in the config.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.koin.core.component.inject
import su.plo.slib.api.chat.component.McTextComponent
import su.plo.slib.api.permission.PermissionDefault
import su.plo.voice.api.server.player.VoicePlayer
import su.plo.voice.discs.GoatHornManager
import su.plo.voice.discs.command.SubCommand
import su.plo.voice.discs.item.GoatHornHelper
import su.plo.voice.discs.utils.extend.asPlayer
Expand All @@ -28,7 +29,8 @@ import su.plo.voice.discs.utils.extend.toPlainText
class BurnCommand : SubCommand() {

private val plugin: JavaPlugin by inject()
private val goatHornHelper: GoatHornHelper by inject()
private val hornHelper: GoatHornHelper by inject()
private val hornManager: GoatHornManager by inject()

override val name = "burn"

Expand Down Expand Up @@ -113,6 +115,13 @@ class BurnCommand : SubCommand() {

val isGoatHorn = item.type.name == "GOAT_HORN"

if (isGoatHorn && !hornManager.canPlay(track)) {
voicePlayer.instance.sendTranslatable(
"pv.addon.discs.error.horn_too_long", config.goatHorn.maxDurationSeconds
)
return@launch
}

plugin.suspendSync(player.location) {
item.editMeta { meta ->
meta.addItemFlags(*ItemFlag.values())
Expand All @@ -129,7 +138,7 @@ class BurnCommand : SubCommand() {
}

if (isGoatHorn) {
goatHornHelper.getInstrument(item)
hornHelper.getInstrument(item)
.takeIf { it.isNotEmpty() }
?.let {
meta.persistentDataContainer.set(
Expand All @@ -150,7 +159,7 @@ class BurnCommand : SubCommand() {
}

if (isGoatHorn) {
goatHornHelper.setEmptyInstrument(item)
hornHelper.setEmptyInstrument(item)
}

voicePlayer.instance.sendTranslatable("pv.addon.discs.success.burn", name)
Expand Down

0 comments on commit 60e338a

Please sign in to comment.