Solved Loop through config file to return integer

Discussion in 'Plugin Development' started by elementalgodz11, Apr 12, 2014.

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

    elementalgodz11

    I am returning an integer value by manually checking using else if statements, this code would be easier to modifier and less dependant on the code if I use a for loop:

    However I do not know what I would do in this case, I have tried getting the keys,

    Here is what I'm doing now (and the only thing I'm changing is the rank just after "Server.Groups."):
    Code:java
    1. public int getMaxWarps(Player player) {
    2.  
    3. Integer warpAmount = 0;
    4.  
    5. if (plugin.betterPlayer.isDefault(player)) {
    6.  
    7. warpAmount = plugin.getConfig().getInt("Server.Groups.Default.MaxWarps");
    8.  
    9. } else if (plugin.betterPlayer.isVip(player)) {
    10.  
    11. warpAmount = plugin.getConfig().getInt("Server.Groups.VIP.MaxWarps");
    12.  
    13. } else if (plugin.betterPlayer.isMvp(player)) {
    14.  
    15. warpAmount = plugin.getConfig().getInt("Server.Groups.MVP.MaxWarps");
    16.  
    17. } else if (plugin.betterPlayer.isPro(player)) {
    18.  
    19. warpAmount = plugin.getConfig().getInt("Server.Groups.PRO.MaxWarps");
    20.  
    21. } else if (plugin.betterPlayer.isMod(player)) {
    22.  
    23. warpAmount = plugin.getConfig().getInt("Server.Groups.MODERATOR.MaxWarps");
    24.  
    25. } else if (plugin.betterPlayer.isAdmin(player)) {
    26.  
    27. warpAmount = plugin.getConfig().getInt("Server.Groups.ADMIN.MaxWarps");
    28.  
    29. } else if (plugin.betterPlayer.isOwner(player)) {
    30.  
    31. warpAmount = plugin.getConfig().getInt("Server.Groups.OWNER.MaxWarps");
    32.  
    33. } else {
    34.  
    35. warpAmount = 0;
    36.  
    37. }
    38.  
    39. return warpAmount;
    40.  
    41. }
     
  2. Offline

    St3venAU

    I'm not sure what class betterPlayer is, but does it possibly have a getGroup(player) method or something similar that returns a string? If it does and the group names match the names in your config you could use that method to get their group and then just do a single line:
    Code:java
    1. warpAmount = plugin.getConfig().getInt("Server.Groups."+group+".MaxWarps");
     
    elementalgodz11 likes this.
Thread Status:
Not open for further replies.

Share This Page