From af77bffaac977138e16eb7d87a9bc2e632e8977c Mon Sep 17 00:00:00 2001 From: Navoei Date: Sat, 9 Jul 2022 21:35:28 -0500 Subject: [PATCH] Some minor changes was trying to get a way to control the audio channel --- build.gradle | 1 - .../customdiscsplugin/command/CustomDisc.java | 3 --- .../Navoei/customdiscsplugin/event/JukeBox.java | 15 +++++---------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index cb31060..6e0008e 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,6 @@ dependencies { } repositories { - maven { url "https://repo.dmulloy2.net/repository/public/" } mavenCentral() maven { name = "henkelmax.public" diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/CustomDisc.java b/src/main/java/me/Navoei/customdiscsplugin/command/CustomDisc.java index 43f74ee..74aee2c 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/CustomDisc.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/CustomDisc.java @@ -7,12 +7,9 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeModifier; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; diff --git a/src/main/java/me/Navoei/customdiscsplugin/event/JukeBox.java b/src/main/java/me/Navoei/customdiscsplugin/event/JukeBox.java index 3fbdc5f..6c3a7af 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/event/JukeBox.java +++ b/src/main/java/me/Navoei/customdiscsplugin/event/JukeBox.java @@ -16,7 +16,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemFlag; @@ -36,7 +35,7 @@ public class JukeBox implements Listener { private final Map playerMap = new ConcurrentHashMap<>(); public static AudioFormat FORMAT = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 48000.0F, 16, 1, 2, 48000.0F, false); - private UUID id; + private static UUID id; @EventHandler public void onInsert(PlayerInteractEvent event) throws IOException { @@ -44,15 +43,16 @@ public class JukeBox implements Listener { Player player = event.getPlayer(); Block block = event.getClickedBlock(); - if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock() == null || event.getItem() == null || event.getItem().getItemMeta() == null) return; + if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock() == null || event.getItem() == null || event.getItem().getItemMeta() == null || block == null) return; if (event.getClickedBlock().getType() != Material.JUKEBOX) return; - id = UUID.randomUUID(); if (isCustomMusicDisc(event)) { Component soundFileNameComponent = Objects.requireNonNull(event.getItem().getItemMeta().lore()).get(1).asComponent(); String soundFileName = PlainTextComponentSerializer.plainText().serialize(soundFileNameComponent); + id = UUID.randomUUID(); + Path soundFilePath = Path.of(CustomDiscs.getInstance().getDataFolder() + "\\musicdata\\" + soundFileName); if (soundFilePath.toFile().exists()) { Component songNameComponent = Objects.requireNonNull(event.getItem().getItemMeta().lore()).get(0).asComponent(); @@ -71,7 +71,7 @@ public class JukeBox implements Listener { } else { player.sendMessage(ChatColor.RED + "Sound file not found."); event.setCancelled(true); - throw new FileNotFoundException("ERROR: Sound file is missing!"); + throw new FileNotFoundException("Sound file is missing!"); } } } @@ -102,11 +102,6 @@ public class JukeBox implements Listener { } } - @EventHandler - public void onJukeboxBreak(BlockBreakEvent Event) { - - } - public static short[] readSoundFile(Path file) throws UnsupportedAudioFileException, IOException { AudioInputStream inputStream = AudioSystem.getAudioInputStream(file.toFile()); AudioInputStream convertedInputStream = AudioSystem.getAudioInputStream(FORMAT, inputStream);