From b29590160e07004430aab79dc104e3f1d6d3a8be Mon Sep 17 00:00:00 2001 From: Apehum Date: Mon, 29 Apr 2024 16:13:22 +0800 Subject: [PATCH 1/6] feat: experimental config option to change lore burn method --- gradle.properties | 2 +- .../kotlin/su/plo/voice/discs/AddonConfig.kt | 19 ++++++++++++++++ .../kotlin/su/plo/voice/discs/DiscsPlugin.kt | 4 ++-- .../discs/command/subcommand/BurnCommand.kt | 22 ++++++++++++++++++- .../discs/command/subcommand/EraseCommand.kt | 21 +++++++++++++++++- 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index fde083f..f9ba4f1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ lavaplayerLibVersion=1.0.8 # Version mavenGroup=su.plo.voice.discs mavenArtifactId=discs -pluginVersion=1.0.6 +pluginVersion=1.0.7 diff --git a/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt b/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt index ef2995b..c5d25a9 100644 --- a/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt +++ b/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt @@ -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( diff --git a/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt b/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt index 9737a87..a450f8f 100644 --- a/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt +++ b/src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt @@ -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() { diff --git a/src/main/kotlin/su/plo/voice/discs/command/subcommand/BurnCommand.kt b/src/main/kotlin/su/plo/voice/discs/command/subcommand/BurnCommand.kt index f3da41e..b88dde5 100644 --- a/src/main/kotlin/su/plo/voice/discs/command/subcommand/BurnCommand.kt +++ b/src/main/kotlin/su/plo/voice/discs/command/subcommand/BurnCommand.kt @@ -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) { @@ -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) diff --git a/src/main/kotlin/su/plo/voice/discs/command/subcommand/EraseCommand.kt b/src/main/kotlin/su/plo/voice/discs/command/subcommand/EraseCommand.kt index e9fcbb1..155c277 100644 --- a/src/main/kotlin/su/plo/voice/discs/command/subcommand/EraseCommand.kt +++ b/src/main/kotlin/su/plo/voice/discs/command/subcommand/EraseCommand.kt @@ -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 @@ -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") From 810968d45be9c10bb88607aefdc88f7390904360 Mon Sep 17 00:00:00 2001 From: Apehum Date: Mon, 29 Apr 2024 16:15:59 +0800 Subject: [PATCH 2/6] ci: change changelog [ci skip] --- changelog.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index e72060d..a996692 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,4 @@ **Requires [pv-addon-lavaplayer-lib 1.0.8+](https://modrinth.com/plugin/pv-addon-lavaplayer-lib/version/1.0.8) to work** Changelog: -- Hopper interactions support -- 1.20 discs burnable craft -- Fixed empty suggestions when using the /disc command -- Config option to disable voice distance visualization [#10](https://github.com/plasmoapp/pv-addon-discs/issues/10) +- Config option to change lore burn method From 20c7067aab0b6cddedcc2b936c2dbce3e84a0830 Mon Sep 17 00:00:00 2001 From: Apehum Date: Wed, 19 Jun 2024 01:27:24 +0800 Subject: [PATCH 3/6] fix: find jobs to unload by iterating jobByBlock instead of Chunk#getTileEntities --- .../su/plo/voice/discs/event/JukeboxEventListener.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 398a1cd..d42c0d6 100644 --- a/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt +++ b/src/main/kotlin/su/plo/voice/discs/event/JukeboxEventListener.kt @@ -61,9 +61,12 @@ class JukeboxEventListener( @EventHandler fun onChunkUnload(event: ChunkUnloadEvent) { - event.chunk.getTileEntities({ it.isJukebox() }, true) + val chunk = event.chunk + + jobByBlock.keys + .filter { it.chunk == chunk } .forEach { - jobByBlock.remove(it.block)?.cancel() + jobByBlock.remove(it)?.cancel() } } From 6664c13522741aa7d72fce74c3ae01e224352f91 Mon Sep 17 00:00:00 2001 From: TABURELTER <60186624+TABURELTER@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:55:36 +0300 Subject: [PATCH 4/6] fix: use plugin's data folder in AddonConfig (#60) fix java.lang.NoSuchMethodError: 'java.io.File org.bukkit.Bukkit.getPluginsFolder()' --- src/main/kotlin/su/plo/voice/discs/AddonConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt b/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt index c5d25a9..e944749 100644 --- a/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt +++ b/src/main/kotlin/su/plo/voice/discs/AddonConfig.kt @@ -172,6 +172,6 @@ class AddonConfig { ) private fun getAddonFolder(): File = - File(Bukkit.getPluginsFolder(), "pv-addon-discs") + Bukkit.getPluginManager().getPlugin("pv-addon-discs")!!.getDataFolder() } } From db9cc3b3cff35824973864e4cd17db94f44f45b9 Mon Sep 17 00:00:00 2001 From: Apehum Date: Fri, 21 Jun 2024 22:16:30 +0800 Subject: [PATCH 5/6] fix: find all disc materials by filtering materials with "MUSIC_DISC_*" (#61) --- .../su/plo/voice/discs/crafting/BurnableDiscCraft.kt | 4 ++-- .../kotlin/su/plo/voice/discs/utils/MaterialUtil.kt | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/su/plo/voice/discs/utils/MaterialUtil.kt diff --git a/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt b/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt index 47abde8..5bdf11a 100644 --- a/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt +++ b/src/main/kotlin/su/plo/voice/discs/crafting/BurnableDiscCraft.kt @@ -6,17 +6,17 @@ import net.kyori.adventure.text.format.TextDecoration import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.NamespacedKey -import org.bukkit.Tag import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.* import org.bukkit.persistence.PersistentDataType import su.plo.voice.discs.DiscsPlugin +import su.plo.voice.discs.utils.MaterialUtil class BurnableDiscCraft(val plugin: DiscsPlugin) { private val groupKey = NamespacedKey(plugin, "burnable_record_craft") - fun registerRecipes() = Tag.ITEMS_MUSIC_DISCS.values.forEach { record -> + fun registerRecipes() = MaterialUtil.itemMusicDiscs.forEach { record -> createRecipe(record).let(Bukkit::addRecipe) } diff --git a/src/main/kotlin/su/plo/voice/discs/utils/MaterialUtil.kt b/src/main/kotlin/su/plo/voice/discs/utils/MaterialUtil.kt new file mode 100644 index 0000000..d75d61e --- /dev/null +++ b/src/main/kotlin/su/plo/voice/discs/utils/MaterialUtil.kt @@ -0,0 +1,10 @@ +package su.plo.voice.discs.utils + +import org.bukkit.Material + +object MaterialUtil { + + val itemMusicDiscs: List = + Material.values() + .filter { it.name.startsWith("MUSIC_DISC_") } +} From 38f62ed75112db1bb0750824ea1310ef6409f070 Mon Sep 17 00:00:00 2001 From: Apehum Date: Fri, 21 Jun 2024 22:17:34 +0800 Subject: [PATCH 6/6] ci: update changelog [ci skip] --- .github/workflows/publish.yml | 2 ++ changelog.md | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 50de275..0c83ccc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -47,6 +47,8 @@ jobs: 1.20.2 1.20.3 1.20.4 + 1.20.6 + 1.21 - name: Publish to GitHub uses: Apehum/mc-publish@v1.1 diff --git a/changelog.md b/changelog.md index a996692..cef260a 100644 --- a/changelog.md +++ b/changelog.md @@ -2,3 +2,4 @@ Changelog: - Config option to change lore burn method +- 1.21 support