Solved Error with send a welcome message

Discussion in 'Plugin Development' started by AguilaAudaz, Oct 1, 2013.

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

    AguilaAudaz

    Well im helping a friend with a code, he speaks spanish, so im helping him with it but when a player joins, the player don't receieve the message

    My main class:

    Code:java
    1. import java.util.logging.Logger;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Main extends JavaPlugin
    10. {
    11. Logger log = null;
    12.  
    13. private Utils plCommands = null;
    14. @Override
    15. public void onEnable() {
    16. log = this.getLogger();
    17. log.info("Ha sido activado");
    18.  
    19. plCommands = new Utils();
    20.  
    21. getCommand("head").setExecutor(plCommands);
    22. }
    23. @EventHandler
    24. public void onPlayerJoin(PlayerJoinEvent event)
    25. {
    26. Player player = event.getPlayer();
    27. player.sendMessage(ChatColor.AQUA + "Escribe " + ChatColor.YELLOW + "/head " + ChatColor.AQUA + "Para tener tu cabeza!");
    28. player.sendMessage(ChatColor.GREEN + "Plugin hecho por Chris Manuel");
    29. }
    30. @Override
    31. public void onDisable(){
    32. log.info("Ha sido desactivado");
    33. }
    34. }


    I don't have problems with the other class
     
  2. Offline

    TheEyeMonster

    if onCommand

    Not getcommand.
     
    AguilaAudaz likes this.
  3. Offline

    MrSnare

    Your class needs to implement Listener
     
    AguilaAudaz likes this.
  4. Offline

    TheEyeMonster

    Here is the original code for command:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    	if(cmd.getName().equalsIgnoreCase("basic")){ // If the player typed /basic then do the following...
    		// doSomething
    		return true;
    	} //If this has happened the function will return true. 
            // If this hasn't happened the a value of false will be returned.
    	return false; 
    }
     
    AguilaAudaz likes this.
  5. Offline

    AguilaAudaz

  6. Offline

    TheEyeMonster


    implements Listener

    After the javaplugin part
     
    AguilaAudaz likes this.
  7. Offline

    AguilaAudaz

    TheEyeMonster i did about add the implements Listener but won't work

    MrSnare Amm, i make a new Class called WelcomeListener

    So i add this code:

    Code:java
    1. package me.christophermanuel.heads;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8.  
    9. public class WelcomeListener implements Listener{
    10. @EventHandler
    11. public void onPlayerJoin(PlayerJoinEvent event)
    12. {
    13. Player player = event.getPlayer();
    14. player.sendMessage(ChatColor.AQUA + "Escribe " + ChatColor.YELLOW + "/head " + ChatColor.AQUA + "Para tener tu cabeza!");
    15. player.sendMessage(ChatColor.GREEN + "Plugin hecho por Chris Manuel");
    16. }
    17. }


    So how i "link" or make work that in the Main class?

    MAIN:

    Code:java
    1. package me.christophermanuel.heads;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class Main extends JavaPlugin
    7. {
    8. Logger log = null;
    9.  
    10. private Utils plCommands = null;
    11. @Override
    12. public void onEnable() {
    13. log = this.getLogger();
    14. log.info("Ha sido activado");
    15.  
    16. plCommands = new Utils();
    17.  
    18. getCommand("head").setExecutor(plCommands);
    19. }
    20. @Override
    21. public void onDisable(){
    22. log.info("Ha sido desactivado");
    23. }
    24. }


    Sorry im new with this :/
     
  8. Offline

    MrSnare

    It's ok. Try watching some bukkit plugin tutorials on youtube. That's how I started :)

    To make your plugin "Listen" to your listener class you must add this line into your onEnable() method.

    Code:java
    1. Bukkit.getPluginManager().registerEvents(new WelcomeListener() , this);
     
    AguilaAudaz likes this.
  9. Offline

    Block34

    AguilaAudaz
    If you put extends Listener after javaplugin thats for if you want events in the main class.
     
    AguilaAudaz likes this.
  10. Offline

    AguilaAudaz

  11. Offline

    Block34

    Np! glad it worked
     
    AguilaAudaz likes this.
Thread Status:
Not open for further replies.

Share This Page