Vanish command

Discussion in 'Plugin Development' started by Funnylizard99, Apr 12, 2017.

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

    Funnylizard99

    I've been creating a vanish plugin, but whenever I type sender in to eclipse it shows up with red lines under it, this also happens when I type cmd, here is the plugin.

    Code:
    package me.Funnylizard99.vanishcommand;
    
    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.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
      
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this,  this);
          
          
        }
    
        private ArrayList<Player> vanished = new ArrayList<Player>();
      
    
        @Override
        public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[] arg3) {
            if (sender instanceof Player) {
               (this is one of the senders with a red line under it)
                Player p = (Player) sender;
                                                    (This is one of the senders with a red line under it)
                if (cmd.getname().equalsIgnoreCase("vanish")) {
                   (This is the cmd with the red line under it)
                  
                    if (!vanished.contains(p))
                  
                    for(Player pl : Bukkit.getOnlinePlayers()){
                        pl.hidePlayer(p);
                    }
                    vanished.add(p);
                    p.sendMessage(ChatColor.GREEN + "Vanish enabled");
                    return true;
                }
          
                else {
                  
                    for(Player pl : Bukkit.getOnlinePlayers()){
                        pl.showPlayer(p);
                    }
                    vanished.remove(p);
                    p.sendMessage(ChatColor.GREEN + "Vanish disabled");
                    return true;
    
                }
            }
    
            return true;
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            for (Player p : vanished) {
                e.getPlayer().hidePlayer(p);
              
              
            }
        }
      
        @EventHandler
        public void onPLayerLeave(PlayerQuitEvent e) {
            vanished.remove(e.getPlayer());
        }
    
    }

    Your help is appreciated
     
    Last edited by a moderator: Apr 13, 2017
  2. Offline

    Zombie_Striker

    One of the flaws of auto generated methods; the method names may not always carry over. In this case, "sender' is replaced with arg0. Go through the onCommands parameters and rename all the variables.
     
  3. Offline

    Ragnarok_

    @Funnylizard99
    You're command boolean is incorrect. You have
    Code:
    public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[] arg3) {
    That would mean you would do Player p = (Player) arg0; for future reference.
    The "correct" boolean or whatever is
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
     
Thread Status:
Not open for further replies.

Share This Page