From 99ae61fdd4ddf21337d5484500899a18575ae89f Mon Sep 17 00:00:00 2001 From: Athar42 Date: Thu, 26 Jun 2025 01:25:32 +0200 Subject: [PATCH 1/4] Add support to 1.21.6 + use URI (with URI to URL) for download links (better input validation, to avoid bad/malformed URL) - Updating CommandAPI to 10.1.0, - Updating Gradle to 8.14.2, - Updating Shadow to 8.3.6 - Remove a duplicate repository declaration (and typo fix) --- build.gradle | 18 +++-- gradle.properties | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- readme.md | 2 +- .../SubCommands/DownloadSubCommand.java | 69 +++++++++++-------- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/build.gradle b/build.gradle index 28416ff..65ba108 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,17 @@ plugins { id 'java' - id "com.gradleup.shadow" version "8.3.5" + id "com.gradleup.shadow" version "8.3.6" } -sourceCompatibility = JavaLanguageVersion.of(java_version as int) -targetCompatibility = JavaLanguageVersion.of(java_version as int) +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + +base { + archivesName = archives_base_name +} -archivesBaseName = archives_base_name version = plugin_version group = maven_group @@ -40,12 +45,12 @@ dependencies { implementation "de.maxhenkel.voicechat:voicechat-api:${voicechat_api_version}" shadow "dev.jorel:commandapi-bukkit-shade:${command_api_version}" - compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.3.0"; + compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.3.0" } repositories { mavenCentral() - maven { url "https://repo.dmulloy2.net/repository/public/" } + maven { url = "https://repo.dmulloy2.net/repository/public/" } maven { name = "henkelmax.public" url = 'https://maven.maxhenkel.de/repository/public' @@ -55,7 +60,6 @@ repositories { name = "papermc" url = uri("https://repo.papermc.io/repository/maven-public/") } - maven { url "https://repo.dmulloy2.net/repository/public/" } maven { url = "https://repo.codemc.org/repository/maven-public/" } mavenLocal() diff --git a/gradle.properties b/gradle.properties index 55239be..5603c53 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,13 +5,13 @@ java_version=21 mp3spi_version=1.9.5.4 bukkit_api_version=1.21 -bukkit_version=1.21.5-R0.1-SNAPSHOT +bukkit_version=1.21.6-R0.1-SNAPSHOT mod_id=customdiscsplugin # Target an older API to make it compatible with older versions of Simple Voice Chat voicechat_api_version=2.3.3 -command_api_version=10.0.1 +command_api_version=10.1.0 -plugin_version=4.4 +plugin_version=4.5 maven_group=me.Navoei.customdiscsplugin archives_base_name=custom-discs \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2598c65..1dd35f4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sun Aug 11 17:52:06 EDT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/readme.md b/readme.md index 32156fd..de44a65 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Custom Discs v4.4 for Paper 1.21.5 +# Custom Discs v4.5 for Paper 1.21.6 A Paper fork of henkelmax's Audio Player. Special thanks to Athar42 for maintaining this plugin. - Play custom music discs using the Simple Voice Chat API. (The voice chat mod is required on the client and server.) diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadSubCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadSubCommand.java index 6acf8c4..60a4f69 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadSubCommand.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadSubCommand.java @@ -16,7 +16,10 @@ import org.codehaus.plexus.util.FileUtils; import java.io.File; import java.io.IOException; import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URLConnection; +import java.net.MalformedURLException; import java.nio.file.Path; import java.util.Objects; @@ -45,43 +48,51 @@ public class DownloadSubCommand extends CommandAPICommand { Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { try { - URL fileURL = new URL(Objects.requireNonNull(arguments.getByClass("url", String.class))); - String filename = Objects.requireNonNull(arguments.getByClass("filename", String.class)); - if (filename.contains("../")) { - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_FILENAME.toString())); - return; - } - - System.out.println(filename); - - if (!getFileExtension(filename).equals("wav") && !getFileExtension(filename).equals("mp3") && !getFileExtension(filename).equals("flac")) { - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_FORMAT.toString())); - return; - } - - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.DOWNLOADING_FILE.toString())); - - URLConnection connection = fileURL.openConnection(); - if (connection != null) { - long size = connection.getContentLengthLong() / 1048576; - if (size > this.plugin.getConfig().getInt("max-download-size", 50)) { - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.FILE_TOO_LARGE.toString().replace("%max_download_size%", String.valueOf(this.plugin.getConfig().getInt("max-download-size", 50))))); + try { + URI uri = new URI(Objects.requireNonNull(arguments.getByClass("url", String.class))); + URL fileURL = uri.toURL(); + String filename = Objects.requireNonNull(arguments.getByClass("filename", String.class)); + if (filename.contains("../")) { + player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_FILENAME.toString())); return; } + + //DEBUG + //System.out.println(filename); + + String fileExtension = getFileExtension(filename); + if (!fileExtension.equals("wav") && !fileExtension.equals("mp3") && !fileExtension.equals("flac")) { + player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_FORMAT.toString())); + return; + } + + player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.DOWNLOADING_FILE.toString())); + + URLConnection connection = fileURL.openConnection(); + if (connection != null) { + long size = connection.getContentLengthLong() / 1048576; + if (size > this.plugin.getConfig().getInt("max-download-size", 50)) { + player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.FILE_TOO_LARGE.toString().replace("%max_download_size%", String.valueOf(this.plugin.getConfig().getInt("max-download-size", 50))))); + return; + } + } + + Path downloadPath = Path.of(this.plugin.getDataFolder().getPath(), "musicdata", filename); + File downloadFile = downloadPath.toFile(); + FileUtils.copyURLToFile(fileURL, downloadFile); + + player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.SUCCESSFUL_DOWNLOAD.toString().replace("%file_path%", "plugins/CustomDiscs/musicdata/" + filename))); + player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_DISC.toString().replace("%filename%", filename))); + } catch (URISyntaxException | MalformedURLException e) { + player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.DOWNLOAD_ERROR.toString())); + e.printStackTrace(); } - - Path downloadPath = Path.of(this.plugin.getDataFolder().getPath(), "musicdata", filename); - File downloadFile = new File(downloadPath.toUri()); - FileUtils.copyURLToFile(fileURL, downloadFile); - - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.SUCCESSFUL_DOWNLOAD.toString().replace("%file_path%", "plugins/CustomDiscs/musicdata/" + filename))); - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_DISC.toString().replace("%filename%", filename))); } catch (IOException e) { player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.DOWNLOAD_ERROR.toString())); e.printStackTrace(); } }); - + return 1; } From 9f093e0227e6e700d5d12fd68a8048fe496d1f1e Mon Sep 17 00:00:00 2001 From: Athar42 Date: Thu, 26 Jun 2025 01:28:31 +0200 Subject: [PATCH 2/4] Forgot to update the dependencies versions in the readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index de44a65..107a6b2 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +21,7 @@ Permission Nodes (Required to run the commands. Playing discs does not require a - ```customdiscs.range``` to set the range of the disc Dependencies: -- This plugin depends on the latest version of ProtocolLib for 1.21.5 and SimpleVoiceChatBukkit version 2.5.30. +- This plugin depends on the latest version of ProtocolLib for 1.21.6 and SimpleVoiceChatBukkit version 2.5.31. https://user-images.githubusercontent.com/64107368/178426026-c454ac66-5133-4f3a-9af9-7f674e022423.mp4 From fe7cdc08602df8aa9f0a3025e2b90c9a0fe37908 Mon Sep 17 00:00:00 2001 From: Athar42 Date: Wed, 2 Jul 2025 18:40:33 +0200 Subject: [PATCH 3/4] Add support to 1.21.7 + prepare for an upcoming change in CommandAPI (disabled for now) - Updating CommandAPI to 10.1.1. --- build.gradle | 3 +++ gradle.properties | 4 ++-- readme.md | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 65ba108..da40844 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,9 @@ dependencies { implementation "io.papermc.paper:paper-api:${bukkit_version}" implementation "de.maxhenkel.voicechat:voicechat-api:${voicechat_api_version}" shadow "dev.jorel:commandapi-bukkit-shade:${command_api_version}" + // Next two are for testing of an upcoming CommandAPI change - Not yet available. + //shadow "dev.jorel:commandapi-paper-shade:${command_api_version}" + //shadow "dev.jorel:commandapi-paper-shade-mojang-mapped:${command_api_version}" compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.3.0" } diff --git a/gradle.properties b/gradle.properties index 5603c53..12d6712 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,12 +5,12 @@ java_version=21 mp3spi_version=1.9.5.4 bukkit_api_version=1.21 -bukkit_version=1.21.6-R0.1-SNAPSHOT +bukkit_version=1.21.7-R0.1-SNAPSHOT mod_id=customdiscsplugin # Target an older API to make it compatible with older versions of Simple Voice Chat voicechat_api_version=2.3.3 -command_api_version=10.1.0 +command_api_version=10.1.1 plugin_version=4.5 maven_group=me.Navoei.customdiscsplugin diff --git a/readme.md b/readme.md index 107a6b2..25dca8f 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Custom Discs v4.5 for Paper 1.21.6 +# Custom Discs v4.5 for Paper 1.21.7 A Paper fork of henkelmax's Audio Player. Special thanks to Athar42 for maintaining this plugin. - Play custom music discs using the Simple Voice Chat API. (The voice chat mod is required on the client and server.) @@ -21,7 +21,7 @@ Permission Nodes (Required to run the commands. Playing discs does not require a - ```customdiscs.range``` to set the range of the disc Dependencies: -- This plugin depends on the latest version of ProtocolLib for 1.21.6 and SimpleVoiceChatBukkit version 2.5.31. +- This plugin depends on the latest version of ProtocolLib for 1.21.7 and SimpleVoiceChatBukkit version 2.5.32. https://user-images.githubusercontent.com/64107368/178426026-c454ac66-5133-4f3a-9af9-7f674e022423.mp4 From 3f952aa632025d4dc33bfeffad90f6f262177097 Mon Sep 17 00:00:00 2001 From: Athar42 Date: Wed, 2 Jul 2025 18:46:21 +0200 Subject: [PATCH 4/4] Update readme again :D --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 25dca8f..a27664e 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Custom Discs v4.5 for Paper 1.21.7 +# Custom Discs v4.5 for Paper 1.21.6 and 1.21.7 A Paper fork of henkelmax's Audio Player. Special thanks to Athar42 for maintaining this plugin. - Play custom music discs using the Simple Voice Chat API. (The voice chat mod is required on the client and server.) @@ -21,7 +21,7 @@ Permission Nodes (Required to run the commands. Playing discs does not require a - ```customdiscs.range``` to set the range of the disc Dependencies: -- This plugin depends on the latest version of ProtocolLib for 1.21.7 and SimpleVoiceChatBukkit version 2.5.32. +- This plugin depends on the latest version of ProtocolLib available for your Paper version and SimpleVoiceChatBukkit (2.5.33 is recommended). https://user-images.githubusercontent.com/64107368/178426026-c454ac66-5133-4f3a-9af9-7f674e022423.mp4