Vanish Halp

Discussion in 'Plugin Development' started by MagmaticBacca, Jun 18, 2015.

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

    MagmaticBacca

    Hewwow :3,
    Imma make this short so ive been making a vanish plugin, and i keep getting this Ambiguous method error, anyone know a fix or alternative for this?

    Heres my code
    Code:
    if (cmd.getName().equalsIgnoreCase("Vanish")) {
                World world = Bukkit.getWorld("InfernoMC");
                for (Player observers : Bukkit.getOnlinePlayers()) {
                    Player player = (Player) sender;
                    if (!observers.isOp()) {
                        if (player.isOp()) {
                            observers.hidePlayer(player);
                            sender.sendMessage("§6[§eVanish§6] " + ChatColor.YELLOW + "Vanish toggled!");
                            return true;
                        }
                    }
                }
            } else if (cmd.getName().equalsIgnoreCase("Reveal")) {
                World world = Bukkit.getWorld("InfernoMC");
                for (Player observers : Bukkit.getOnlinePlayers()) {
                    Player player = (Player) sender;
                    if (!observers.isOp()) {
                        if (player.isOp()) {
                            observers.showPlayer(player);
                            sender.sendMessage("§6[§eVanish§6] " + ChatColor.YELLOW + "Vanish toggled!");
                            return true;
                        }
                    }
                }
            }
            return true;
        }
    }
     
  2. Offline

    tomudding

    Where do you get it? Because I can't see it in this code
     
  3. Offline

    MagmaticBacca

    @tompudding sorry my bad its in the "getOnlinePlayers(this is where i get it))" nad plus theres a Null pointer exception in the console
     
  4. Offline

    Garnetty

    Post stack trace please
     
  5. Offline

    Drkmaster83

    Well, you really ought to move the permissions check for the Player (as well as the force-casting of the object) out of the for-loop.
    ...Because you're returning inside the for-loop right now, which will make it vanish only one person who isn't OP... and, additionally, if you were to remove that return statement, it would spam the command sender.
    Code:
    if (cmd.getName().equalsIgnoreCase("Vanish")) {
                if(!(sender instanceof Player)) return false;
                World world = Bukkit.getWorld("InfernoMC");
                Player player = (Player) sender;
                if (!player.isOp()) return false;
                for (Player observers : Bukkit.getOnlinePlayers()) {
                    if (observers.isOp()) continue;
                    observers.hidePlayer(player);
                }
                sender.sendMessage("§6[§eVanish§6] §eVanish toggled!");
    } else if (cmd.getName().equalsIgnoreCase("Reveal")) {
        if(!(sender instanceof Player)) return false;
        World world = Bukkit.getWorld("InfernoMC");
        Player player = (Player) sender;
        if (!player.isOp()) return false;
        for (Player observers : Bukkit.getOnlinePlayers()) {
            if (observers.isOp()) continue; //Question if you should add permission checking for this one; someone could remain invisible for someone who just received op after 'vanish' was executed
            observers.showPlayer(player);
        }
        sender.sendMessage("§6[§eVanish§6] §eVanish toggled!");
    }
    return true;
     
  6. Offline

    MagmaticBacca

    @Drkmaster83 thanks for the tip ;)

    After a lot of searches i have found that getting the bukkit api instead of the craftbukkit jat fixes it but thanks to the DMCA takedown request that is unavailable but thanks to everyone who tried to halp, i can figure the null pointer exception with some tinkering!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page