Bukkit's playSound method must somehow access a play-file and stream it. How could I possibly make my own custom playSound method? Not depending on Bukkit at all? Any ideas?
@DoggyCode™ No. Bukkit's playSound method pretty much tells the client "Hey! Play this sound that you have!".
@DoggyCode™ Minecraft sends the name of the sound it wants to player in the form of a string (e.g. "bat.hurt.ogg"). Use .playSound("Sound Name"....); to play your custom sound.
I have a question.. what is wrong with this?i need to play a sound with this pitch and volumen on player interact with chest for example.. the command work, but the sound no. Code: public void onCommand(Command cmd, CommandSender sender, String commandLabel, String[] args) { //command name if(commandLabel.equalsIgnoreCase("chestopen")) { Player p = (Player) sender; World w = p.getWorld(); Player t = p.getServer().getPlayer(args[0]); w.playSound(p.getLocation(), Sound.CHEST_OPEN, 10, 0); } }
@maxmar628 You set the pitch to 0. The lowest you can go before muting the sound is 1. Note: Use cmd.getName() instead of commandlebel and DON'T BLIND CAST! Make sure the sender is a player before casting. Also don't automatically get the args that may or may not exist. check to make sure args[0] exists and that t is not null.
the pitch is the frequency, the volumen "10" is the sound to mute this value is "0" EDIT: This is my completly code and work perfectly now. Ty Code: import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.World; 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.player.PlayerInteractEvent; public class ChestListener implements Listener { @EventHandler public void playerInteract(PlayerInteractEvent e){ Player p = e.getPlayer(); World w = p.getWorld(); if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ Material m = e.getClickedBlock().getType(); if (m.equals(Material.CHEST)){ e.setCancelled(true); w.playSound(p.getLocation(), Sound.CHEST_OPEN, 1, 10); p.sendMessage(ChatColor.GREEN + "Chest sound!"); } } } }