Prison Prestige

Discussion in 'Plugin Development' started by MrConHD, Nov 30, 2014.

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

    MrConHD

    So I have recently been asked to create a plugin that would 'prestige' a player if they had a certain permission. When the user executed this command, it would remove the 'Free' PEX Rank and set him back to 'A.' I was doing this with Vault, as that is what others were telling me. When I actually do the /prestige command, this is the error that comes up:

    Code:
     at me.MrConHD.Prestiges.Core.playerRemoveGroup(Core.java:51) ~[?:?]
    That is spammed through the entire console.

    Here is line 51:


    Code:java
    1. public boolean playerRemoveGroup(Player player, String Free) {
    2. return playerRemoveGroup(player, "Free");
    3. }


    Entire Class:

    Code:java
    1. package me.MrConHD.Prestiges;
    2.  
    3. import net.milkbowl.vault.permission.Permission;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.OfflinePlayer;
    8. import org.bukkit.Server;
    9. import org.bukkit.World;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.plugin.RegisteredServiceProvider;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Core extends JavaPlugin {
    17.  
    18. public void onEnable() {
    19. Bukkit.getServer().getLogger().info(ChatColor.GREEN + "PrisonPrestige has been enabled! - Developed by MrConHD");
    20. }
    21.  
    22. public void onDisable() {
    23. Bukkit.getServer().getLogger().info(ChatColor.GREEN + "PrisonPrestige has been disabled! - Developed by MrConHD");
    24. }
    25.  
    26. public static Permission permission = null;
    27.  
    28. private boolean setupPermissions()
    29. {
    30. RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    31. if (permissionProvider != null) {
    32. permission = permissionProvider.getProvider();
    33. }
    34. return (permission != null);
    35. }
    36.  
    37. public boolean playerAddGroup(Player player, String A) {
    38. return playerAddGroup(player, "A");
    39. }
    40.  
    41. public boolean playerRemoveGroup(Player player, String Free) {
    42. return playerRemoveGroup(player, "Free");
    43. }
    44.  
    45.  
    46. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    47. if (cmd.getName().equalsIgnoreCase("Prestige")) {
    48. if (sender.hasPermission("prison.prestige1")) {
    49. if (sender instanceof Player) {
    50. Player player = (Player) sender;
    51. player.getWorld().getName();
    52. playerRemoveGroup(player, "Free");
    53. playerAddGroup(player, "A");
    54. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    55.  
    56. }
    57. else {
    58. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    59. return false;
    60. }
    61.  
    62. }
    63. else {
    64.  
    65. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    66. return false;
    67. }
    68. if (sender.hasPermission("prison.prestige2")) {
    69. if (sender instanceof Player) {
    70. Player player = (Player) sender;
    71. player.getWorld().getName();
    72. playerRemoveGroup(player, "Free");
    73. playerAddGroup(player, "A");
    74. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    75. }
    76. else {
    77. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    78. return false;
    79. }
    80. }
    81. else {
    82.  
    83. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    84. return false;
    85. }
    86. if (sender.hasPermission("prison.prestige3")) {
    87. if (sender instanceof Player) {
    88. Player player = (Player) sender;
    89. player.getWorld().getName();
    90. playerRemoveGroup(player, "Free");
    91. playerAddGroup(player, "A");
    92. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    93.  
    94. }
    95. else {
    96. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    97. return false;
    98. }
    99. }
    100. else {
    101. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    102. }
    103.  
    104. if (sender.hasPermission("prison.prestige4")) {
    105. if (sender instanceof Player) {
    106. Player player = (Player) sender;
    107. player.getWorld().getName();
    108. playerRemoveGroup(player, "Free");
    109. playerAddGroup(player, "A");
    110. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    111.  
    112. }
    113. else {
    114. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    115. return false;
    116. }
    117.  
    118. }
    119. else {
    120. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    121. return false;
    122. }
    123.  
    124. if (sender.hasPermission("prison.prestige5")) {
    125. if (sender instanceof Player) {
    126. Player player = (Player) sender;
    127. player.getWorld().getName();
    128. playerRemoveGroup(player, "Free");
    129. playerAddGroup(player, "A");
    130. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    131.  
    132. }
    133. else {
    134. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    135. return false;
    136. }
    137. }
    138. else {
    139. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    140. return false;
    141. }
    142.  
    143. if (sender.hasPermission("prison.prestige6")) {
    144. if (sender instanceof Player) {
    145. Player player = (Player) sender;
    146. player.getWorld().getName();
    147. playerRemoveGroup(player, "Free");
    148. playerAddGroup(player, "A");
    149. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    150.  
    151. }
    152. else {
    153. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    154. return false;
    155. }
    156. }
    157. else {
    158. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    159. return false;
    160. }
    161.  
    162. if (sender.hasPermission("prison.prestige7")) {
    163. if (sender instanceof Player) {
    164. Player player = (Player) sender;
    165. player.getWorld().getName();
    166. playerRemoveGroup(player, "Free");
    167. playerAddGroup(player, "A");
    168. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    169. }
    170. else {
    171.  
    172. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    173. return false;
    174. }
    175.  
    176. }
    177. else {
    178. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    179. return false;
    180. }
    181. if (sender.hasPermission("prison.prestige8")) {
    182. if (sender instanceof Player) {
    183. Player player = (Player) sender;
    184. player.getWorld().getName();
    185. playerRemoveGroup(player, "Free");
    186. playerAddGroup(player, "A");
    187. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    188.  
    189. }
    190. else {
    191. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    192. return false;
    193. }
    194. }
    195. else {
    196. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    197. return false;
    198. }
    199. if (sender.hasPermission("prison.prestige9")) {
    200. if (sender instanceof Player) {
    201. Player player = (Player) sender;
    202. player.getWorld().getName();
    203. playerRemoveGroup(player, "Free");
    204. playerAddGroup(player, "A");
    205. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    206.  
    207. }
    208. else {
    209. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    210. return false;
    211. }
    212.  
    213. }
    214. else {
    215. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    216. return false;
    217. }
    218. if (sender.hasPermission("prison.prestige10")) {
    219. if (sender instanceof Player) {
    220. Player player = (Player) sender;
    221. player.getWorld().getName();
    222. playerRemoveGroup(player, "Free");
    223. playerAddGroup(player, "A");
    224. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&cPrestige&8] &3You have successfully prestiged!"));
    225.  
    226. }
    227. else {
    228. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + " You must be a player to execute this command!");
    229. return false;
    230. }
    231.  
    232. }
    233. else {
    234. sender.sendMessage(ChatColor.DARK_RED.toString() + ChatColor.BOLD + "ERROR: " + ChatColor.RESET + ChatColor.RED + "You are not the required rank to Prestige!");
    235. return false;
    236. }
    237.  
    238. }
    239. return true;
    240. }
    241. }
    242.  
     
  2. Offline

    HeadGam3z

    Never called setupPermissions().
     
  3. Offline

    Totom3

    MrConHD
    Code:java
    1. public boolean playerRemoveGroup(Player player, String Free) {
    2. return playerRemoveGroup(player, "Free"); // This line re-calls the method
    3. }

    This method will call itself infinitely, until a StackOverflowError is thrown because the JVM can't store the stack anymore. Same for playerAddGroup(). There is no other way of fixing this except making sure the method will not call itself infinitely.
     
  4. Offline

    mine-care

    Totom3 is right, you are calling the same method over and over... If you are trying to do recursion, you need the method to process something not endlessly call itself....
     
    yewtree8 likes this.
  5. Offline

    yewtree8

    Recursion = not good.
     
  6. Offline

    mine-care

    yewtree8 recursion can be good when used correctly, when it is used the wrong way it may cause ram leaks, stack overflows and generally many headaches
     
Thread Status:
Not open for further replies.

Share This Page