Config issues, maybe.

Discussion in 'Plugin Development' started by ColaCraft, Jun 20, 2013.

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

    ColaCraft

    Hey everyone- I'm just having an issue with this code:

    Code:java
    1. public boolean onCommand( CommandSender sender, Command cmd, String label, String[] args ){
    2. if(cmd.getName().equalsIgnoreCase("addmod")){
    3. if (!sender.hasPermission("modstick.adduser")){
    4. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission!");
    5. }else if(args[0] != null){
    6.  
    7. config.addDefault(args[0] + ".advertsing", false );
    8. config.addDefault(args[0] + ".chatviolation", false);
    9. config.addDefault(args[0] + ".spam", false);
    10. config.addDefault(args[0] + ".isOnDuty", false);
    11.  
    12. saveConfig();
    13. reloadConfig();
    14.  
    15. sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.RED + args[0] + ChatColor.GREEN + " has been added as a mod!");
    16.  
    17. }
    18. return true;
    19. }
    20. if(cmd.getName().equalsIgnoreCase("remmod")){
    21.  
    22. if(!sender.hasPermission("modstick.remmod")){
    23. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission!");
    24. }else if (config.contains(args[0])){
    25. config.set(args[0], null);
    26. sender.sendMessage(ChatColor.DARK_RED + "Player " + ChatColor.GREEN + args[0] + ChatColor.DARK_RED + " has been removed as a moderator!");
    27. saveConfig();
    28. }else if(!config.contains(args[0])){
    29. sender.sendMessage(ChatColor.DARK_RED + "ERROR: That user is not a Moderator!");
    30. }
    31. return true;
    32. }
    33. if(cmd.getName().equalsIgnoreCase("toggleonduty")){
    34. if(!sender.hasPermission("modstick.toggleonduty")){
    35. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission!");
    36. }else if(config.getBoolean(sender + ".isOnDuty") == true){
    37. config.set(sender + ".isOnDuty", false);
    38. saveConfig();
    39. sender.sendMessage(ChatColor.RED + "You're no longer on duty");
    40. }else if(config.getBoolean(sender + ".isOnDuty") == false){
    41. config.set(sender + ".isOnDuty", true);
    42. saveConfig();
    43. sender.sendMessage(ChatColor.GREEN + "You're now on duty!");
    44. }else if(!config.contains(sender + ".isOnDuty")){
    45. sender.sendMessage(ChatColor.DARK_RED + "ERROR: You're not listed as a moderator in the database!");
    46. }else{
    47. sender.sendMessage(ChatColor.DARK_RED + "ERROR: An unknown error has occured");
    48. }
    49. return true;
    50. }
    51. return true;
    52. }
    53.  



    Normally, this wouldn't be an issue, but this seems to be broken.

    I can type /addmod & it works perfect.
    I can type /remmod & it's the same sort of deal.

    When I type /toggleonduty, it comes up with "You're not listed as a mod in our database!", even though I can see the user is listed in the config.

    Don't worry about the brackets, I had to delete some code of the post, so they may not be exact.

    Thanks!
     
  2. Offline

    caseif

    When you're having issues with if blocks, brackets are everything. They have to match up if we're to help you. Please don't blow them off like that.

    sender represents your CommandSender. You want to replace that with sender.getName() to actually get the sender's username.
     
    ColaCraft likes this.
  3. Offline

    ColaCraft


    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page