Solved Where is the mistake ?

Discussion in 'Plugin Development' started by MCinemaGamer, Jul 26, 2013.

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

    MCinemaGamer

    Hi, I'm tryng to create a plugin, that should play a sound every time a player join the server.
    I've tried with this code here
    Code:java
    1. package it.multicraft;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.Sound;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class JSound extends JavaPlugin {
    12. @EventHandler
    13. public void onPlayerJoin(PlayerJoinEvent event){
    14. for(Player player: Bukkit.getOnlinePlayers()){
    15. Location location = player.getLocation();
    16. player.playSound(location, Sound.NOTE_PIANO, 100, 1);
    17.  
    18. }
    19. }
    20. }
    21.  


    Eclipse and the console don't mark any error.

    Now, can you tell me where is the mistake ?
     
  2. Offline

    chasechocolate

    Did you register your events?
     
  3. Offline

    Rocoty

    chasechocolate Obviously not. It looks as though he is trying to create an EventHandler method in the main class, which, by the way, does not implement Listener nor is registered as an event listener

    MCinemaGamer I suggest you look a bit more into how the Bukkit API works.
     
  4. Offline

    MCinemaGamer

    I've tryed with this code here. I created a second class called "Listener". I'm new at plugin development, and I'm working hard studyng the Bukkit API.
    Here's the main class

    Code:java
    1. package it.multicraft.JSound;
    2.  
    3. import it.multicraft.JSound.JoinListener;
    4.  
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class JSoundMain extends JavaPlugin {
    8. public void onEnable(){
    9.  
    10. }
    11. public void onDisable(){
    12. getServer().getPluginManager().registerEvents(new JoinListener(), this);
    13. }
    14.  
    15. }


    And this is the Listener class

    Code:java
    1. package it.multicraft.JSound;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.Sound;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10.  
    11. public class JoinListener implements Listener {
    12. @EventHandler
    13. public void onPlayerJoin(PlayerJoinEvent event){
    14. for(Player player: Bukkit.getOnlinePlayers()){
    15. Location location = player.getLocation();
    16. player.playSound(location, Sound.NOTE_PIANO, 100, 1);
    17. }
    18. }
    19.  
    20. }


    Thanks for the help
     
  5. Offline

    Polaris29

    MCinemaGamer You're supposed to register your events when the plugin enables, not when it disables...
     
    Alex5657 likes this.
  6. Offline

    MCinemaGamer

    whops.... Sorry, I'm very distracted and I'm creating this plugin with a friend... He's not a genius :)
    By the way, I'll try without this stupid mistake.
     
  7. Offline

    Alex5657

    The onDisable method is called when the plugin disables. Most of the time, when the server shuts down.
     
  8. Offline

    MCinemaGamer

    Hi, thanks everyone, now it works perfectly !
     
Thread Status:
Not open for further replies.

Share This Page