From c955a22483f76520de1100041a431ba59d78e278 Mon Sep 17 00:00:00 2001 From: Navoei Date: Fri, 29 Nov 2024 12:46:26 -0600 Subject: [PATCH] Complications with Goathorns Goat horns removed due to complications in cancelling sound events. --- readme.md | 5 - .../Navoei/customdiscsplugin/CustomDiscs.java | 9 -- .../customdiscsplugin/PlayerManager.java | 73 ------------ .../Navoei/customdiscsplugin/VoicePlugin.java | 75 ------------- .../command/CustomDiscCommand.java | 2 - .../command/SubCommands/CreateSubCommand.java | 50 +++------ .../SetHornCooldownSubCommand.java | 83 -------------- .../SubCommands/SetRangeSubCommand.java | 27 +---- .../customdiscsplugin/event/GoatHorn.java | 104 ------------------ .../customdiscsplugin/language/Lang.java | 6 +- src/main/resources/config.yml | 6 - src/main/resources/goat_horn_category.png | Bin 199 -> 0 bytes src/main/resources/lang.yml | 6 +- 13 files changed, 21 insertions(+), 425 deletions(-) delete mode 100644 src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetHornCooldownSubCommand.java delete mode 100644 src/main/java/me/Navoei/customdiscsplugin/event/GoatHorn.java delete mode 100644 src/main/resources/goat_horn_category.png diff --git a/readme.md b/readme.md index 6c60e04..5bc8a3f 100644 --- a/readme.md +++ b/readme.md @@ -15,15 +15,10 @@ Set the range of a disc: - To set the active range of a playable disc, just use the command ```/cd range ```. The range can be between 1 and the max value set in the config file (default : 256) - Example: ```/cd range 100``` -Set the cooldown for a modified goat horn: (GOAT HORNS ARE EXPERIMENTAL!!! Please report any issues.) -- To set a different cooldown timer than the one set by the config, just use the command ```/cd goatcooldown ``` where is between 0 and the max value set in the config file (default : 6000) -- Example: ```/cd goatcooldown 7``` - Permission Nodes (Required to run the commands. Playing discs does not require a permission.): - ```customdiscs.create``` to create a disc - ```customdiscs.download``` to download a file - ```customdiscs.range``` to set the range of the disc -- ```customdiscs.horncooldown``` to set the cooldown for your modified goat horn Dependencies: - This plugin depends on the latest version of ProtocolLib for 1.21 and SimpleVoiceChatBukkit version 2.5.16. diff --git a/src/main/java/me/Navoei/customdiscsplugin/CustomDiscs.java b/src/main/java/me/Navoei/customdiscsplugin/CustomDiscs.java index 75e55a5..7f96750 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/CustomDiscs.java +++ b/src/main/java/me/Navoei/customdiscsplugin/CustomDiscs.java @@ -11,14 +11,11 @@ import de.maxhenkel.voicechat.api.BukkitVoicechatService; import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIBukkitConfig; import me.Navoei.customdiscsplugin.command.CustomDiscCommand; -import me.Navoei.customdiscsplugin.event.GoatHorn; import me.Navoei.customdiscsplugin.event.JukeBox; import me.Navoei.customdiscsplugin.language.Lang; import org.bukkit.NamespacedKey; import org.bukkit.block.Jukebox; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.java.JavaPlugin; @@ -39,9 +36,6 @@ public final class CustomDiscs extends JavaPlugin { public float musicDiscDistance; public float musicDiscMaxDistance; public float musicDiscVolume; - public float hornCooldown; - public int hornMaxCooldown; - public int hornMaxCooldownTicks; @Override public void onLoad() { @@ -75,14 +69,11 @@ public final class CustomDiscs extends JavaPlugin { } getServer().getPluginManager().registerEvents(new JukeBox(), this); - getServer().getPluginManager().registerEvents(new GoatHorn(), this); getServer().getPluginManager().registerEvents(new HopperManager(), this); musicDiscDistance = Objects.requireNonNull(getConfig().getInt("music-disc-distance")); musicDiscMaxDistance = Objects.requireNonNull(getConfig().getInt("music-disc-max-distance")); musicDiscVolume = Float.parseFloat(Objects.requireNonNull(getConfig().getString("music-disc-volume"))); - hornCooldown = Float.parseFloat(Objects.requireNonNull(getConfig().getString("horn-cooldown"))); - hornMaxCooldown = Objects.requireNonNull(getConfig().getInt("horn-max-cooldown")); ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); diff --git a/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java b/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java index 82cbfd5..258f804 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java +++ b/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java @@ -101,61 +101,6 @@ public class PlayerManager { }); } - public void playLocationalAudioHorn(VoicechatServerApi api, Path soundFilePath, Player block, Component actionbarComponent, float range) { - UUID id = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes()); - - LocationalAudioChannel audioChannel = api.createLocationalAudioChannel(id, api.fromServerLevel(block.getWorld()), api.createPosition(block.getLocation().getX() + 0.5d, block.getLocation().getY() + 0.5d, block.getLocation().getZ() + 0.5d)); - - if (audioChannel == null) return; - - audioChannel.setCategory(VoicePlugin.GOAT_HORN_CATEGORY); - audioChannel.setDistance(range); - - AtomicBoolean stopped = new AtomicBoolean(); - AtomicReference player = new AtomicReference<>(); - - playerMap.put(id, () -> { - synchronized (stopped) { - stopped.set(true); - de.maxhenkel.voicechat.api.audiochannel.AudioPlayer audioPlayer = player.get(); - if (audioPlayer != null) { - audioPlayer.stopPlaying(); - } - } - }); - - executorService.execute(() -> { - Collection playersInRange = api.getPlayersInRange(api.fromServerLevel(block.getWorld()), api.createPosition(block.getLocation().getX() + 0.5d, block.getLocation().getY() + 0.5d, block.getLocation().getZ() + 0.5d), range); - - de.maxhenkel.voicechat.api.audiochannel.AudioPlayer audioPlayer = playChannelHorn(api, audioChannel, block, soundFilePath, playersInRange); - - for (ServerPlayer serverPlayer : playersInRange) { - Player bukkitPlayer = (Player) serverPlayer.getPlayer(); - bukkitPlayer.sendActionBar(actionbarComponent); - } - - if (audioPlayer == null) { - playerMap.remove(id); - return; - } - - audioPlayer.setOnStopped(() -> { - - //Bukkit.getScheduler().runTask(CustomDiscs.getInstance(), () -> HopperManager.instance().discToHopper(block)); - - playerMap.remove(id); - }); - - synchronized (stopped) { - if (!stopped.get()) { - player.set(audioPlayer); - } else { - audioPlayer.stopPlaying(); - } - } - }); - } - @Nullable private de.maxhenkel.voicechat.api.audiochannel.AudioPlayer playChannel(VoicechatServerApi api, AudioChannel audioChannel, Block block, Path soundFilePath, Collection playersInRange) { try { @@ -174,24 +119,6 @@ public class PlayerManager { } } - @Nullable - private de.maxhenkel.voicechat.api.audiochannel.AudioPlayer playChannelHorn(VoicechatServerApi api, AudioChannel audioChannel, Player block, Path soundFilePath, Collection playersInRange) { - try { - short[] audio = readSoundFile(soundFilePath); - AudioPlayer audioPlayer = api.createAudioPlayer(audioChannel, api.createEncoder(), audio); - audioPlayer.startPlaying(); - return audioPlayer; - } catch (Exception e) { - e.printStackTrace(); - Bukkit.getLogger().info("Error Occurred At: " + block.getLocation()); - for (ServerPlayer serverPlayer : playersInRange) { - Player bukkitPlayer = (Player) serverPlayer.getPlayer(); - bukkitPlayer.sendMessage(NamedTextColor.RED + "An error has occurred while trying to play this horn."); - } - return null; - } - } - private static short[] readSoundFile(Path file) throws UnsupportedAudioFileException, IOException, LineUnavailableException { return VoicePlugin.voicechatApi.getAudioConverter().bytesToShorts(convertFormat(file, FORMAT)); } diff --git a/src/main/java/me/Navoei/customdiscsplugin/VoicePlugin.java b/src/main/java/me/Navoei/customdiscsplugin/VoicePlugin.java index c631a6d..1d79927 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/VoicePlugin.java +++ b/src/main/java/me/Navoei/customdiscsplugin/VoicePlugin.java @@ -69,24 +69,6 @@ public class VoicePlugin implements VoicechatPlugin { .setIcon(getMusicDiscIcon()) .build(); voicechatServerApi.registerVolumeCategory(musicDiscs); - - goatHorns = voicechatServerApi.volumeCategoryBuilder() - .setId(GOAT_HORN_CATEGORY) - .setName("Goat Horns") - .setDescription("The volume of goat horns") - .setIcon(getGoatHornsIcon()) - .build(); - voicechatServerApi.registerVolumeCategory(goatHorns); - - /* - playerHeads = voicechatServerApi.volumeCategoryBuilder() - .setId(PLAYER_HEAD_CATEGORY) - .setName("Player Heads") - .setDescription("The volume of player heads (not enabled)") - .setIcon(getPlayerHeadsIcon()) - .build(); - voicechatServerApi.registerVolumeCategory(playerHeads); - */ } @@ -116,62 +98,5 @@ public class VoicePlugin implements VoicechatPlugin { } return null; } - - private int[][] getGoatHornsIcon() { - try { - Enumeration resources = CustomDiscs.getInstance().getClass().getClassLoader().getResources("goat_horn_category.png"); - - while (resources.hasMoreElements()) { - BufferedImage bufferedImage = ImageIO.read(resources.nextElement().openStream()); - if (bufferedImage.getWidth() != 16) { - continue; - } - if (bufferedImage.getHeight() != 16) { - continue; - } - int[][] image = new int[16][16]; - for (int x = 0; x < bufferedImage.getWidth(); x++) { - for (int y = 0; y < bufferedImage.getHeight(); y++) { - image[x][y] = bufferedImage.getRGB(x, y); - } - } - return image; - } - - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - /* - private int[][] getPlayerHeadsIcon() { - try { - Enumeration resources = CustomDiscs.getInstance().getClass().getClassLoader().getResources("player_head_category.png"); - - while (resources.hasMoreElements()) { - BufferedImage bufferedImage = ImageIO.read(resources.nextElement().openStream()); - if (bufferedImage.getWidth() != 16) { - continue; - } - if (bufferedImage.getHeight() != 16) { - continue; - } - int[][] image = new int[16][16]; - for (int x = 0; x < bufferedImage.getWidth(); x++) { - for (int y = 0; y < bufferedImage.getHeight(); y++) { - image[x][y] = bufferedImage.getRGB(x, y); - } - } - return image; - } - - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - */ - } \ No newline at end of file diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/CustomDiscCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/CustomDiscCommand.java index 4005d47..82f3e09 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/CustomDiscCommand.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/CustomDiscCommand.java @@ -6,7 +6,6 @@ import me.Navoei.customdiscsplugin.CustomDiscs; import me.Navoei.customdiscsplugin.command.SubCommands.CreateSubCommand; import me.Navoei.customdiscsplugin.command.SubCommands.DownloadSubCommand; import me.Navoei.customdiscsplugin.command.SubCommands.SetRangeSubCommand; -import me.Navoei.customdiscsplugin.command.SubCommands.SetHornCooldownSubCommand; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.ConsoleCommandSender; @@ -26,7 +25,6 @@ public class CustomDiscCommand extends CommandAPICommand { this.withSubcommand(new CreateSubCommand(plugin)); this.withSubcommand(new DownloadSubCommand(plugin)); this.withSubcommand(new SetRangeSubCommand(plugin)); - this.withSubcommand(new SetHornCooldownSubCommand(plugin)); this.executesPlayer(this::onCommandPlayer); this.executesConsole(this::onCommandConsole); diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateSubCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateSubCommand.java index 814071b..f1febed 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateSubCommand.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateSubCommand.java @@ -67,7 +67,7 @@ public class CreateSubCommand extends CommandAPICommand { ItemStack item = player.getInventory().getItemInMainHand(); - if (!isMusicDisc(item) && !isGoatHorn(item)) { + if (!isMusicDisc(item)) { player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_DISC.toString())); return 1; } @@ -98,41 +98,20 @@ public class CreateSubCommand extends CommandAPICommand { String song_name = Objects.requireNonNull(arguments.getByClass("song_name", String.class)); - if (isMusicDisc(item)) { - // IF DISC - ItemStack disc = new ItemStack(player.getInventory().getItemInMainHand()); - ItemMeta meta = disc.getItemMeta(); - @Nullable List itemLore = new ArrayList<>(); - final TextComponent customLoreSong = Component.text().decoration(TextDecoration.ITALIC, false).content(song_name).color(NamedTextColor.GRAY).build(); - itemLore.add(customLoreSong); - meta.lore(itemLore); + ItemStack disc = new ItemStack(player.getInventory().getItemInMainHand()); + ItemMeta meta = disc.getItemMeta(); + @Nullable List itemLore = new ArrayList<>(); + final TextComponent customLoreSong = Component.text().decoration(TextDecoration.ITALIC, false).content(song_name).color(NamedTextColor.GRAY).build(); + itemLore.add(customLoreSong); + meta.lore(itemLore); - JukeboxPlayableComponent jpc = meta.getJukeboxPlayable(); - jpc.setShowInTooltip(false); - meta.setJukeboxPlayable(jpc); + JukeboxPlayableComponent jpc = meta.getJukeboxPlayable(); + jpc.setShowInTooltip(false); + meta.setJukeboxPlayable(jpc); - PersistentDataContainer data = meta.getPersistentDataContainer(); - data.set(new NamespacedKey(this.plugin, "customdisc"), PersistentDataType.STRING, filename); - player.getInventory().getItemInMainHand().setItemMeta(meta); - - } else if (isGoatHorn(item)) { - // IF HORN - ItemStack goat_horn = new ItemStack(player.getInventory().getItemInMainHand()); - ItemMeta meta = goat_horn.getItemMeta(); - @Nullable List itemLore = new ArrayList<>(); - final TextComponent customLoreSong = Component.text().decoration(TextDecoration.ITALIC, false).content(song_name).color(NamedTextColor.GRAY).build(); - itemLore.add(customLoreSong); - meta.lore(itemLore); - - meta.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP); - - PersistentDataContainer data = meta.getPersistentDataContainer(); - data.set(new NamespacedKey(this.plugin, "customhorn"), PersistentDataType.STRING, filename); - player.getInventory().getItemInMainHand().setItemMeta(meta); - } else { - return 1; - } - + PersistentDataContainer data = meta.getPersistentDataContainer(); + data.set(new NamespacedKey(this.plugin, "customdisc"), PersistentDataType.STRING, filename); + player.getInventory().getItemInMainHand().setItemMeta(meta); player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_FILENAME.toString().replace("%filename%", filename))); player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_NAME.toString().replace("%custom_name%", song_name))); return 1; @@ -156,7 +135,4 @@ public class CreateSubCommand extends CommandAPICommand { return item.getType().toString().contains("MUSIC_DISC"); } - public static boolean isGoatHorn(ItemStack item) { - return item.getType().toString().contains("GOAT_HORN"); - } } diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetHornCooldownSubCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetHornCooldownSubCommand.java deleted file mode 100644 index fe1a53a..0000000 --- a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetHornCooldownSubCommand.java +++ /dev/null @@ -1,83 +0,0 @@ -package me.Navoei.customdiscsplugin.command.SubCommands; - -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.FloatArgument; -import dev.jorel.commandapi.executors.CommandArguments; -import io.papermc.paper.datacomponent.DataComponentTypes; -import io.papermc.paper.datacomponent.item.JukeboxPlayable; -import io.papermc.paper.datacomponent.item.UseCooldown; -import me.Navoei.customdiscsplugin.CustomDiscs; -import me.Navoei.customdiscsplugin.language.Lang; -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.NamespacedKey; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.components.UseCooldownComponent; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; - -import java.util.Objects; -import org.bukkit.Bukkit; - -public class SetHornCooldownSubCommand extends CommandAPICommand { - private final CustomDiscs plugin; - - public SetHornCooldownSubCommand(CustomDiscs plugin) { - super("goatcooldown"); - this.plugin = plugin; - - this.withFullDescription(NamedTextColor.GRAY + "Set the cooldown for a modified goat horn (range from 0 to "+ this.plugin.hornMaxCooldown +" in seconds)."); - this.withUsage("/cd goatcooldown "); - - this.withArguments(new FloatArgument("goatcooldown")); - - this.executesPlayer(this::onCommandPlayer); - this.executesConsole(this::onCommandConsole); - } - - private int onCommandPlayer(Player player, CommandArguments arguments) { - - ItemStack item = player.getInventory().getItemInMainHand(); - - if (!isCustomGoatHorn(item)) { - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_GOATHORN.toString())); - return 1; - } - - if (!player.hasPermission("customdiscs.horncooldown")) { - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NO_PERMISSION.toString())); - return 1; - } - - Float goatcooldown = Objects.requireNonNull(arguments.getByClass("goatcooldown", Float.class)); - - if ( goatcooldown < 0 || goatcooldown > this.plugin.hornMaxCooldown) { - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_COOLDOWN.toString().replace("%cooldown_value%", Float.toString(this.plugin.hornMaxCooldown)))); - return 1; - } - - ItemMeta meta = item.getItemMeta(); - meta.getPersistentDataContainer().set(new NamespacedKey(plugin, "horncooldown"), PersistentDataType.INTEGER, goatcooldown.intValue()); - item.setItemMeta(meta); - - player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_GOAT_COOLDOWN.toString().replace("%custom_goat_cooldown%", Float.toString(goatcooldown)))); - - return 1; - } - - private int onCommandConsole(ConsoleCommandSender executor, CommandArguments arguments) { - executor.sendMessage(NamedTextColor.RED + "Only players can use this command : '"+arguments+"'!"); - return 1; - } - - public boolean isCustomGoatHorn(ItemStack item) { - if (item==null) return false; - return item.getType().toString().contains("GOAT_HORN") && item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(plugin, "customhorn")); - } - -} diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetRangeSubCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetRangeSubCommand.java index 3469cbe..32bb834 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetRangeSubCommand.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/SetRangeSubCommand.java @@ -42,7 +42,7 @@ public class SetRangeSubCommand extends CommandAPICommand { ItemStack item = player.getInventory().getItemInMainHand(); - if (!isCustomDisc(item) && !isCustomGoatHorn(item)) { + if (!isCustomDisc(item)) { player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_DISC.toString())); return 1; } @@ -59,22 +59,12 @@ public class SetRangeSubCommand extends CommandAPICommand { return 1; } - if (isCustomDisc(item)) { - ItemMeta meta = item.getItemMeta(); - - PersistentDataContainer data = meta.getPersistentDataContainer(); - data.set(new NamespacedKey(this.plugin, "range"), PersistentDataType.FLOAT, range); - player.getInventory().getItemInMainHand().setItemMeta(meta); - } else if (isCustomGoatHorn(item)) { - ItemMeta meta = item.getItemMeta(); - - PersistentDataContainer data = meta.getPersistentDataContainer(); - data.set(new NamespacedKey(this.plugin, "range"), PersistentDataType.FLOAT, range); - player.getInventory().getItemInMainHand().setItemMeta(meta); - } - + ItemMeta meta = item.getItemMeta(); + PersistentDataContainer data = meta.getPersistentDataContainer(); + data.set(new NamespacedKey(this.plugin, "range"), PersistentDataType.FLOAT, range); + player.getInventory().getItemInMainHand().setItemMeta(meta); player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_RANGE.toString().replace("%custom_range%", Float.toString(range)))); - + return 1; } @@ -88,9 +78,4 @@ public class SetRangeSubCommand extends CommandAPICommand { return item.getType().toString().contains("MUSIC_DISC") && item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(plugin, "customdisc")); } - public boolean isCustomGoatHorn(ItemStack item) { - if (item==null) return false; - return item.getType().toString().contains("GOAT_HORN") && item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(plugin, "customhorn")); - } - } diff --git a/src/main/java/me/Navoei/customdiscsplugin/event/GoatHorn.java b/src/main/java/me/Navoei/customdiscsplugin/event/GoatHorn.java deleted file mode 100644 index 0fa082a..0000000 --- a/src/main/java/me/Navoei/customdiscsplugin/event/GoatHorn.java +++ /dev/null @@ -1,104 +0,0 @@ -package me.Navoei.customdiscsplugin.event; - -import me.Navoei.customdiscsplugin.CustomDiscs; -import me.Navoei.customdiscsplugin.PlayerManager; -import me.Navoei.customdiscsplugin.VoicePlugin; -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.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.block.Block; -import org.bukkit.block.TileState; -import org.bukkit.block.data.Powerable; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; -import org.jetbrains.annotations.NotNull; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Objects; - -public class GoatHorn implements Listener { - - static CustomDiscs customDiscs = CustomDiscs.getInstance(); - PlayerManager playerManager = PlayerManager.instance(); - - @EventHandler(priority = EventPriority.HIGHEST) - public void onPlayerInteract(PlayerInteractEvent event) throws IOException { - ItemStack item = event.getItem(); - Player player = event.getPlayer(); - - if (item == null) return; - if (item.getType() != Material.GOAT_HORN) return; - - Block block = event.getClickedBlock(); - if (player.hasCooldown(Material.GOAT_HORN)) return; - - if (isCustomGoatHorn(event) && ((event.getAction() == Action.RIGHT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_AIR))) { - - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && !player.isSneaking()) { - if ((block.getBlockData() instanceof Powerable) || (block instanceof TileState) && event.useInteractedBlock().equals(Event.Result.ALLOW)) { - return; - } - } - - String soundFileName = event.getItem().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(customDiscs, "customhorn"), PersistentDataType.STRING); - - @NotNull PersistentDataContainer persistentDataContainer = event.getItem().getItemMeta().getPersistentDataContainer(); - - float range; - NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "range"); - if(persistentDataContainer.has(customSoundRangeKey, PersistentDataType.FLOAT)) { - range = Math.min(persistentDataContainer.get(customSoundRangeKey, PersistentDataType.FLOAT), CustomDiscs.getInstance().musicDiscMaxDistance); - } else { - range = Math.min(CustomDiscs.getInstance().musicDiscDistance, CustomDiscs.getInstance().musicDiscMaxDistance); - } - - int hornCooldown; - NamespacedKey hornCooldownKey = new NamespacedKey(customDiscs, "horncooldown"); - if(persistentDataContainer.has(hornCooldownKey, PersistentDataType.INTEGER)) { - hornCooldown = Math.min(persistentDataContainer.get(hornCooldownKey, PersistentDataType.INTEGER), CustomDiscs.getInstance().hornMaxCooldown) * 20; - } else { - hornCooldown = Math.min(Math.round(CustomDiscs.getInstance().hornCooldown) * 20, CustomDiscs.getInstance().hornMaxCooldown) * 20; - } - - Path soundFilePath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", soundFileName); - - if (soundFilePath.toFile().exists()) { - - Component songNameComponent = Objects.requireNonNull(event.getItem().getItemMeta().lore()).get(0).asComponent(); - String songName = PlainTextComponentSerializer.plainText().serialize(songNameComponent); - - TextComponent customActionBarSongPlaying = Component.text() - .content("Now Horn Playing: " + songName) - .color(NamedTextColor.GOLD) - .build(); - - assert VoicePlugin.voicechatServerApi != null; - playerManager.playLocationalAudioHorn(VoicePlugin.voicechatServerApi, soundFilePath, player, customActionBarSongPlaying.asComponent(), range); - player.setCooldown(Material.GOAT_HORN, hornCooldown); - } else { - player.sendMessage(NamedTextColor.RED + "Sound file not found."); - event.setCancelled(true); - throw new FileNotFoundException("Sound file is missing!"); - } - } - } - - public static boolean isCustomGoatHorn(PlayerInteractEvent e) { - if (e.getItem()==null) return false; - return e.getItem().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(customDiscs, "customhorn")); - } - -} \ No newline at end of file diff --git a/src/main/java/me/Navoei/customdiscsplugin/language/Lang.java b/src/main/java/me/Navoei/customdiscsplugin/language/Lang.java index 0d8db19..5c8e967 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/language/Lang.java +++ b/src/main/java/me/Navoei/customdiscsplugin/language/Lang.java @@ -20,11 +20,7 @@ public enum Lang { NOW_PLAYING("now-playing","&6Now playing: %song_name%"), DISC_CONVERTED("disc-converted", "&aConverted disc to new format! &fThis is due to changes in newer Minecraft versions which introduced &7JukeboxPlayableComponent&f."), INVALID_RANGE("invalid-range","&rYou need to chose a range between 1 and %range_value%"), - CREATE_CUSTOM_RANGE("create-custom-range", "&7Your range is set to: &a\"%custom_range%\"."), - NOT_HOLDING_GOATHORN("not-holding-goathorn", "&cYou must hold a goat horn in your main hand."), - NOT_HOLDING_MODIFIED_GOATHORN("not-holding-modified-goathorn", "&cYou must hold a modified goat horn in your main hand."), - INVALID_COOLDOWN("invalid-cooldown","&cYou need to chose a cooldown between 0 and %cooldown_value%"), - CREATE_CUSTOM_GOAT_COOLDOWN("create-custom-goat-cooldown", "&7Your goat horn cooldown is set to: &a\"%custom_goat_cooldown%\"."); + CREATE_CUSTOM_RANGE("create-custom-range", "&7Your range is set to: &a\"%custom_range%\"."); private final String path; private final String def; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6823c95..7813db5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,12 +12,6 @@ music-disc-volume: 1 # The maximum download size in megabytes. max-download-size: 50 -# The default cooldown time for horns in seconds from 1 to the max value of horn-max-cooldown. -horn-cooldown: 7 - -# The default max cooldown time for horns in seconds (5 minutes by default). -horn-max-cooldown: 300 - #Custom Discs Help Page help: - "&8-[&6CustomDiscs Help Page&8]-" diff --git a/src/main/resources/goat_horn_category.png b/src/main/resources/goat_horn_category.png deleted file mode 100644 index e1a7d6de6c035514c1aa8c232b07249bc596cf43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 199 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPGa3-AeX1=5QbPj0L$OG`1ME)D%m++XAM*+2 zI2>?NF35A~M0_mJ3I