Update 2.6

This commit is contained in:
Navoei
2024-06-12 14:51:41 -05:00
parent cb271ef71f
commit abe58976c0
10 changed files with 107 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx2G
java_version=22
java_version=17
mp3spi_version=1.9.5.4

View File

@@ -94,7 +94,7 @@ public class HopperManager implements Listener {
public void onChunkLoad(ChunkLoadEvent event) {
for (BlockState blockState : event.getChunk().getTileEntities()) {
if (blockState instanceof Jukebox jukebox) {
if (!PlayerManager.instance().isAudioPlayerPlaying(blockState.getLocation()) && !jukebox.isPlaying()) {
if (!PlayerManager.instance().isAudioPlayerPlaying(blockState.getLocation()) && isCustomMusicDisc(jukebox.getRecord())) {
discToHopper(blockState.getBlock());
}
}

View File

@@ -1,4 +1,5 @@
package me.Navoei.customdiscsplugin;
public class YoutubePlayerManager {
//Work in progress.
}

View File

@@ -1,12 +1,16 @@
package me.Navoei.customdiscsplugin.command;
import me.Navoei.customdiscsplugin.CustomDiscs;
import me.Navoei.customdiscsplugin.command.SubCommands.CreateCommand;
import me.Navoei.customdiscsplugin.command.SubCommands.DownloadCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -40,11 +44,14 @@ public class CommandManager implements CommandExecutor, TabCompleter {
}
}
} else {
player.sendMessage(ChatColor.AQUA + "----[ Custom Discs ]----");
for (int i = 0; i < getSubCommands().size(); i++) {
player.sendMessage(getSubCommands().get(i).getSyntax() + ChatColor.DARK_GRAY + " - " + getSubCommands().get(i).getDescription());
FileConfiguration config = CustomDiscs.getInstance().getConfig();
List<String> messagesList = config.getStringList("help");
for (String s : messagesList) {
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(s);
player.sendMessage(textComponent);
}
player.sendMessage(ChatColor.AQUA + "---------------------");
return true;
}

View File

@@ -2,10 +2,12 @@ package me.Navoei.customdiscsplugin.command.SubCommands;
import me.Navoei.customdiscsplugin.CustomDiscs;
import me.Navoei.customdiscsplugin.command.SubCommand;
import me.Navoei.customdiscsplugin.language.Lang;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@@ -35,7 +37,7 @@ public class CreateCommand extends SubCommand {
@Override
public String getSyntax() {
return ChatColor.GREEN + "/customdisc create <filename> \"Custom Lore\"";
return "/customdisc create <filename> \"Custom Lore\"";
}
@Override
@@ -44,22 +46,25 @@ public class CreateCommand extends SubCommand {
if (args.length >= 3) {
if (!player.hasPermission("customdiscs.create")) {
player.sendMessage(ChatColor.RED + "You do not have permission to execute this command!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.NO_PERMISSION.toString());
player.sendMessage(textComponent);
return;
}
// /cd create test.mp3 "test"
// [0] [1] [2]
//Find file, if file not there then say "file not there"
String songname = "";
String song_name = "";
String filename = args[1];
if (filename.contains("../")) {
player.sendMessage(ChatColor.RED + "This is an invalid filename!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.INVALID_FILENAME.toString());
player.sendMessage(textComponent);
return;
}
if (customName(readQuotes(args)).equalsIgnoreCase("")) {
player.sendMessage(ChatColor.RED + "You must provide a name for your disc.");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.NO_DISC_NAME_PROVIDED.toString());
player.sendMessage(textComponent);
return;
}
@@ -67,13 +72,15 @@ public class CreateCommand extends SubCommand {
File songFile = new File(getDirectory.getPath(), filename);
if (songFile.exists()) {
if (getFileExtension(filename).equals("wav") || getFileExtension(filename).equals("mp3") || getFileExtension(filename).equals("flac")) {
songname = args[1];
song_name = args[1];
} else {
player.sendMessage(ChatColor.RED + "File is not in wav, flac, or mp3 format!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.INVALID_FORMAT.toString());
player.sendMessage(textComponent);
return;
}
} else {
player.sendMessage(ChatColor.RED + "File not found!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.FILE_NOT_FOUND.toString());
player.sendMessage(textComponent);
return;
}
@@ -95,14 +102,17 @@ public class CreateCommand extends SubCommand {
player.getInventory().getItemInMainHand().setItemMeta(meta);
player.sendMessage("Your filename is: " + ChatColor.GRAY + songname);
player.sendMessage("Your custom name is: " + ChatColor.GRAY + customName(readQuotes(args)));
Component textComponentFileName = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.CREATE_FILENAME.toString().replace("%filename%", song_name));
Component textComponentCustomName = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.CREATE_CUSTOM_NAME.toString().replace("%custom_name%", customName(readQuotes(args))));
player.sendMessage(textComponentFileName);
player.sendMessage(textComponentCustomName);
} else {
player.sendMessage(ChatColor.RED + "Insufficient arguments! ( /customdisc create <filename> \"Custom Lore\" )");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.INVALID_ARGUMENTS.toString().replace("%command_syntax", getSyntax()));
player.sendMessage(textComponent);
}
} else {
player.sendMessage(ChatColor.RED + "You are not holding a music disc in your main hand!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.NOT_HOLDING_DISC.toString());
player.sendMessage(textComponent);
}
}

View File

@@ -2,6 +2,9 @@ package me.Navoei.customdiscsplugin.command.SubCommands;
import me.Navoei.customdiscsplugin.CustomDiscs;
import me.Navoei.customdiscsplugin.command.SubCommand;
import me.Navoei.customdiscsplugin.language.Lang;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -29,7 +32,7 @@ public class DownloadCommand extends SubCommand {
@Override
public String getSyntax() {
return ChatColor.GREEN + "/customdisc download <url> <filename.extension>";
return "/customdisc download <url> <filename.extension>";
}
@Override
@@ -38,12 +41,14 @@ public class DownloadCommand extends SubCommand {
// [0] [1] [2]
if (!player.hasPermission("customdiscs.download")) {
player.sendMessage(ChatColor.RED + "You do not have permission to execute this command!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.NO_PERMISSION.toString());
player.sendMessage(textComponent);
return;
}
if (args.length!=3) {
player.sendMessage(ChatColor.RED + "Invalid arguments! ( /customdisc download <url> <filename.extension> )");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.INVALID_ARGUMENTS.toString().replace("%command_syntax", getSyntax()));
player.sendMessage(textComponent);
return;
}
@@ -52,18 +57,21 @@ public class DownloadCommand extends SubCommand {
URL fileURL = new URL(args[1]);
String filename = args[2];
if (filename.contains("../")) {
player.sendMessage(ChatColor.RED + "This is an invalid filename!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.INVALID_FILENAME.toString());
player.sendMessage(textComponent);
return;
}
System.out.println(filename);
if (!getFileExtension(filename).equals("wav") && !getFileExtension(filename).equals("mp3") && !getFileExtension(filename).equals("flac")) {
player.sendMessage(ChatColor.RED + "The file must have an extension of wav, flac, or mp3!");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.INVALID_FORMAT.toString());
player.sendMessage(textComponent);
return;
}
player.sendMessage(ChatColor.GRAY + "Downloading file...");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.DOWNLOADING_FILE.toString());
player.sendMessage(textComponent);
Path downloadPath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", filename);
File downloadFile = new File(downloadPath.toUri());
@@ -72,17 +80,22 @@ public class DownloadCommand extends SubCommand {
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.");
Component textComponent2 = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.FILE_TOO_LARGE.toString().replace("%max_download_size%", String.valueOf(customDiscs.getConfig().getInt("max-download-size", 50))));
player.sendMessage(textComponent2);
return;
}
}
FileUtils.copyURLToFile(fileURL, downloadFile);
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 + ".");
Component fileDownloaded = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.SUCCESSFUL_DOWNLOAD.toString().replace("%file_path%", "plugins/CustomDiscs/musicdata/" + filename));
Component createDisc = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.CREATE_DISC.toString().replace("%filename%", filename));
player.sendMessage(fileDownloaded);
player.sendMessage(createDisc);
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "An error has occurred while downloading.");
Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.DOWNLOAD_ERROR.toString());
player.sendMessage(textComponent);
e.printStackTrace();
}
});

