Code:java public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ Player p = (Player)sender; if(cmd.getName().equalsIgnoreCase("admin") && (p.getGameMode() == GameMode.SURVIVAL) && (p.hasPermission("iervolib.admin"))){ p.sendMessage(ChatColor.GREEN + ChatColor.ITALIC.toString() + "Você entrou do modo Admin!"); p.setGameMode(GameMode.CREATIVE); Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " left the game."); for(Player players : Bukkit.getOnlinePlayers()){ players.hidePlayer(p); } }else{ if(cmd.getName().equalsIgnoreCase("admin") && (p.getGameMode() == GameMode.CREATIVE) && (p.hasPermission("iervolib.admin"))){ p.sendMessage(ChatColor.RED + ChatColor.ITALIC.toString() + "Você saiu do modo Admin!"); p.setGameMode(GameMode.SURVIVAL); Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " joined the game."); for(Player players : Bukkit.getOnlinePlayers()){ players.showPlayer(p); } } } return true;} How I check if the sender IS HIDE or IS NOT HIDE?
Well, idk how to do it, i'm noob, can you please write it? Garris0n I add like this? list.add(all.getName()); And if yes, how I check after add? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
ArrayList<String> hiddenPlayers = new ArrayList<String>; When a player goes into 'hide' mode: hiddenPlayers.add(player.getName()); When a player goes out of 'hide' mode: hiddenPlayers.remove(player.getName()); To check if a player is in 'hide' mode: if(hiddenPlayers.contains(player.getName())){ //hide mode } Remember never save players, only player names.
There is some problem.. I can't leave the admin mode, I can only join the admin mode.. Code:java ArrayList<String> hiddenPlayers = new ArrayList<String>(); public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ Player p = (Player)sender; if(cmd.getName().equalsIgnoreCase("admin") && (p.hasPermission("iervolib.admin"))){ p.sendMessage(ChatColor.GREEN + ChatColor.ITALIC.toString() + "You are now in the Admin Mode!"); p.setGameMode(GameMode.CREATIVE); Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " left the game."); hiddenPlayers.add(p.getName()); for(Player players : Bukkit.getOnlinePlayers()){ players.hidePlayer(p); } }else{ if(cmd.getName().equalsIgnoreCase("admin") && (hiddenPlayers.contains(p.getName())) && (p.hasPermission("iervolib.admin"))){ p.sendMessage(ChatColor.RED + ChatColor.ITALIC.toString() + "You leave the Admin Mode!"); p.setGameMode(GameMode.SURVIVAL); hiddenPlayers.remove(p.getName()); Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " joined the game."); for(Player players : Bukkit.getOnlinePlayers()){ players.showPlayer(p); } } } return true;}
You're not even checking if they're in the list the first time around...you may want to watch some java tutorials.
So the first time I have to check and remove the player from the admin mode and in the secound time add? Garris0n now worked, look how I did: Code:java ArrayList<String> hiddenPlayers = new ArrayList<String>(); public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ Player p = (Player)sender; if(cmd.getName().equalsIgnoreCase("admin") && (hiddenPlayers.contains(p.getName()) == false) && (p.hasPermission("iervolib.admin"))){ p.sendMessage(ChatColor.GREEN + ChatColor.ITALIC.toString() + "Você entrou do modo Admin!"); p.setGameMode(GameMode.CREATIVE); Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " left the game."); hiddenPlayers.add(p.getName()); for(Player players : Bukkit.getOnlinePlayers()){ players.hidePlayer(p); } }else{ if(cmd.getName().equalsIgnoreCase("admin") && (hiddenPlayers.contains(p.getName()) == true) && (p.hasPermission("iervolib.admin"))){ p.sendMessage(ChatColor.RED + ChatColor.ITALIC.toString() + "Você saiu do modo Admin!"); p.setGameMode(GameMode.SURVIVAL); hiddenPlayers.remove(p.getName()); Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " joined the game."); for(Player players : Bukkit.getOnlinePlayers()){ players.showPlayer(p); } } } return true;} But I have another question: as you can see the sender will be hide only for the online players.. (if a player enter in the server after I did /admin he will still see me) is there some way to be hide for the server? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
First of all, you should be checking if(!hiddenPlayers.contains(player.getName()) in the first part. Second, listen to the PlayerJoinEvent and check if a player is in the list. If one is hide the player in the list from the player who joined. Do the opposite on the leave event.
1- This is not a plugin 2- You don't need to write, just rewrite or add something But ok, thanks anyway