Solved Cant play sound when a block breaks

Discussion in 'Plugin Development' started by TheDepressedOne, May 24, 2021.

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

    TheDepressedOne

    Hi! I'm trying to make a plugin so that whenever you break a block it says the block broken in chat and plays a challenge compleated the sound effect. When I try to do it breaks and the main errors are "Cannot resolve symbol 'bukkit'" and 'playsound()' in 'Annoyingness' cannot be applied to '(org.bukkit.Location, org.bukkit.Sound, int, int)'

    Code:
    package TheDepressedOne.Annoyingness.main;
    import org.bukkit.Bukkit;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.Listener;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.Bukkit;
    
    public class Annoyingness extends JavaPlugin implements Listener {
    @Overridepublic 
    void onEnable() {
    getLogger().info("Successfully Enabled Annoyingness Plugin. Have Fun :)");
    };
    
    @Overridepublic 
    void onDisable() {
    getLogger().info("Successfully Disabled Annoyingness Plugin. Did ya get too annoyed?");
    }
    
    void playSound() {}
    
    @EventHandler
    
    public void onBlockBreak(BlockBreakEvent BlockBreak) {
    Player p = (Player) BlockBreak.getPlayer();Block b = (Block) BlockBreak.getBlock();playSound(p.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1);
    bukkit.broadcastMessage(p + " Broke the block " + b + "!");
    
    }
    
    
    }
    
     
    Last edited: May 24, 2021
  2. Offline

    timtower Administrator Administrator Moderator

    @TheDepressedOne You did not register the event.
    And there is no need to log your own plugin, Bukkit does that for you.
    bukkit should be Bukkit
     
  3. Offline

    davidclue

    @TheDepressedOne Is this not even your code because that would give errors in the IDE and it would give you a lot more problems. Also, why are you casting a player to a player instance?
     
  4. Offline

    TheDepressedOne

    @davidclue yes it is my code. And @timtower how would I register the event, also what is logging my plugin? I'm relatively new to this as all my java knowledge was replaced by c++ knowledge, so I forgot everything I know :).

    I was testing it and I completely removed the play sound event so now it's just detecting a block break and it does not detect ANY block breaks, I put text to see if the event was even firing but it's not as it does not output the text.
     
    Last edited: May 25, 2021
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    TheDepressedOne

    so in the onEnable class I would register an event like this: getServer().getPluginManager().registerEvents(new onBlockBreak(), this); ?

    New code :

    Code:
    
    package TheDepressedOne.Annoyingness.main;
    import org.bukkit.Bukkit;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.Listener;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.Bukkit;
    
    public class Annoyingness extends JavaPlugin implements Listener {
    @Overridepublic
    void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
    getLogger().info("Successfully Enabled Annoyingness Plugin. Have Fun :)");
    };
    
    @Overridepublic
    void onDisable() {
    getLogger().info("Successfully Disabled Annoyingness Plugin. Did ya get too annoyed?");
    }
    
    
    
    @EventHandler
    
    public void onBlockBreak(BlockBreakEvent BlockBreak) {
    Player p = (Player) BlockBreak.getPlayer();Block b = (Block) BlockBreak.getBlock();playSound(p.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1);
    bukkit.broadcastMessage(p + " Broke the block " + b + "!");
    
    playsound(p.getLocation(), Sound.<Challenge Compleated ID>, 1, 1);
    
    }
    
    
    }
     
    Last edited: May 25, 2021
  7. Offline

    timtower Administrator Administrator Moderator

  8. Offline

    TheDepressedOne

    Thanks tim, I will check this when i get back. I will then mark as solved once its good, and here is my final question: Are there any imports im missing for the API? Because when i check it it is marked as red.
     
  9. Offline

    timtower Administrator Administrator Moderator

    @TheDepressedOne Then hover your mouse over the error and it will tell you.
     
  10. Offline

    TheDepressedOne

    Ok, I will figure it out. In the mean time, thanks!
     
Thread Status:
Not open for further replies.

Share This Page