#1 Version 2.3 release.

This commit is contained in:
Navoei
2023-03-31 20:47:38 -05:00
parent 6732b02b58
commit 035af8df7b
8 changed files with 28 additions and 116 deletions

View File

@@ -4,7 +4,7 @@ java_version=17
mp3spi_version=1.9.5.4 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 bukkit_version=1.19.4-R0.1-SNAPSHOT
mod_id=customdiscsplugin mod_id=customdiscsplugin

View File

@@ -1,4 +1,4 @@
# Custom Discs 1.19-1.19.3 # Custom Discs 1.19.4
A Paper fork of henkelmax's Audio Player. 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.) - 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. - Music files must be in the ```.wav```, ```.flac```, or ```.mp3``` format.
- Only custom discs are compatible with hoppers. - Only custom discs are compatible with hoppers.
Downloading Files:
- To download a file use the command ```/cd download <url> <filename.extension>```. 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.): Permission Nodes (Required to run the commands. Playing discs does not require a permission.):
- ```customdiscs.create``` to create a disc - ```customdiscs.create``` to create a disc
- ```customdiscs.convert``` to convert a disc - ```customdiscs.download``` to download a file
Dependencies: Dependencies:
- This plugin depends on the latest version of ProtocolLib for 1.19.x - This plugin depends on the latest version of ProtocolLib for 1.19.x

View File

@@ -4,26 +4,17 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; 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.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.*; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
public class HopperManager implements Listener { public class HopperManager implements Listener {

View File

@@ -8,9 +8,6 @@ import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel;
import javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider; import javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider;
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader; import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
import net.kyori.adventure.text.Component; 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.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@@ -25,7 +22,6 @@ import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;

View File

@@ -1,6 +1,5 @@
package me.Navoei.customdiscsplugin.command; 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.CreateCommand;
import me.Navoei.customdiscsplugin.command.SubCommands.DownloadCommand; import me.Navoei.customdiscsplugin.command.SubCommands.DownloadCommand;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@@ -21,7 +20,6 @@ public class CommandManager implements CommandExecutor, TabCompleter {
public CommandManager() { public CommandManager() {
subCommands.add(new CreateCommand()); subCommands.add(new CreateCommand());
subCommands.add(new ConvertCommand());
subCommands.add(new DownloadCommand()); subCommands.add(new DownloadCommand());
} }

View File

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

View File

@@ -7,13 +7,11 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Objects;
public class DownloadCommand extends SubCommand { 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!"); player.sendMessage(ChatColor.RED + "You do not have permission to execute this command!");
return; return;
} }
if (args.length!=3) { if (args.length!=3) {
player.sendMessage(ChatColor.RED + "Invalid arguments! ( /customdisc download <url> <filename.extension> )"); player.sendMessage(ChatColor.RED + "Invalid arguments! ( /customdisc download <url> <filename.extension> )");
return; return;
@@ -68,9 +66,20 @@ public class DownloadCommand extends SubCommand {
player.sendMessage(ChatColor.GRAY + "Downloading file..."); player.sendMessage(ChatColor.GRAY + "Downloading file...");
Path downloadPath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", filename); Path downloadPath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", filename);
File downloadFile = new File(downloadPath.toUri()); 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); 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 + "."); player.sendMessage(ChatColor.GREEN + "Create a disc by doing " + ChatColor.GRAY + "/cd create "+filename+" \"Custom Lore\" " + ChatColor.GREEN + ".");
} catch (IOException e) { } catch (IOException e) {
player.sendMessage(ChatColor.RED + "An error has occurred while downloading."); player.sendMessage(ChatColor.RED + "An error has occurred while downloading.");

View File

@@ -4,4 +4,7 @@
music-disc-distance: 16 music-disc-distance: 16
# The master volume of music discs from 0-1. (You can set values like 0.5 for 50% volume). # The master volume of music discs from 0-1. (You can set values like 0.5 for 50% volume).
music-disc-volume: 1 music-disc-volume: 1
#The maximum download size in megabytes.
max-download-size: 50