Solved Help with Command

Discussion in 'Plugin Development' started by Iervolino, Jun 28, 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.hasPermission("iervolib.admin"))){
    5. p.sendMessage(ChatColor.GREEN + ChatColor.BOLD.toString() + "Now you join the admin mode!");
    6. p.setGameMode(GameMode.CREATIVE);
    7. for (Player players : Bukkit.getOnlinePlayers()){
    8. players.hidePlayer(p);
    9. }
    10. } else {
    11. if(p.getGameMode() == GameMode.CREATIVE){
    12. p.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Now you leave the admin mode!");
    13. p.setGameMode(GameMode.SURVIVAL);
    14. for (Player players : Bukkit.getOnlinePlayers()){
    15. players.showPlayer(p);
    16. }
    17. }
    18. }
    19. return true;
    20. }


    I can only join the admin mode, but when I'm in creative mode and do /admin I can't leave the admin mode..
     
  2. You might need
    Code:
    (cmd.getName().equalsIgnoreCase("admin")
    to be a check at line 11 too.
    Oh I see it know at the top you need to check if player is in survival mode silly =P
    Because you are continuously setting the player to admin mode even if he is already in admin mode.
     
    Iervolino likes this.
  3. Offline

    Iervolino


    Thanks dude!
     
Thread Status:
Not open for further replies.

Share This Page