Command is shown after the command is performend

Discussion in 'Plugin Development' started by gaz1812, May 23, 2014.

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

    gaz1812

    Not sure if the title made sense but basically what is happening is when a user types /gmc it will turn them into creative mode and also say "/gmc". The below is my code:
    Code:java
    1. //if the command is /gmc
    2. if (cmd.getName().equalsIgnoreCase("gmc")){
    3. if(player.hasPermission("mortality.gmc")) {
    4. player.setGameMode(GameMode.CREATIVE);
    5. player.sendMessage(ChatColor.RED + "You are now in gamemode: " + ChatColor.YELLOW + "creative.");
    6. }
    7. } else {
    8. player.sendMessage(ChatColor.RED + "You can't do this.");
    9. }
    10. }
    11.  


    The screenshot:
    [​IMG]
     
  2. Offline

    Charmax

    Code:java
    1. //if the command is /gmc
    2. if (cmd.getName().equalsIgnoreCase("gmc")){
    3. if(player.hasPermission("mortality.gmc")) {
    4. player.setGameMode(GameMode.CREATIVE);
    5. player.sendMessage(ChatColor.RED + "You are now in gamemode: " + ChatColor.YELLOW + "creative.");
    6. return true;
    7. }
    8. } else {
    9. player.sendMessage(ChatColor.RED + "You can't do this.");
    10. return true;
    11. }
    12. }


    As stated above you need to return true.
     
  3. Offline

    gaz1812

    CaptainBern Thanks! Also by any chance do you know why I keep receiving the permission error message when I have permission for the commands? The creative command works fine but then with survival and adventure mode it keeps printing out the message which I set player.sendMessage(ChatColor.RED + "You can't do this."); if you don't have permission.

    Code:java
    1. //if the command is /gmc
    2. if (cmd.getName().equalsIgnoreCase("gmc")){
    3. if(player.hasPermission("mortality.gmc")) {
    4. player.setGameMode(GameMode.CREATIVE);
    5. player.sendMessage(ChatColor.RED + "You are now in gamemode: " + ChatColor.YELLOW + "CREATIVE.");
    6. }
    7. } else {
    8. player.sendMessage(ChatColor.RED + "You can't do this.");
    9. return true;
    10. }
    11.  
    12.  
    13. //if the command is /gms
    14. if (cmd.getName().equalsIgnoreCase("gms")){
    15. if(player.hasPermission("mortality.gms")) {
    16. player.setGameMode(GameMode.SURVIVAL);
    17. player.sendMessage(ChatColor.RED + "You are now in gamemode: " + ChatColor.YELLOW + "CREATIVE.");
    18. }
    19. } else {
    20. player.sendMessage(ChatColor.RED + "You can't do this.");
    21. return true;
    22. }
     
  4. Offline

    techboy291

    If the command doesn't equal gmc at the beginning of your code, then the else runs, which prints "You can't do this." in red and then returns true, exiting the method before your gms command runs. I don't think he meant for you to do it in an else statement.
     
  5. Offline

    aFreshKiwi

    Change this
    Code:java
    1. else {
    2. player.sendMessage(ChatColor.RED + "You can't do this.");
    3. return true;
    4. }

    To this

    Code:java
    1.  
    2.  
    3. else if (!player.hasPermission("mortatility.gmc"))
    4. {
    5. player.sendMessage(ChatColor.RED + "You can't do this.");
    6. return true;
    7. }
     
  6. Offline

    RainoBoy97

    gaz1812
    Your brackets are messed up.
     
  7. Offline

    gaz1812

  8. Offline

    Garris0n

  9. Offline

    gaz1812

    Garris0n Thanks will do from now on!
     
Thread Status:
Not open for further replies.

Share This Page