Solved [Help] .hasPermission problem

Discussion in 'Plugin Development' started by Cheesepro, Oct 18, 2014.

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

    Cheesepro

    So I was adding a chat formatting feature to my server/plugin and when I debugs it, it displayed that Bukkit went into every if statement even when it is not true, so if you know where I got wrong, please help me :D thank you.

    Code:
    Code:java
    1. if (p.hasPermission("CheeseEss.chat.player")) {
    2. String playerprefix = plugin.getConfig().getString("chat_format.group_prefix.player");
    3. playerprefix = playerprefix.replaceAll("&", "§");
    4. String playername = plugin.getConfig().getString("chat_format.group_name_color.player");
    5. playername = playername.replaceAll("&", "§");
    6. String playerchat = plugin.getConfig().getString("chat_format.group_chat_color.player");
    7. playerchat = playerchat.replaceAll("&", "§");
    8. String playerchatsign = plugin.getConfig().getString("chat_format.group_chatsign.player");
    9. playerchatsign = playerchatsign.replaceAll("&", "§");
    10. e.setFormat(playerprefix + playername + "%s" + playerchatsign + playerchat + "%s");
    11. }
    12. if (p.hasPermission("CheeseEss.chat.helper")) {
    13. String helperprefix = plugin.getConfig().getString("chat_format.group_prefix.helper");
    14. helperprefix = helperprefix.replaceAll("&", "§");
    15. String helpername = plugin.getConfig().getString("chat_format.group_name_color.helper");
    16. helpername = helpername.replaceAll("&", "§");
    17. String helperchat = plugin.getConfig().getString("chat_format.group_chat_color.helper");
    18. helperchat = helperchat.replaceAll("&", "§");
    19. String helperchatsign = plugin.getConfig().getString("chat_format.group_chatsign.helper");
    20. helperchatsign = helperchatsign.replaceAll("&", "§");
    21. e.setFormat(helperprefix + " " + helpername + "%s" + helperchatsign + helperchat + "%s");
    22. }
    23. if (p.hasPermission("CheeseEss.chat.builder")) {
    24. String builderprefix = plugin.getConfig().getString("chat_format.group_prefix.builder");
    25. builderprefix = builderprefix.replaceAll("&", "§");
    26. String buildername = plugin.getConfig().getString("chat_format.group_name_color.builder");
    27. buildername = buildername.replaceAll("&", "§");
    28. String builderchat = plugin.getConfig().getString("chat_format.group_chat_color.builder");
    29. builderchat = builderchat.replaceAll("&", "§");
    30. String builderchatsign = plugin.getConfig().getString("chat_format.group_chatsign.builder");
    31. builderchatsign = builderchatsign.replaceAll("&", "§");
    32. e.setFormat(builderprefix + " " + buildername + "%s" + builderchatsign + builderchat + "%s");
    33. }
    34. if (p.hasPermission("CheeseEss.chat.mod")) {
    35. String modprefix = plugin.getConfig().getString("chat_format.group_prefix.mod");
    36. modprefix = modprefix.replaceAll("&", "§");
    37. String modname = plugin.getConfig().getString("chat_format.group_name_color.mod");
    38. modname = modname.replaceAll("&", "§");
    39. String modchat = plugin.getConfig().getString("chat_format.group_chat_color.mod");
    40. modchat = modchat.replaceAll("&", "§");
    41. String modchatsign = plugin.getConfig().getString("chat_format.group_chatsign.mod");
    42. modchatsign = modchatsign.replaceAll("&", "§");
    43. e.setFormat(modprefix + " " + modname + "%s" + modchatsign + modchat + "%s");
    44. }
    45. if (p.hasPermission("CheeseEss.chat.admin")) {
    46. String adminprefix = plugin.getConfig().getString("chat_format.group_prefix.admin");
    47. adminprefix = adminprefix.replaceAll("&", "§");
    48. String adminname = plugin.getConfig().getString("chat_format.group_name_color.admin");
    49. adminname = adminname.replaceAll("&", "§");
    50. String adminchat = plugin.getConfig().getString("chat_format.group_chat_color.admin");
    51. adminchat = adminchat.replaceAll("&", "§");
    52. String adminchatsign = plugin.getConfig().getString("chat_format.group_chatsign.admin");
    53. adminchatsign = adminchatsign.replaceAll("&", "§");
    54. e.setFormat(adminprefix + " " + adminname + "%s" + adminchatsign + adminchat + "%s");
    55. }
    56. if (p.hasPermission("CheeseEss.chat.owner")) {
    57. String ownerprefix = plugin.getConfig().getString("chat_format.group_prefix.owner");
    58. ownerprefix = ownerprefix.replaceAll("&", "§");
    59. String ownername = plugin.getConfig().getString("chat_format.group_name_color.owner");
    60. ownername = ownername.replaceAll("&", "§");
    61. String ownerchat = plugin.getConfig().getString("chat_format.group_chat_color.owner");
    62. ownerchat = ownerchat.replaceAll("&", "§");
    63. String ownerchatsign = plugin.getConfig().getString("chat_format.group_chatsign.owner");
    64. ownerchatsign = ownerchatsign.replaceAll("&", "§");
    65. e.setFormat(ownerprefix + " " + ownername + "%s" + ownerchatsign + ownerchat + "%s");
    66. }
     
  2. Offline

    Gamecube762

    By default every permission is True for everyone unless set otherwise. Add your permission nodes to your plugin.yml and set the default for them(true, false, OP).
     
  3. Offline

    Cheesepro

  4. Offline

    FerusGrim

    If I may...

    Code:java
    1. String permPar = "CheeseEss.chat."
    2. String rankStr = "";
    3. if (p.hasPermission(permPar + "player")) {
    4. rankStr = "player";
    5. } else if (p.hasPermission(permPar + "helper")) {
    6. rankStr = "helper";
    7. } else if (p.hasPermission(permPar + "builder")) {
    8. rankStr = "builder";
    9. } else if (p.hasPermission(permPar = "mod")) {
    10. rankStr = "mod";
    11. } else if (p.hasPermission(permPar = "admin")) {
    12. rankStr = "admin";
    13. } else if (p.hasPermission(permPar = "owner")) {
    14. rankStr = "owner";
    15. }
    16.  
    17. if (!rankStr.isEmpty()) {
    18. String prefix = plugin.getConfig().getString("chat_format.group_prefix." + rankStr).replaceAll("&", "§");
    19. String name = plugin.getConfig().getString("chat_format.group_name_color." + rankStr).replaceAll("&", "§");
    20. String chat = plugin.getConfig().getString("chat_format.group_chat_color." + rankStr).replaceAll("&", "§");
    21. String sign = plugin.getConfig().getString("chat_format.group_chatsign." + rankStr).replaceAll("&", "§");
    22. e.setFormat(prefix + " " + name + " " + "%s" + sign + chat + "%s");
    23. }


    I'm sure there are even better ways to optimize that, but the above is definitely much better than what you're using, now. :p
     
  5. Offline

    Cheesepro

    FerusGrim Thanks this would actually optimize my plugin a lot, since there are less variables :D and it is easier for other people to read :D Thank you
     
Thread Status:
Not open for further replies.

Share This Page