Ranking Plugin

Discussion in 'Plugin Development' started by AlphaBetaMC, Jul 30, 2013.

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

    AlphaBetaMC

    Hello,

    So I am making a ranking plugin where you right click a sign to rank up.

    The first rank works, but then when i right click the sign for rank #2 nothing happens.

    Here is my code:

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. Block block = event.getClickedBlock();
    5. Player player = event.getPlayer();
    6. Material mat = block.getType();
    7. boolean isSign = false;
    8. for (Material allSigns : signs) {
    9. if (allSigns.equals(mat)) {
    10. isSign = true;
    11. break;
    12. }
    13. }
    14. if (isSign == false)
    15. return;
    16. Sign sign = (Sign) block.getState();
    17. String line3 = sign.getLine(2);
    18. World world = player.getWorld();
    19. Location pl = player.getLocation();
    20. CommandSender console = this.getServer().getConsoleSender();
    21. if(line3.equalsIgnoreCase("Rank #1")){
    22. if(player.hasPermission("rank.1")){
    23. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    24. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 1, Noob.");
    25. player.sendMessage("§3You have been promoted to rank 1, Noob.");
    26. world.playEffect(pl, Effect.POTION_BREAK, 2);
    27. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    28. }else if(line3.equalsIgnoreCase("Rank #2")){
    29. if(player.hasPermission("rank.2")){
    30. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    31. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 1, Fierce Noob.");
    32. player.sendMessage("§3You have been promoted to rank 2, Fierce Noob.");
    33. world.playEffect(pl, Effect.POTION_BREAK, 2);
    34. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    35. }
    36. }else if(line3.equalsIgnoreCase("Rank #3")){
    37. if(player.hasPermission("rank.3")){
    38. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    39. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 3, Mighty Noob.");
    40. player.sendMessage("§3You have been promoted to rank 3, Mighty Noob.");
    41. world.playEffect(pl, Effect.POTION_BREAK, 2);
    42. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    43. }
    44. }else if(line3.equalsIgnoreCase("Rank #4")){
    45. if(player.hasPermission("rank.4")){
    46. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    47. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 4, Deadly Noob.");
    48. player.sendMessage("§3You have been promoted to rank 4, Deadly Noob.");
    49. world.playEffect(pl, Effect.POTION_BREAK, 2);
    50. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    51. }
    52. }else if(line3.equalsIgnoreCase("Rank #5")){
    53. if(player.hasPermission("rank.5")){
    54. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    55. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 5, Terrifying Noob.");
    56. player.sendMessage("§3You have been promoted to rank 5, Terrifying Noob.");
    57. world.playEffect(pl, Effect.POTION_BREAK, 2);
    58. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    59. }
    60. }else if(line3.equalsIgnoreCase("Rank #6")){
    61. if(player.hasPermission("rank.6")){
    62. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    63. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 6, Conquering Noob.");
    64. player.sendMessage("§3You have been promoted to rank 6, Conquering Noob.");
    65. world.playEffect(pl, Effect.POTION_BREAK, 2);
    66. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    67. }
    68. }else if(line3.equalsIgnoreCase("Rank #7")){
    69. if(player.hasPermission("rank.7")){
    70. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    71. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 7, Subjugating Noob.");
    72. player.sendMessage("§3You have been promoted to rank 7, Subjugating Noob.");
    73. world.playEffect(pl, Effect.POTION_BREAK, 2);
    74. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    75. }
    76. }else if(line3.equalsIgnoreCase("Rank #8")){
    77. if(player.hasPermission("rank.8")){
    78. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    79. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 8, Vanquishing Noob.");
    80. player.sendMessage("§3You have been promoted to rank 8, Vanquishing Noob.");
    81. world.playEffect(pl, Effect.POTION_BREAK, 2);
    82. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    83. }
    84. }else if(line3.equalsIgnoreCase("Rank #9")){
    85. if(player.hasPermission("rank.9")){
    86. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    87. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 9, Warrior.");
    88. player.sendMessage("§3You have been promoted to rank 9, Warrior.");
    89. world.playEffect(pl, Effect.POTION_BREAK, 2);
    90. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    91. }
    92. }else if(line3.equalsIgnoreCase("Rank #10")){
    93. if(player.hasPermission("rank.10")){
    94. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    95. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 10, Proven Warrior.");
    96. player.sendMessage("§3You have been promoted to rank 10, Proven Warrior.");
    97. world.playEffect(pl, Effect.POTION_BREAK, 2);
    98. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    99. }
    100. }else if(line3.equalsIgnoreCase("Rank #11")){
    101. if(player.hasPermission("rank.11")){
    102. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    103. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 11, Renowned Warrior.");
    104. player.sendMessage("§3You have been promoted to rank 11, Renowned Warrior.");
    105. world.playEffect(pl, Effect.POTION_BREAK, 2);
    106. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    107. }
    108. }else if(line3.equalsIgnoreCase("Rank #12")){
    109. if(player.hasPermission("rank.12")){
    110. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    111. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 12, Eminent Warrior.");
    112. player.sendMessage("§3You have been promoted to rank 12, Eminent Warrior.");
    113. world.playEffect(pl, Effect.POTION_BREAK, 2);
    114. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    115. }
    116. }else if(line3.equalsIgnoreCase("Rank #13")){
    117. if(player.hasPermission("rank.13")){
    118. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    119. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 13, Legendary Warrior.");
    120. player.sendMessage("§3You have been promoted to rank 13, Legendary Warrior.");
    121. world.playEffect(pl, Effect.POTION_BREAK, 2);
    122. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    123. }
    124. }else if(line3.equalsIgnoreCase("Rank #14")){
    125. if(player.hasPermission("rank.14")){
    126. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    127. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 14, Unproven Assassin.");
    128. player.sendMessage("§3You have been promoted to rank 14, Unproven Assassin.");
    129. world.playEffect(pl, Effect.POTION_BREAK, 2);
    130. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    131. }
    132. }else if(line3.equalsIgnoreCase("Rank #15")){
    133. if(player.hasPermission("rank.15")){
    134. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    135. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 15, Proven Assassin.");
    136. player.sendMessage("§3You have been promoted to rank 15, Proven Assassin.");
    137. world.playEffect(pl, Effect.POTION_BREAK, 2);
    138. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    139. }
    140. }else if(line3.equalsIgnoreCase("Rank #16")){
    141. if(player.hasPermission("rank.16")){
    142. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    143. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 16, Illustrious Assassin.");
    144. player.sendMessage("§3You have been promoted to rank 16, Illustrious Assassin.");
    145. world.playEffect(pl, Effect.POTION_BREAK, 2);
    146. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    147. }
    148. }else if(line3.equalsIgnoreCase("Rank #17")){
    149. if(player.hasPermission("rank.17")){
    150. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    151. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 17, Ultimate Assassin.");
    152. player.sendMessage("§3You have been promoted to rank 17, Ultimate Assassin.");
    153. world.playEffect(pl, Effect.POTION_BREAK, 2);
    154. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    155. }
    156. }
    157. }
    158. }
    159. }
    160.  
    161. }


    By the way, there are no errors in the console when I click the sign.

    Thanks,

    - AlphaBeta

    [BUMP]

    Really need to fix this today :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    Rocoty

    You had messed up some brackets. This is completely untested, but I think this will work:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. Block block = event.getClickedBlock();
    5. Player player = event.getPlayer();
    6. Material mat = block.getType();
    7. boolean isSign = false;
    8. for (Material allSigns : signs) {
    9. if (allSigns.equals(mat)) {
    10. isSign = true;
    11. break;
    12. }
    13. }
    14. if (isSign == false)
    15. return;
    16. Sign sign = (Sign) block.getState();
    17. String line3 = sign.getLine(2);
    18. World world = player.getWorld();
    19. Location pl = player.getLocation();
    20. CommandSender console = this.getServer().getConsoleSender();
    21. if (line3.equalsIgnoreCase("Rank #1")) {
    22. if (player.hasPermission("rank.1")) {
    23. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    24. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 1, Noob.");
    25. player.sendMessage("§3You have been promoted to rank 1, Noob.");
    26. world.playEffect(pl, Effect.POTION_BREAK, 2);
    27. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    28. }
    29. } else if (line3.equalsIgnoreCase("Rank #2")) {
    30. if (player.hasPermission("rank.2")) {
    31. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    32. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 1, Fierce Noob.");
    33. player.sendMessage("§3You have been promoted to rank 2, Fierce Noob.");
    34. world.playEffect(pl, Effect.POTION_BREAK, 2);
    35. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    36. }
    37. } else if (line3.equalsIgnoreCase("Rank #3")) {
    38. if (player.hasPermission("rank.3")) {
    39. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    40. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 3, Mighty Noob.");
    41. player.sendMessage("§3You have been promoted to rank 3, Mighty Noob.");
    42. world.playEffect(pl, Effect.POTION_BREAK, 2);
    43. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    44. }
    45. } else if (line3.equalsIgnoreCase("Rank #4")) {
    46. if (player.hasPermission("rank.4")) {
    47. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    48. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 4, Deadly Noob.");
    49. player.sendMessage("§3You have been promoted to rank 4, Deadly Noob.");
    50. world.playEffect(pl, Effect.POTION_BREAK, 2);
    51. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    52. }
    53. } else if (line3.equalsIgnoreCase("Rank #5")) {
    54. if (player.hasPermission("rank.5")) {
    55. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    56. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 5, Terrifying Noob.");
    57. player.sendMessage("§3You have been promoted to rank 5, Terrifying Noob.");
    58. world.playEffect(pl, Effect.POTION_BREAK, 2);
    59. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    60. }
    61. } else if (line3.equalsIgnoreCase("Rank #6")) {
    62. if (player.hasPermission("rank.6")) {
    63. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    64. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 6, Conquering Noob.");
    65. player.sendMessage("§3You have been promoted to rank 6, Conquering Noob.");
    66. world.playEffect(pl, Effect.POTION_BREAK, 2);
    67. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    68. }
    69. } else if (line3.equalsIgnoreCase("Rank #7")) {
    70. if (player.hasPermission("rank.7")) {
    71. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    72. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 7, Subjugating Noob.");
    73. player.sendMessage("§3You have been promoted to rank 7, Subjugating Noob.");
    74. world.playEffect(pl, Effect.POTION_BREAK, 2);
    75. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    76. }
    77. } else if (line3.equalsIgnoreCase("Rank #8")) {
    78. if (player.hasPermission("rank.8")) {
    79. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    80. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 8, Vanquishing Noob.");
    81. player.sendMessage("§3You have been promoted to rank 8, Vanquishing Noob.");
    82. world.playEffect(pl, Effect.POTION_BREAK, 2);
    83. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    84. }
    85. } else if (line3.equalsIgnoreCase("Rank #9")) {
    86. if (player.hasPermission("rank.9")) {
    87. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    88. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 9, Warrior.");
    89. player.sendMessage("§3You have been promoted to rank 9, Warrior.");
    90. world.playEffect(pl, Effect.POTION_BREAK, 2);
    91. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    92. }
    93. } else if (line3.equalsIgnoreCase("Rank #10")) {
    94. if (player.hasPermission("rank.10")) {
    95. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    96. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 10, Proven Warrior.");
    97. player.sendMessage("§3You have been promoted to rank 10, Proven Warrior.");
    98. world.playEffect(pl, Effect.POTION_BREAK, 2);
    99. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    100. }
    101. } else if (line3.equalsIgnoreCase("Rank #11")) {
    102. if (player.hasPermission("rank.11")) {
    103. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    104. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 11, Renowned Warrior.");
    105. player.sendMessage("§3You have been promoted to rank 11, Renowned Warrior.");
    106. world.playEffect(pl, Effect.POTION_BREAK, 2);
    107. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    108. }
    109. } else if (line3.equalsIgnoreCase("Rank #12")) {
    110. if (player.hasPermission("rank.12")) {
    111. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    112. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 12, Eminent Warrior.");
    113. player.sendMessage("§3You have been promoted to rank 12, Eminent Warrior.");
    114. world.playEffect(pl, Effect.POTION_BREAK, 2);
    115. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    116. }
    117. } else if (line3.equalsIgnoreCase("Rank #13")) {
    118. if (player.hasPermission("rank.13")) {
    119. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    120. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 13, Legendary Warrior.");
    121. player.sendMessage("§3You have been promoted to rank 13, Legendary Warrior.");
    122. world.playEffect(pl, Effect.POTION_BREAK, 2);
    123. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    124. }
    125. } else if (line3.equalsIgnoreCase("Rank #14")) {
    126. if (player.hasPermission("rank.14")) {
    127. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    128. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 14, Unproven Assassin.");
    129. player.sendMessage("§3You have been promoted to rank 14, Unproven Assassin.");
    130. world.playEffect(pl, Effect.POTION_BREAK, 2);
    131. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    132. }
    133. } else if (line3.equalsIgnoreCase("Rank #15")) {
    134. if (player.hasPermission("rank.15")) {
    135. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    136. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 15, Proven Assassin.");
    137. player.sendMessage("§3You have been promoted to rank 15, Proven Assassin.");
    138. world.playEffect(pl, Effect.POTION_BREAK, 2);
    139. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    140. }
    141. } else if (line3.equalsIgnoreCase("Rank #16")) {
    142. if (player.hasPermission("rank.16")) {
    143. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    144. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 16, Illustrious Assassin.");
    145. player.sendMessage("§3You have been promoted to rank 16, Illustrious Assassin.");
    146. world.playEffect(pl, Effect.POTION_BREAK, 2);
    147. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    148. }
    149. } else if (line3.equalsIgnoreCase("Rank #17")) {
    150. if (player.hasPermission("rank.17")) {
    151. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    152. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 17, Ultimate Assassin.");
    153. player.sendMessage("§3You have been promoted to rank 17, Ultimate Assassin.");
    154. world.playEffect(pl, Effect.POTION_BREAK, 2);
    155. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    156. }
    157. }
    158. }
    159. }
     
  3. Offline

    AlphaBetaMC

    Which brackets did i mess up? I'd just like to know so I can avoid this problem in the future.
     
  4. Offline

    Rocoty

    Your code:
    Code:java
    1. if (line3.equalsIgnoreCase("Rank #1")) {
    2. if (player.hasPermission("rank.1")) {
    3. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    4. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 1, Noob.");
    5. player.sendMessage("§3You have been promoted to rank 1, Noob.");
    6. world.playEffect(pl, Effect.POTION_BREAK, 2);
    7. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    8. } else if (line3.equalsIgnoreCase("Rank #2")) {

    my fix:
    Code:java
    1. if (line3.equalsIgnoreCase("Rank #1")) {
    2. if (player.hasPermission("rank.1")) {
    3. Bukkit.dispatchCommand(console, "pex promote " + player.getName());
    4. Bukkit.broadcastMessage("§b[AspireKits] §e" + player.getName() + " has been promoted to rank 1, Noob.");
    5. player.sendMessage("§3You have been promoted to rank 1, Noob.");
    6. world.playEffect(pl, Effect.POTION_BREAK, 2);
    7. world.playSound(pl, Sound.LEVEL_UP, 2, 1);
    8. } //this one
    9. } else if (line3.equalsIgnoreCase("Rank #2")) {



    Did it work, though?
     
  5. Offline

    AlphaBetaMC

    Aha, okay I see, and yes it did, thanks for the help, I will look more closely next time because to me that is a silly mistake.
     
    Rocoty likes this.
Thread Status:
Not open for further replies.

Share This Page