diff --git a/gradle.properties b/gradle.properties index 69a607d..9701039 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ java_version=17 mp3spi_version=1.9.5.4 -bukkit_api_version=1.19.4 +bukkit_api_version=1.19 bukkit_version=1.19.4-R0.1-SNAPSHOT mod_id=customdiscsplugin diff --git a/readme.md b/readme.md index ad4c8a9..ea89176 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Custom Discs 1.19-1.19.3 +# Custom Discs 1.19.4 A Paper fork of henkelmax's Audio Player. - Play custom music discs using the Simple Voice Chat API. (The voice chat mod is required on the client and server.) @@ -7,9 +7,14 @@ A Paper fork of henkelmax's Audio Player. - Music files must be in the ```.wav```, ```.flac```, or ```.mp3``` format. - Only custom discs are compatible with hoppers. +Downloading Files: +- To download a file use the command ```/cd download ```. The link used to download a file must be a direct link (meaning the file must automatically begin downloading when accessing the link). Files must have the correct extension specified. An UnsupportedAudioFileException will be thrown in the server's console if the file extension is not correct (for example when giving a wav file the mp3 extension). Below is an example of how to use the command and a link to get direct downloads from Google Drive. +- Example: ```/cd download https://example.com/mysong "mysong.mp3"``` +- Direct Google Drive links: https://lonedev6.github.io/gddl/ + Permission Nodes (Required to run the commands. Playing discs does not require a permission.): - ```customdiscs.create``` to create a disc -- ```customdiscs.convert``` to convert a disc +- ```customdiscs.download``` to download a file Dependencies: - This plugin depends on the latest version of ProtocolLib for 1.19.x diff --git a/src/main/java/me/Navoei/customdiscsplugin/HopperManager.java b/src/main/java/me/Navoei/customdiscsplugin/HopperManager.java index 3f0bdc1..b3b9c75 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/HopperManager.java +++ b/src/main/java/me/Navoei/customdiscsplugin/HopperManager.java @@ -4,26 +4,17 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Jukebox; -import org.bukkit.block.data.type.Hopper; -import org.bukkit.entity.minecart.HopperMinecart; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.inventory.*; -import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; import java.nio.file.Path; -import java.util.Arrays; import java.util.Objects; public class HopperManager implements Listener { diff --git a/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java b/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java index b1b50cc..aaa96b7 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java +++ b/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java @@ -8,9 +8,6 @@ import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel; import javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider; import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -25,7 +22,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Collection; import java.util.Map; -import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/CommandManager.java b/src/main/java/me/Navoei/customdiscsplugin/command/CommandManager.java index 0253e40..c7717c6 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/CommandManager.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/CommandManager.java @@ -1,6 +1,5 @@ package me.Navoei.customdiscsplugin.command; -import me.Navoei.customdiscsplugin.command.SubCommands.ConvertCommand; import me.Navoei.customdiscsplugin.command.SubCommands.CreateCommand; import me.Navoei.customdiscsplugin.command.SubCommands.DownloadCommand; import org.bukkit.ChatColor; @@ -21,7 +20,6 @@ public class CommandManager implements CommandExecutor, TabCompleter { public CommandManager() { subCommands.add(new CreateCommand()); - subCommands.add(new ConvertCommand()); subCommands.add(new DownloadCommand()); } diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/ConvertCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/ConvertCommand.java deleted file mode 100644 index 8f966f7..0000000 --- a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/ConvertCommand.java +++ /dev/null @@ -1,90 +0,0 @@ -package me.Navoei.customdiscsplugin.command.SubCommands; - -import me.Navoei.customdiscsplugin.CustomDiscs; -import me.Navoei.customdiscsplugin.command.SubCommand; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; - -import java.util.List; - -public class ConvertCommand extends SubCommand { - - @Override - public String getName() { - return "convert"; - } - - @Override - public String getDescription() { - return ChatColor.GRAY + "Converts a disc from the old format to the new one."; - } - - @Override - public String getSyntax() { - return ChatColor.GREEN + "/customdisc convert"; - } - - @Override - public void perform(Player player, String[] args) { - - if (!player.hasPermission("customdiscs.convert")) { - player.sendMessage(ChatColor.RED + "You do not have permission to execute this command!"); - return; - } - - if (isOldCustomMusicDisc(player.getInventory().getItemInMainHand())) { - ItemMeta customDiscMeta = player.getInventory().getItemInMainHand().getItemMeta(); - - Component soundFileNameComponent = customDiscMeta.lore().get(1).asComponent(); - String soundFileName = PlainTextComponentSerializer.plainText().serialize(soundFileNameComponent); - List songName = customDiscMeta.lore(); - - PersistentDataContainer data = customDiscMeta.getPersistentDataContainer(); - data.set(new NamespacedKey(CustomDiscs.getInstance(), "customdisc"), PersistentDataType.STRING, soundFileName); - - songName.remove(1); - - customDiscMeta.lore(songName); - - customDiscMeta.removeItemFlags(ItemFlag.HIDE_ENCHANTS); - - player.getInventory().getItemInMainHand().setItemMeta(customDiscMeta); - - player.sendMessage(ChatColor.GREEN + "The new format has been applied."); - - } else { - player.sendMessage(ChatColor.RED + "The new format could not be applied."); - } - - } - - private boolean isOldCustomMusicDisc (ItemStack item) { - - return item.hasItemFlag(ItemFlag.HIDE_ENCHANTS) && ( - item.getType().equals(Material.MUSIC_DISC_13) || - item.getType().equals(Material.MUSIC_DISC_CAT) || - item.getType().equals(Material.MUSIC_DISC_BLOCKS) || - item.getType().equals(Material.MUSIC_DISC_CHIRP) || - item.getType().equals(Material.MUSIC_DISC_FAR) || - item.getType().equals(Material.MUSIC_DISC_MALL) || - item.getType().equals(Material.MUSIC_DISC_MELLOHI) || - item.getType().equals(Material.MUSIC_DISC_STAL) || - item.getType().equals(Material.MUSIC_DISC_STRAD) || - item.getType().equals(Material.MUSIC_DISC_WARD) || - item.getType().equals(Material.MUSIC_DISC_11) || - item.getType().equals(Material.MUSIC_DISC_WAIT) || - item.getType().equals(Material.MUSIC_DISC_OTHERSIDE) || - item.getType().equals(Material.MUSIC_DISC_5) || - item.getType().equals(Material.MUSIC_DISC_PIGSTEP) - ); - } -} diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadCommand.java index cc9ea16..2a6c237 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadCommand.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/DownloadCommand.java @@ -7,13 +7,11 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.codehaus.plexus.util.FileUtils; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; +import java.net.URLConnection; import java.nio.file.Path; -import java.util.Objects; public class DownloadCommand extends SubCommand { @@ -43,7 +41,7 @@ public class DownloadCommand extends SubCommand { player.sendMessage(ChatColor.RED + "You do not have permission to execute this command!"); return; } - + if (args.length!=3) { player.sendMessage(ChatColor.RED + "Invalid arguments! ( /customdisc download )"); return; @@ -68,9 +66,20 @@ public class DownloadCommand extends SubCommand { player.sendMessage(ChatColor.GRAY + "Downloading file..."); Path downloadPath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", filename); File downloadFile = new File(downloadPath.toUri()); + + URLConnection connection = fileURL.openConnection(); + + if (connection != null) { + long size = connection.getContentLengthLong() / 1048576; + if (size > customDiscs.getConfig().getInt("max-download-size", 50)) { + player.sendMessage(ChatColor.RED + "The file is larger than " + customDiscs.getConfig().getInt("max-download-size", 50) + "MB."); + return; + } + } + FileUtils.copyURLToFile(fileURL, downloadFile); - player.sendMessage(ChatColor.GREEN + "File successfully downloaded to " + ChatColor.GRAY + downloadPath.toUri() + ChatColor.GREEN + " ."); + player.sendMessage(ChatColor.GREEN + "File successfully downloaded to " + ChatColor.GRAY + "plugins/CustomDiscs/musicdata/"+ filename + ChatColor.GREEN + " ."); player.sendMessage(ChatColor.GREEN + "Create a disc by doing " + ChatColor.GRAY + "/cd create "+filename+" \"Custom Lore\" " + ChatColor.GREEN + "."); } catch (IOException e) { player.sendMessage(ChatColor.RED + "An error has occurred while downloading."); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0e1e60c..54ba534 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,4 +4,7 @@ music-disc-distance: 16 # The master volume of music discs from 0-1. (You can set values like 0.5 for 50% volume). -music-disc-volume: 1 \ No newline at end of file +music-disc-volume: 1 + +#The maximum download size in megabytes. +max-download-size: 50 \ No newline at end of file