Help

Discussion in 'Plugin Development' started by Iervolino, Jun 29, 2013.

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

    Iervolino

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    2. {
    3. Player p = (Player)sender;
    4. if(cmd.getName().equalsIgnoreCase("admin") && (p.getGameMode() == GameMode.SURVIVAL) && (p.hasPermission("iervolib.admin"))){
    5. p.sendMessage(ChatColor.GREEN + ChatColor.ITALIC.toString() + "Você entrou do modo Admin!");
    6. p.setGameMode(GameMode.CREATIVE);
    7. Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " left the game.");
    8. for(Player players : Bukkit.getOnlinePlayers()){
    9. players.hidePlayer(p);
    10. }
    11. }else{
    12. if(cmd.getName().equalsIgnoreCase("admin") && (p.getGameMode() == GameMode.CREATIVE) && (p.hasPermission("iervolib.admin"))){
    13. p.sendMessage(ChatColor.RED + ChatColor.ITALIC.toString() + "Você saiu do modo Admin!");
    14. p.setGameMode(GameMode.SURVIVAL);
    15. Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " joined the game.");
    16. for(Player players : Bukkit.getOnlinePlayers()){
    17. players.showPlayer(p);
    18. }
    19. }
    20. }
    21. return true;
    22. }


    How I check if the sender IS HIDE or IS NOT HIDE?
     
  2. Offline

    Garris0n

    Save them to a list of players and check if it contains them.
     
  3. Offline

    Iervolino


    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.
     
    Last edited by a moderator: Jun 2, 2016
  4. Offline

    Garris0n

    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.
     
  5. Offline

    Iervolino


    There is some problem.. I can't leave the admin mode, I can only join the admin mode..

    Code:java
    1. ArrayList<String> hiddenPlayers = new ArrayList<String>();
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    4. {
    5. Player p = (Player)sender;
    6. if(cmd.getName().equalsIgnoreCase("admin") && (p.hasPermission("iervolib.admin"))){
    7. p.sendMessage(ChatColor.GREEN + ChatColor.ITALIC.toString() + "You are now in the Admin Mode!");
    8. p.setGameMode(GameMode.CREATIVE);
    9. Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " left the game.");
    10. hiddenPlayers.add(p.getName());
    11. for(Player players : Bukkit.getOnlinePlayers()){
    12. players.hidePlayer(p);
    13. }
    14. }else{
    15. if(cmd.getName().equalsIgnoreCase("admin") && (hiddenPlayers.contains(p.getName())) && (p.hasPermission("iervolib.admin"))){
    16. p.sendMessage(ChatColor.RED + ChatColor.ITALIC.toString() + "You leave the Admin Mode!");
    17. p.setGameMode(GameMode.SURVIVAL);
    18. hiddenPlayers.remove(p.getName());
    19. Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " joined the game.");
    20. for(Player players : Bukkit.getOnlinePlayers()){
    21. players.showPlayer(p);
    22. }
    23. }
    24. }
    25. return true;
    26. }
     
  6. Offline

    Garris0n

    You're not even checking if they're in the list the first time around...you may want to watch some java tutorials.
     
    dillyg10 likes this.
  7. Offline

    Iervolino


    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
    1. ArrayList<String> hiddenPlayers = new ArrayList<String>();
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    4. {
    5. Player p = (Player)sender;
    6. if(cmd.getName().equalsIgnoreCase("admin") && (hiddenPlayers.contains(p.getName()) == false) && (p.hasPermission("iervolib.admin"))){
    7. p.sendMessage(ChatColor.GREEN + ChatColor.ITALIC.toString() + "Você entrou do modo Admin!");
    8. p.setGameMode(GameMode.CREATIVE);
    9. Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " left the game.");
    10. hiddenPlayers.add(p.getName());
    11. for(Player players : Bukkit.getOnlinePlayers()){
    12. players.hidePlayer(p);
    13. }
    14. }else{
    15. if(cmd.getName().equalsIgnoreCase("admin") && (hiddenPlayers.contains(p.getName()) == true) && (p.hasPermission("iervolib.admin"))){
    16. p.sendMessage(ChatColor.RED + ChatColor.ITALIC.toString() + "Você saiu do modo Admin!");
    17. p.setGameMode(GameMode.SURVIVAL);
    18. hiddenPlayers.remove(p.getName());
    19. Bukkit.broadcastMessage(ChatColor.YELLOW + p.getName() + ChatColor.YELLOW + " joined the game.");
    20. for(Player players : Bukkit.getOnlinePlayers()){
    21. players.showPlayer(p);
    22. }
    23. }
    24. }
    25. return true;
    26. }


    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.
     
    Last edited by a moderator: Jun 2, 2016
  8. Offline

    Garris0n

    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.
     
  9. Offline

    Iervolino


    Well, I didn't understood the PlayerJoinEvent part, can you rewrite the code please? Thanks..
     
  10. Offline

    Garris0n

    I'm not going to write the whole plugin for you...
     
  11. Offline

    Iervolino

    1- This is not a plugin
    2- You don't need to write, just rewrite or add something

    But ok, thanks anyway
     
Thread Status:
Not open for further replies.

Share This Page