Sounds

Discussion in 'Plugin Development' started by DoggyCode™, Feb 17, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    DoggyCode™

    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?
     
  2. Offline

    teej107

    @DoggyCode™ No. Bukkit's playSound method pretty much tells the client "Hey! Play this sound that you have!".
     
    DoggyCode™ likes this.
  3. Offline

    DoggyCode™

    Oh well. So I can't play a custom file?
     
  4. Offline

    teej107

    Resource packs are the only way.
     
    DoggyCode™ likes this.
  5. Offline

    Zombie_Striker

    @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.
     
    DoggyCode™ likes this.
  6. Offline

    maxmar628

    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);
        }
        }
     
  7. Offline

    Zombie_Striker

    @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.
     
  8. Offline

    maxmar628

    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!");
    
           }
         }
        }
    
    
    
    }
    
    
     
    Last edited: Feb 17, 2016
  9. Offline

    DoggyCode™

    teej107 and Zombie_Striker like this.
  10. Offline

    teej107

    Well things can get stolen if you don't lock them up :p
     
    DoggyCode™ likes this.
  11. Offline

    WolfMage1

    N
    He's just simply using your thread to aid in solving is problem :3
     
Thread Status:
Not open for further replies.

Share This Page