Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
fix: Disks -> Discs
Browse files Browse the repository at this point in the history
  • Loading branch information
kpids committed Mar 4, 2023
1 parent f8698d0 commit a835df7
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 112 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# pv-addon-disks
Paper only [Plasmo Voice](https://github.com/plasmoapp/plasmo-voice) addon. Play audio from Youtube and other sources in Minecraft using music disks.
# pv-addon-discs
Paper only [Plasmo Voice](https://github.com/plasmoapp/plasmo-voice) addon. Play audio from Youtube and other sources in Minecraft using music discs.

The addon can stream audio from various sources instead of saving audio files on the server. It even supports Youtube and Twitch live streams. Thanks to the brilliant [LavaPlayer](https://github.com/sedmelluq/lavaplayer) library.

**Depends on [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/)**

Inspired by [SVC](https://github.com/henkelmax/simple-voice-chat)'s [AudioPlayer](https://github.com/henkelmax/audio-player) & [CustomDisks](https://github.com/Navoei/CustomDiscs).
Inspired by [SVC](https://github.com/henkelmax/simple-voice-chat)'s [AudioPlayer](https://github.com/henkelmax/audio-player) & [Customdiscs](https://github.com/Navoei/CustomDiscs).

## Commands

Expand All @@ -17,13 +17,13 @@ Inspired by [SVC](https://github.com/henkelmax/simple-voice-chat)'s [AudioPlayer

Commands are only available to OP by default:

`pv.addon.disks.burn` – Burn command
`pv.addon.discs.burn` – Burn command

`pv.addon.disks.erase` – Erase command
`pv.addon.discs.erase` – Erase command

Available to everyone by default:

`pv.addon.disks.play` – Use custom music disks
`pv.addon.discs.play` – Use custom music discs

## Supported sources

Expand Down Expand Up @@ -51,7 +51,7 @@ If you want to stream audio from direct URLs

## Planned features

- Copy disks like you can copy maps
- Copy discs like you can copy maps
- YouTube search
- Set distance on a jukebox
- Custom goat horn audio
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ tasks {

bukkit {
load = net.minecrell.pluginyml.bukkit.BukkitPluginDescription.PluginLoadOrder.STARTUP
main = "su.plo.voice.disks.DisksPlugin"
main = "su.plo.voice.discs.DiscsPlugin"
apiVersion = "1.19"
authors = listOf("KPidS", "Apehum")

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ paperVersion=1.19-R0.1-SNAPSHOT
kotlinVersion=1.8.10

# Version
mavenGroup=su.plo.voice.disks
mavenArtifactId=disks
mavenGroup=su.plo.voice.discs
mavenArtifactId=discs
pluginVersion=1.0.0

# Dev
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pluginManagement {
}
}

rootProject.name = "pv-addon-disks"
rootProject.name = "pv-addon-discs"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package su.plo.voice.disks
package su.plo.voice.discs

import org.bukkit.Bukkit
import su.plo.config.Config
Expand All @@ -18,8 +18,8 @@ class AddonConfig {
@ConfigField(path = "default_jukebox_distance")
var jukeboxDistance = 65

@ConfigField(path = "add_glint_to_custom_disks")
var addGlintToCustomDisks = false
@ConfigField(path = "add_glint_to_custom_discs")
var addGlintToCustomDiscs = false

companion object {
fun loadConfig(server: PlasmoVoiceServer): AddonConfig {
Expand All @@ -32,22 +32,22 @@ class AddonConfig {
File(addonFolder, "languages")
)

val configFile = File(addonFolder, "disks.toml")
val configFile = File(addonFolder, "discs.toml")

return toml.load<AddonConfig>(AddonConfig::class.java, configFile, false)
.also { toml.save(AddonConfig::class.java, it, configFile) }
}

@Throws(IOException::class)
private fun getLanguageResource(resourcePath: String): InputStream? {
return javaClass.classLoader.getResourceAsStream(String.format("disks/%s", resourcePath))
return javaClass.classLoader.getResourceAsStream(String.format("discs/%s", resourcePath))
}

private val toml = ConfigurationProvider.getProvider<ConfigurationProvider>(
TomlConfiguration::class.java
)

private fun getAddonFolder(): File =
File(Bukkit.getPluginsFolder(), "pv-addon-disks")
File(Bukkit.getPluginsFolder(), "pv-addon-discs")
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package su.plo.voice.disks
package su.plo.voice.discs

import com.comphenix.protocol.ProtocolLibrary
import com.comphenix.protocol.ProtocolManager
Expand All @@ -7,24 +7,24 @@ import com.google.inject.Inject
import org.bukkit.NamespacedKey
import org.bukkit.plugin.java.JavaPlugin
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.disks.event.JukeboxEventListener
import su.plo.voice.discs.event.JukeboxEventListener
import su.plo.voice.api.addon.AddonManager
import su.plo.voice.api.addon.AddonScope
import su.plo.voice.api.addon.annotation.Addon
import su.plo.voice.api.event.EventSubscribe
import su.plo.voice.api.server.PlasmoVoiceServer
import su.plo.voice.api.server.audio.line.ServerSourceLine
import su.plo.voice.api.server.event.config.VoiceServerConfigLoadedEvent
import su.plo.voice.disks.command.subcommand.BurnCommand
import su.plo.voice.disks.command.CommandHandler
import su.plo.voice.disks.command.subcommand.EraseCommand
import su.plo.voice.disks.packet.CancelJukeboxPlayEvent
import su.plo.voice.discs.command.subcommand.BurnCommand
import su.plo.voice.discs.command.CommandHandler
import su.plo.voice.discs.command.subcommand.EraseCommand
import su.plo.voice.discs.packet.CancelJukeboxPlayEvent


@Addon(id = "disks", scope = AddonScope.SERVER, version = "1.0.0", authors = ["KPidS"])
class DisksPlugin : JavaPlugin() {
@Addon(id = "discs", scope = AddonScope.SERVER, version = "1.0.0", authors = ["KPidS"])
class DiscsPlugin : JavaPlugin() {

private val addonName = "disks"
private val addonName = "discs"

@Inject
lateinit var voiceServer: PlasmoVoiceServer
Expand Down Expand Up @@ -70,7 +70,7 @@ class DisksPlugin : JavaPlugin() {
command.tabCompleter = handler

voiceServer.minecraftServer.permissionsManager
.register("pv.addon.disks.play", PermissionDefault.TRUE)
.register("pv.addon.discs.play", PermissionDefault.TRUE)

val protocolManager: ProtocolManager = ProtocolLibrary.getProtocolManager()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package su.plo.voice.disks
package su.plo.voice.discs

import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager
Expand All @@ -15,7 +15,6 @@ import su.plo.voice.proto.packets.tcp.clientbound.SourceAudioEndPacket
import su.plo.voice.proto.packets.udp.clientbound.SourceAudioPacket
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
import kotlin.jvm.Throws

class PlasmoAudioPlayerManager(
private val voiceServer: PlasmoVoiceServer,
Expand Down Expand Up @@ -53,6 +52,7 @@ class PlasmoAudioPlayerManager(
source.id,
distance
)

source.sendAudioPacket(packet, distance)

if (start == 0L) start = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package su.plo.voice.disks.command
package su.plo.voice.discs.command

import net.kyori.adventure.text.Component
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import su.plo.lib.api.chat.MinecraftTextComponent
import su.plo.lib.api.server.command.MinecraftCommandSource
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.disks.DisksPlugin
import su.plo.voice.disks.utils.extend.asPlayer
import su.plo.voice.disks.utils.extend.asVoicePlayer
import su.plo.voice.discs.DiscsPlugin
import su.plo.voice.discs.utils.extend.asPlayer
import su.plo.voice.discs.utils.extend.asVoicePlayer
import su.plo.voice.groups.command.SubCommand
import java.util.concurrent.ConcurrentHashMap

open class CommandHandler(
val plugin: DisksPlugin,
val plugin: DiscsPlugin,
): CommandExecutor, TabCompleter {

private val subCommands: MutableMap<String, SubCommand> = ConcurrentHashMap()
Expand All @@ -30,14 +29,14 @@ open class CommandHandler(
private fun registerPermissions(permissions: List<Pair<String, PermissionDefault>>) {
permissions.forEach {
plugin.voiceServer.minecraftServer.permissionsManager.register(
"pv.addon.disks.${it.first}",
"pv.addon.discs.${it.first}",
it.second
)
}
}

private val unknownCommandComponent = MinecraftTextComponent.translatable(
"pv.addon.disks.error.unknown_subcommand",
"pv.addon.discs.error.unknown_subcommand",
subCommands.keys.joinToString(", ")
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package su.plo.voice.groups.command

import org.bukkit.command.CommandSender
import su.plo.lib.api.server.command.MinecraftCommandSource
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.disks.command.CommandHandler
import su.plo.voice.discs.command.CommandHandler

abstract class SubCommand(val handler: CommandHandler) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package su.plo.voice.disks.command.subcommand
package su.plo.voice.discs.command.subcommand

import com.sedmelluq.discord.lavaplayer.tools.FriendlyException
import net.kyori.adventure.text.Component
Expand All @@ -9,10 +9,10 @@ import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemFlag
import org.bukkit.persistence.PersistentDataType
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.disks.command.CommandHandler
import su.plo.voice.disks.utils.extend.asPlayer
import su.plo.voice.disks.utils.extend.asVoicePlayer
import su.plo.voice.disks.utils.extend.sendTranslatable
import su.plo.voice.discs.command.CommandHandler
import su.plo.voice.discs.utils.extend.asPlayer
import su.plo.voice.discs.utils.extend.asVoicePlayer
import su.plo.voice.discs.utils.extend.sendTranslatable
import su.plo.voice.groups.command.SubCommand
import java.util.concurrent.ExecutionException

Expand All @@ -28,10 +28,10 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {
val voicePlayer = source.asPlayer()?.asVoicePlayer(handler.plugin.voiceServer) ?: return listOf()
if (arguments.size < 2 ) return listOf()
if (arguments.size == 2) return listOf(
handler.getTranslationStringByKey("pv.addon.disks.arg.url", voicePlayer.instance)
handler.getTranslationStringByKey("pv.addon.discs.arg.url", voicePlayer.instance)
)
return listOf(
handler.getTranslationStringByKey("pv.addon.disks.arg.label", voicePlayer.instance)
handler.getTranslationStringByKey("pv.addon.discs.arg.label", voicePlayer.instance)
)
}

Expand All @@ -40,7 +40,7 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {
val voicePlayer = sender.asPlayer()?.asVoicePlayer(handler.plugin.voiceServer) ?: return

val identifier = arguments.getOrNull(1) ?: run {
voicePlayer.instance.sendTranslatable("pv.addon.disks.usage.burn")
voicePlayer.instance.sendTranslatable("pv.addon.discs.usage.burn")
return
}

Expand All @@ -51,7 +51,7 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {
is FriendlyException -> (e.cause as FriendlyException).message
else -> e.message
}
voicePlayer.instance.sendTranslatable("pv.addon.disks.error.get_track_fail", message)
voicePlayer.instance.sendTranslatable("pv.addon.discs.error.get_track_fail", message)
return
}

Expand All @@ -66,7 +66,7 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {

val meta = player.inventory.itemInMainHand
.also { if (!it.type.isRecord) {
voicePlayer.instance.sendTranslatable("pv.addon.disks.error.not_a_record")
voicePlayer.instance.sendTranslatable("pv.addon.discs.error.not_a_record")
return
}}
.itemMeta
Expand All @@ -79,7 +79,7 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {
identifier
)

if (handler.plugin.addonConfig.addGlintToCustomDisks) {
if (handler.plugin.addonConfig.addGlintToCustomDiscs) {
meta.addEnchant(Enchantment.MENDING, 1, false)
}

Expand All @@ -93,8 +93,8 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {

player.inventory.itemInMainHand.itemMeta = meta

voicePlayer.instance.sendTranslatable("pv.addon.disks.success.burn", name)
voicePlayer.instance.sendTranslatable("pv.addon.discs.success.burn", name)
}

override fun checkCanExecute(sender: CommandSender): Boolean = sender.hasPermission("pv.addon.disks.burn")
override fun checkCanExecute(sender: CommandSender): Boolean = sender.hasPermission("pv.addon.discs.burn")
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package su.plo.voice.disks.command.subcommand
package su.plo.voice.discs.command.subcommand

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextDecoration
import org.bukkit.NamespacedKey
import org.bukkit.Server
import org.bukkit.command.CommandSender
import org.bukkit.inventory.ItemFactory
import org.bukkit.inventory.ItemFlag
import org.bukkit.persistence.PersistentDataType
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.disks.command.CommandHandler
import su.plo.voice.disks.utils.extend.asPlayer
import su.plo.voice.disks.utils.extend.asVoicePlayer
import su.plo.voice.disks.utils.extend.sendTranslatable
import su.plo.voice.discs.command.CommandHandler
import su.plo.voice.discs.utils.extend.asPlayer
import su.plo.voice.discs.utils.extend.asVoicePlayer
import su.plo.voice.discs.utils.extend.sendTranslatable
import su.plo.voice.groups.command.SubCommand

class EraseCommand(handler: CommandHandler) : SubCommand(handler) {
Expand All @@ -36,17 +28,17 @@ class EraseCommand(handler: CommandHandler) : SubCommand(handler) {
val item = player.inventory.itemInMainHand
.takeIf { it.type.isRecord && it.hasItemMeta() }
?: run {
voicePlayer.instance.sendTranslatable("pv.addon.disks.error.erase_wrong_item")
voicePlayer.instance.sendTranslatable("pv.addon.discs.error.erase_wrong_item")
return
}

val meta = source.server.itemFactory.getItemMeta(item.type)

item.itemMeta = meta

voicePlayer.instance.sendTranslatable("pv.addon.disks.success.erase")
voicePlayer.instance.sendTranslatable("pv.addon.discs.success.erase")
}

override fun checkCanExecute(sender: CommandSender): Boolean =
sender.hasPermission("pv.addon.disks.erase")
sender.hasPermission("pv.addon.discs.erase")
}
Loading

0 comments on commit a835df7

Please sign in to comment.