"sender cannot be resolved to a variable"- noob question

Discussion in 'Plugin Development' started by Jayteescout, Sep 4, 2013.

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

    Jayteescout

    I just starting out with plugin development.

    I am following this tutorial:

    I am getting an error that the "sender" variable can't be defined for some reason. As I said I have no idea what I'm doing so if someone could help me out in plain English that would be much appreciated.

    Here's my source:

    Code:java
    1. package me.jay.myPlugin;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Tutorial extends JavaPlugin {
    10.  
    11. public void onEnable() {
    12. getLogger().info("It's on!");
    13. }
    14.  
    15. public void onDisable() {
    16. getLogger().info("It's off!");
    17. }
    18.  
    19. public boolean onCommand(CommandSender server, Command cmd, String label, String[] args){
    20. if(sender instanceof Player) {
    21. Player player = (Player) sender;
    22. if(cmd.getName().equalsIgnoreCase("Hello")) {
    23. player.sendMessage(ChatColor.AQUA + "Hello World!");
    24. }
    25.  
    26. }
    27. }
     
  2. Offline

    mydeblob

    Jayteescout
    Nooby mistake indeed, you mispelled sender in your onCommand.
    You had it like this
    Code:java
    1. public boolean onCommand(CommandSender server, Command cmd, String label, String[] args){

    Notice how it is (CommandSender server) it should be (CommandSender sender)
    Do it like this
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. if(sender instanceof Player) {
    3. Player player = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("Hello")) {
    5. player.sendMessage(ChatColor.AQUA + "Hello World!");
    6. }
    7.  
    8. }
    9. }
     
    Jayteescout likes this.
  3. Offline

    Jayteescout

    Ah, thanks!
     
  4. Offline

    UltimateBudgie

    Are you using an IDE (Eclipse, netbeans, etc.)?

    If not, I seriously suggest it. They pickup silly errors like this very easily!
     
Thread Status:
Not open for further replies.

Share This Page