View File

@@ -4,6 +4,7 @@ import me.Navoei.customdiscsplugin.CustomDiscs;
import me.Navoei.customdiscsplugin.ParticleManager;
import me.Navoei.customdiscsplugin.PlayerManager;
import me.Navoei.customdiscsplugin.VoicePlugin;
import me.Navoei.customdiscsplugin.language.Lang;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -53,9 +54,10 @@ public class JukeBox implements Listener{
Component songNameComponent = Objects.requireNonNull(event.getItem().getItemMeta().lore()).get(0).asComponent();
String songName = PlainTextComponentSerializer.plainText().serialize(songNameComponent);
String content = Lang.NOW_PLAYING.toString().replace("%song_name%", songName);
TextComponent customActionBarSongPlaying = Component.text()
.content("Now Playing: " + songName)
.content(content)
.color(NamedTextColor.GOLD)
.build();

View File

@@ -4,7 +4,22 @@ import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
public enum Lang {
PREFIX("text", "text");
PREFIX("prefix", "&8[&6CustomDiscs&8]&r"),
NO_PERMISSION("no-permission", "&rYou do not have permission to execute this command."),
INVALID_FILENAME("invalid-filename", "&rThis is an invalid filename!"),
NO_DISC_NAME_PROVIDED("no-disc-name-provided", "&rYou must provide a name for your disc."),
INVALID_FORMAT("invalid-format", "&rFile must be in wav, flac, or mp3 format!"),
FILE_NOT_FOUND("file-not-found", "&rFile not found!"),
INVALID_ARGUMENTS("invalid-arguments", "&rInsufficient arguments. &7(&a%command_syntax%&7)"),
NOT_HOLDING_DISC("not-holding-disc", "&rYou must hold a disc in your main hand."),
CREATE_FILENAME("create-filename", "&7Your filename is: &a\"%filename%\"."),
CREATE_CUSTOM_NAME("create-custom-name", "&7Your custom name is: &a\"%custom_name%\"."),
DOWNLOADING_FILE("downloading-file", "&7Downloading file..."),
FILE_TOO_LARGE("file-too-large", "&rThe file is larger than %max_download_size%MB."),
SUCCESSFUL_DOWNLOAD("successful-download", "&aFile successfully downloaded to &7%file_path%&a."),
CREATE_DISC("create-disc", "&aCreate a disc by doing &7/cd create filename.extension \"Custom Lore\"&a."),
DOWNLOAD_ERROR("download-error", "&rAn error has occurred while downloading."),
NOW_PLAYING("now-playing","&6Now playing: %song_name%");
private final String path;
private final String def;
@@ -31,8 +46,8 @@ public enum Lang {
@Override
public String toString() {
if (this == PREFIX)
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)) + " ";
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def));
return LANG.getString(this.path, def) + " ";
return LANG.getString(this.path, def);
}
/**
@@ -50,4 +65,7 @@ public enum Lang {
public String getPath() {
return this.path;
}
//Component textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(PlaceholderAPI.setPlaceholders(player, Lang.PREFIX + Lang.COMBAT.toString()));
//player.sendMessage(textComponent);
}

View File

@@ -7,4 +7,10 @@ music-disc-distance: 16
music-disc-volume: 1
#The maximum download size in megabytes.
max-download-size: 50
max-download-size: 50
#Custom Discs Help Page
help:
- "&8-[&6CustomDiscs Help Page&8]-"
- "&aAuthor&7: &6Navoei"
- "&fGit&0Hub&7: &9&ohttps://github.com/Navoei/CustomDiscs"

View File

@@ -0,0 +1,16 @@
prefix: "&8[&6CustomDiscs&8]&r"
no-permission: "&rYou do not have permission to execute this command."
invalid-filename: "&rThis is an invalid filename!"
no-disc-name-provided: "&rYou must provide a name for your disc."
invalid-format: "&rFile must be in wav, flac, or mp3 format!"
file-not-found: "&rFile not found!"
invalid-arguments: "&rInvalid arguments. &7(&a%command_syntax%&7)"
not-holding-disc: "&rYou must hold a disc in your main hand."
create-filename: "&7Your filename is: &a\"%filename%\"."
create-custom-name: "&7Your custom name is: &a\"%custom_name%\"."
downloading-file: "&7Downloading file..."
file-too-large: "&rThe file is larger than %max_download_size%MB."
successful-download: "&aFile successfully downloaded to &7%file_path%&a."
create-disc: "&aCreate a disc by doing &7/cd create %filename% \"Custom Lore\"&a."
download-error: "&rAn error has occurred while downloading."
now-playing: "&6Now playing: %song_name%"