英文:
Vanish Plugin 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 Unvanished§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;
}
}
请注意,我已经将HTML实体编码(如")还原为正常的引号字符,以便您可以正确使用代码。
英文:
I have made a vanish plugin but I'm having trouble with making it so server admins can see the person when they are in vanish. I want to make it so if they have permission they can see people in vanish.
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;
}
}
答案1
得分: 0
Sure, here's the translated code snippet:
for (Player people : Bukkit.getOnlinePlayers()) {
if (!people.hasPermission("xyz.vanish")) {
people.hidePlayer(plugin, player);
}
}
Please note that I've corrected the syntax error in the original code by adding a closing parenthesis after hasPermission("xyz.vanish")
.
英文:
for (Player people : Bukkit.getOnlinePlayers()) {
people.hidePlayer(plugin, player);
}
this code snippet is the problem. You have to add a if query if the other player have the permissions to see the player. As example the following code:
for (Player people : Bukkit.getOnlinePlayers()) {
if(!people.hasPermission("xyz.vanish"){
people.hidePlayer(plugin, player);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论