消失的插件Minecraft

问题描述

我制作了一个消失的插件,但是在制作时遇到了麻烦,因此服务器管理员可以在消失时看到该人。我要这样做,以便在获得许可的情况下可以看到消失的人。

public class VanishCommand implements CommandExecutor {

    VanishPlugin plugin;

    public VanishCommand(VanishPlugin plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {

        Player p = (Player) sender;

        if (p.hasPermission("vanish.vanish")) {

            if (sender instanceof Player) {
                Player player = (Player) sender;
                if (plugin.invisible_list.contains(player)) {
                    for (Player people : Bukkit.getonlinePlayers()) {
                        people.showPlayer(plugin,player);
                    }
                    plugin.invisible_list.remove(player);
                    player.sendMessage("§cYou Are Now Un Vanished§r");
                } else if (!plugin.invisible_list.contains(player)) {
                    for (Player people : Bukkit.getonlinePlayers()) {
                        people.hidePlayer(plugin,player);
                    }
                    plugin.invisible_list.add(player);
                    player.sendMessage("§aYou Are Now Vanished!§r");

                }
            }
        }
        return true;
    }
}

解决方法

    for (Player people : Bukkit.getOnlinePlayers()) {
                    people.hidePlayer(plugin,player);
                }

此代码段就是问题。您必须添加一个if查询,以便其他玩家有权查看该玩家。例如,以下代码:

    for (Player people : Bukkit.getOnlinePlayers()) {
                    if(!people.hasPermission("xyz.vanish"){
                    people.hidePlayer(plugin,player);
                }
}