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)
This commit is contained in:
Athar42
2025-06-26 01:25:32 +02:00
parent 85148b489a
commit 99ae61fdd4
5 changed files with 56 additions and 41 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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.)

View File

@@ -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;
}