Solved Sender cannot be resolved to a variable

Discussion in 'Spigot Plugin Development' started by thecamzone, May 12, 2016.

  1. Hello! I'm trying to develop a vanish plugin for my server. I have all the code written and no errors are given except one that I cannot figure out. It says "Sender cannot be resolved to a variable"

    Heres the whole main class (Only class). Very sorry if code is sloppy.
    package me.TheCamZone.EQVanish;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin implements Listener {
    private ArrayList<Player> vanished = new ArrayList<Player>();

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    if (!(sender instanceof Player)) {
    sender.sendMessage(ChatColor.RED + "You must be a player to vanish.");
    return true;
    }
    }

    Player p = (Player) sender;
    if(cmd.getName().equalsIgnoreCase("vanish")){
    if(!p.hasPermission("eq.vanish")){
    p.sendMessage(ChatColor.RED + "You do not have permission to run this command.");
    }
    if(p.hasPermission("eq.vanish")){
    if(!(vanished.contains(p))){
    for(Player pl : Bukkit.getServer().getOnlinePlayers()){
    pl.hidePlayer(p);
    vanished.add(p);
    p.sendMessage(ChatColor.LIGHT_PURPLE + "You are now vanished to all nonstaff members.");
    if(pl.hasPermission("eq.vanish.see")){
    pl.showPlayer(p);
    }
    if(pl.hasPermission("diamondfac.vanishalert")){
    pl.sendMessage("§8[§c§lNOTICE§8] " + ChatColor.RED + pl.getName() + " has toggled vanish on.");
    }
    }
    }


    if(vanished.contains(p)){
    for(Player pl : Bukkit.getServer().getOnlinePlayers()){
    pl.showPlayer(p);
    vanished.remove(p);
    p.sendMessage(ChatColor.LIGHT_PURPLE + "You are now visible to all nonstaff members.");
    }
    for(Player pl : Bukkit.getServer().getOnlinePlayers()){
    if(pl.hasPermission("diamondfac.vanishalert")){
    pl.sendMessage("§8[§c§lNOTICE§8] " + ChatColor.RED + pl.getName() + " has toggled vanish off.");
    }
    }
    }
    }
    }
    }
    }

    Thanks for any help you can provide!
     
    #1 thecamzone, May 12, 2016
    Last edited: May 12, 2016
  2. First, please put all your code in proper <code> tags.

    Anyway, I think your issue is where your closing brackets are. You have two closing brackets on this if statement, so that's going to cause an issue. If I were you, I would trace your curly brackets, from where they open to where they close. It's very difficult for me to see the code, and I don't feel like counting brackets :p.
     
    • Agree Agree x 1
  3. Yep, that was the error! Thanks for your help!

    I will also do <code> tags from now on.
     
  4. No problem! And thanks, it helps everyone :)