Skip to content

Commit

Permalink
feat: reimplement lore burn method #41
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Dec 6, 2024
1 parent d1fdebe commit 88ae0c0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
10 changes: 4 additions & 6 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
- Yet another lavaplayer update to fix playback issues.
- Addons' permissions are now registered in Bukkit permissions. This resolves auto-complete and goat horns not working properly.
- New config option `mono_sources` to use mono sources for playing the audio.
- `/vreload` command is now reloading the addon's config properly.
- Add [poToken](https://github.com/lavalink-devs/youtube-source?tab=readme-ov-file#using-a-potoken) support for YouTube source.
- Fixed discs commands not working properly after `/vreload`.
- Added option to change lore burning method (`burn_lore_method` in the addon config):
- DISABLE — Disables any lore manipulations on burn/erase.
- REPLACE (default) — Replaces the whole lore with a string containing the song name on burn, and removes the lore completely on erase.
- APPEND — Adds a new line to the end of the lore on burn, and removes the last line on erase.
18 changes: 18 additions & 0 deletions core/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ class AddonConfig {
)
var addGlintToCustomDiscs = false

enum class LoreMethod {
DISABLE,
REPLACE,
APPEND
}
@ConfigField(
comment = """
The method for creating/removing a lore on burning/erasing the discs:
DISABLE — Disables any lore manipulations on burn/erase.
REPLACE — Replaces the whole lore with a string containing the song name on burn, and removes the lore completely on erase.
APPEND — Adds a new line to the end of the lore on burn, and removes the last line on erase.
Default is REPLACE.
"""
)
val burnLoreMethod = LoreMethod.REPLACE

@ConfigField(
comment = """
Uses mono sources to play tracks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ 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.AddonConfig
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
import su.plo.voice.discs.utils.extend.asVoicePlayer
import su.plo.voice.discs.utils.extend.forbidGrindstone
import su.plo.voice.discs.utils.extend.isCustomDisc
import su.plo.voice.discs.utils.extend.render
import su.plo.voice.discs.utils.extend.sendTranslatable
import su.plo.voice.discs.utils.extend.suspendSync
Expand Down Expand Up @@ -155,7 +157,24 @@ class BurnCommand : SubCommand() {
.color(NamedTextColor.GRAY)
.build()

meta.lore(listOf(loreName))
when (config.burnLoreMethod) {
AddonConfig.LoreMethod.REPLACE -> {
meta.lore(listOf(loreName))
}

AddonConfig.LoreMethod.APPEND -> {
val currentLore = meta.lore()?.let {
if (with(keys) { item.isCustomDisc() }) {
it.subList(0, it.size - 1)
} else {
it
}
} ?: emptyList()
meta.lore(currentLore + listOf(loreName))
}

AddonConfig.LoreMethod.DISABLE -> {} // do nothing
}
}

if (isGoatHorn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemFlag
import org.bukkit.persistence.PersistentDataType
import org.koin.core.component.inject
import su.plo.slib.api.permission.PermissionDefault
import su.plo.voice.discs.AddonConfig
import su.plo.voice.discs.command.SubCommand
import su.plo.voice.discs.item.GoatHornHelper
import su.plo.voice.discs.utils.extend.allowGrindstone
Expand Down Expand Up @@ -53,7 +54,24 @@ class EraseCommand : SubCommand() {
meta.removeEnchant(Enchantment.MENDING)
}

meta.lore(null)
when (config.burnLoreMethod) {
AddonConfig.LoreMethod.REPLACE -> {
meta.lore(null)
}

AddonConfig.LoreMethod.APPEND -> {
val currentLore = meta.lore() ?: return@editMeta
if (currentLore.isEmpty()) return@editMeta
val newLore = currentLore.subList(0, currentLore.size - 1)
if (newLore.isEmpty()) {
meta.lore(null)
} else {
meta.lore(newLore)
}
}

AddonConfig.LoreMethod.DISABLE -> {} // do nothing
}
}

if (item.type.name == "GOAT_HORN") {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=su.plo.voice.discs
version=1.1.3
version=1.1.4
mavenArtifactId=discs

0 comments on commit 88ae0c0

Please sign in to comment.