Skip to content

Commit

Permalink
feat: experimental config option to change lore burn method
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Apr 29, 2024
1 parent 42012ed commit b295901
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ lavaplayerLibVersion=1.0.8
# Version
mavenGroup=su.plo.voice.discs
mavenArtifactId=discs
pluginVersion=1.0.6
pluginVersion=1.0.7
19 changes: 19 additions & 0 deletions src/main/kotlin/su/plo/voice/discs/AddonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ 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.
"""
)
var burnLoreMethod = LoreMethod.REPLACE

@Config class DistanceConfig {

@ConfigField(
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import su.plo.voice.discs.utils.extend.debug
@Addon(
id = "pv-addon-discs",
scope = AddonLoaderScope.SERVER,
version = "1.0.6",
authors = ["KPidS"]
version = "1.0.7",
authors = ["KPidS", "Apehum"]
)
class DiscsPlugin : JavaPlugin() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.api.server.player.VoicePlayer
import su.plo.voice.discs.AddonConfig
import su.plo.voice.discs.DiscsPlugin
import su.plo.voice.discs.command.CommandHandler
import su.plo.voice.discs.command.SubCommand
import su.plo.voice.discs.utils.SchedulerUtil.suspendSync
import su.plo.voice.discs.utils.extend.asPlayer
import su.plo.voice.discs.utils.extend.asVoicePlayer
import su.plo.voice.discs.utils.extend.isCustomDisc
import su.plo.voice.discs.utils.extend.sendTranslatable

class BurnCommand(handler: CommandHandler) : SubCommand(handler) {
Expand Down Expand Up @@ -124,7 +126,25 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {
.color(NamedTextColor.GRAY)
.build()

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

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

meta.lore(currentLore + listOf(loreName))
}

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

voicePlayer.instance.sendTranslatable("pv.addon.discs.success.burn", name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemFlag
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.discs.AddonConfig
import su.plo.voice.discs.command.CommandHandler
import su.plo.voice.discs.command.SubCommand
import su.plo.voice.discs.utils.extend.asPlayer
Expand Down Expand Up @@ -48,7 +49,25 @@ class EraseCommand(handler: CommandHandler) : SubCommand(handler) {
meta.removeEnchant(Enchantment.MENDING)
}

meta.lore(null)
when (handler.plugin.addonConfig.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
}
}

voicePlayer.instance.sendTranslatable("pv.addon.discs.success.erase")
Expand Down

0 comments on commit b295901

Please sign in to comment.