Solved Can't hide myself

Discussion in 'Spigot Plugin Development' started by Niqck, Mar 26, 2020.

  1. I am trying to make a simple vanish plugin but it won't hide myself.
    It will send the message but won't hide me.

    Code (Java):

    package me.niqck.SimpleVanish;

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

    public class Main extends JavaPlugin {

        @Override
        public void onEnable() {

        }

        @Override
        public void onDisable() {

        }

        public boolean onCommand(CommandSender sender, Command cnd, String label, String[] args) {
            if (cnd.getName().equalsIgnoreCase("vanish")) {
                Player playerToHide = (Player) sender;
                if (args.length == 0) {
                    if (!(sender instanceof Player)) {
                        sender.sendMessage(ChatColor.RED + "You need to be a player to use this command.");
                        return true;
                    }
                    else {
                        if (playerToHide.hasPermission("vanish.use")) {
                            for (Player allPlayers : getServer().getOnlinePlayers()) {
                                playerToHide.hidePlayer(playerToHide);
                                playerToHide.sendMessage(ChatColor.GREEN + "You have vanished.");
                                return true;


                            }

                        }
                        else {
                            sender.sendMessage(ChatColor.RED + "You are not allowed to use /vanish.");
                            return true;
                        }
                    }


                }
                else {
                    sender.sendMessage(ChatColor.RED + "Later.");
                    return true;
                }

            }



            return false;
        }
    }
     
  2. You are hide but for others players, the server see you, if you want to hide completely you have to use "nms" and i don't know if it will work properly.
     
  3. You're hiding yourself, from yourself, of course you're not vanished for other players.

    Your first cast to Player and then make an instanceof check, it should be the other way around
     
    • Like Like x 1
  4. Thanks a lot, I didn't know it worked that way!
     
  5. Choco

    Moderator