我的命令/消失有问题:当我消失时,一个玩家在我消失后加入游戏,他可以看到我。下面是命令和playerjoinevent+UpdateVish()的代码:
if(commandLabel.equalsIgnoreCase("vanish")) {
if (player.hasPermission("vanish.permission")) {
if(!vanish.contains(target)) {
vanish.add(target);
if (player == target) {
player.sendMessage(ChatColor.BLUE + "Ora sei in " + ChatColor.LIGHT_PURPLE + "Vanish" + ChatColor.BLUE+ ". Nessuno ti potrà vedere");
} else {
player.sendMessage(ChatColor.BLUE + "Hai Impostato " + ChatColor.DARK_BLUE + target.getName() + ChatColor.YELLOW + " in " + ChatColor.LIGHT_PURPLE + "Vanish");
target.sendMessage(ChatColor.BLUE + "Ora sei in Vanish. Nessuno ti potrà vedere");
}
for (Player persone : Bukkit.getOnlinePlayers()) {
if (!persone.hasPermission("visible.vanish")) {
persone.hidePlayer(this, target);
}
}
} else {
vanish.remove(target);
for (Player persone : Bukkit.getOnlinePlayers()) {
persone.showPlayer(this, target);
}
if (player == target) {
player.sendMessage(ChatColor.RED + "Ora non sei in " + ChatColor.LIGHT_PURPLE + "Vanish" + ChatColor.RED+ ". Tutti ti potranno vedere");
} else {
player.sendMessage(ChatColor.RED + "Hai disattivato " + ChatColor.DARK_BLUE + target.getName() + ChatColor.YELLOW + " dal " + ChatColor.LIGHT_PURPLE + "Vanish");
target.sendMessage(ChatColor.RED + "Ora non sei in Vanish. Tutti ti potranno vedere");
}
}
} else {
player.sendMessage(ChatColor.RED + "Non hai il permesso di usare questo comando");
}
return true;
}
这里是playerjoinevent+UpdateVish()
@EventHandler
public void OnPlayerJoin(PlayerJoinEvent e) {
updateVanish();
}
public void updateVanish() {
for (Player persone : Bukkit.getOnlinePlayers()) {
if (vanish.contains(persone)) {
for (Player persone2 : Bukkit.getOnlinePlayers() ) {
persone2.hidePlayer(this, persone);
}
}
}
}
谢谢!
1条答案
按热度按时间7gyucuyw1#
这可以通过创建一个包含所有当前消失玩家的列表来解决,然后在新玩家加入后,使用playerjoinevent迭代所有当前消失的玩家,并使用:player.hideplayer(t)为新手消失他们
我目前不拥有构建正确代码的工具,但如果您在阅读了上述内容后仍有疑问,我可以提供更好的详细信息。