Playsound with resource pack sounds

Discussion in 'Plugin Development' started by sandlin006, Jan 25, 2015.

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

    sandlin006

    I am trying to make it so a song plays while in a region, like if the player goes to the shop there is a shop type song. with p.playSound(p.getLocation(), lobbymusic, 2F, 1F); the lobbymusic cant be resolved to a variable so it gives an error. In game with the /lobby command it gives an internal error.

    Here is the whole code
    Code:
    package me.sandlin6.sound;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    public class music extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("Lobby")){
            Player p = (Player)sender;
            if (sender instanceof Player){
                p.sendMessage(ChatColor.RED + "Playing the lobby Mucic");
                p.playSound(p.getLocation(), lobbymusic, 2F, 1F);
                return true;
            }
        }
    return false;
    }
      
    }
    As you can see it imports everything that it needs I just need to know how to get that resource pack sound to work.

    I have read the threads about this, but they are from like 2 years ago so I was wondering if there is any new stuff about this
     
  2. Offline

    ChipDev

    You did not define lobby music. You have to use a string!
    *If you have an error your code won't work, please try and learn java :)
     
    Last edited: Jan 25, 2015
  3. Offline

    sandlin006

    I am new to coding, so in eclipse it gave the option to create a local variable then to initialize the variable, it ends up like this
    Code:
                Sound lobbymusic = null;
                p.playSound(p.getLocation(), lobbymusic, 2F, 1F);
    Is that what you mean by using a string
    Edit: with that the internal error is gone but no sound
     
    ChipDev likes this.
  4. Offline

    ChipDev

    Null in java is nothing! It doesn't read your mind, you have to play it with your resource pack sounds.
    For example: customsounds/sound1.ogg
    (Only start inside of the 'sounds' of the resource pack! Custom sounds is a folder inside of your resource pack's sounds folder. You also have to make a sounds.son)
     
  5. Offline

    sandlin006

    I know that this is probably like super easy stuff but I am not good at this, when I add the sounds/lobbymusic.ogg it gives an error on the .ogg and there isnt a quick fix for it in eclipse and the sounds/lobbymusic creates
    int sounds;
    Object lobbymusic;
    Could you show me how the code would look if you were doing it
     
  6. Offline

    ChipDev

    "sounds/lobbymusic.ogg"
     
  7. Offline

    sandlin006

    So this is what I have now... What do I do for the .ogg because it says .ogg cant be resolved or is not a field. also how would I do it so the song plays when they are in a region like spawn... and have it loop

    Code:
    package me.sandlin6.sound;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    public class music extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("Lobby")){
            Player p = (Player)sender;
            if (sender instanceof Player){
                p.sendMessage(ChatColor.RED + "Playing the lobby Mucic");
                int sounds;
                Object lobbymusic;
                p.playSound(p.getLocation(), sounds/lobbymusic.ogg, 2F, 1F);
                return true;
            }
        }
    return false;
    }
    
    }
     
    Last edited: Jan 25, 2015
Thread Status:
Not open for further replies.

Share This Page