Help Needed Playing Notes at Players

Discussion in 'Plugin Development' started by Benlewis9000, Feb 8, 2014.

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


    Ok, so I recently just learnt how to use the scheduler, and with the knowledge I had gained I moved on to making a doorbell plugin. The plugin works so that they type /doorbell, it does some code (plays not and prints message) then moves on to the scheduler, waits three seconds and performs the same type of code. Whilst the scheduler is fine, I am having problems with playing the note. I used the format Player.playNote() like so:
    1. player.playNote(location, Instrument.PIANO, 10);
    2. //after the delay...
    3. player.playNote(location, Instrument.PIANO, 7);

    The whole chunk of code it goes through is:
    1. else if(commandLabel.equalsIgnoreCase("doorbell")){
    3. Player player = (Player) theSender;
    4. player.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Anyone home?");
    6. Player location = (Player) player.getLocation();
    8. player.playNote(location, Instrument.PIANO, 10);
    10. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    11. public void run() {
    12. for(Player online : Bukkit.getServer().getOnlinePlayers()){
    13. player.playNote(location, Instrument.PIANO, 7);
    14. }
    15. }
    16. }, 10L);
    17. }

    Eclipse tells me that playNote is not applicable with Player, but I am not really sure how to fix this?

    Thanks for your time,

    *The ERROR file is at *
    *The FULL CODE is at *

    Oh nevermind, a friend helped me out!

    I was using the playNote method incorrect.

    1. player.playNote(location, Instrument.PIANO, 7);

    should have been...

    1. player.playNote(player.getLocation(), Instrument.PIANO, Note.flat(1, Tone.B));

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 6, 2016
  2. Offline


    You are trying to cast player.getLocation() to a Player, while it isn't a player. Use
    Location location = player.getLocation(); instead, or just change the location in playSound to player.getLocation();.
    To make different sounds use byte like this:

    1. player.playNote(player.getLocation(), (byte) 4, (byte) 7);

    the (byte) 4 is the piano sound, you can change (byte) 7 is how high / low the sound is, in your case use 7 and 10 :)
  3. Offline



    I swapped over to your method, and it seems simple enough, however I have to lines: one with the pitch at 10 and the other with the pitch at 7. They sound exactly the same when played, even with the delays.
Thread Status:
Not open for further replies.

Share This Page