Enum Rank System - Minimum Rank

Discussion in 'Plugin Development' started by Jamscott, Dec 24, 2014.

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

    Jamscott

    I have been making a custom rank system for my server.
    When I running command I want to set a minimal rank for example
    1 - Owner
    2 - Admin
    3 - Moderator
    4 - Helper
    5 - Legend
    6 - Elite
    7 - Default

    A command has a minimum rank of Helper meaning only players which are (Helper,Mod,Admin,Owner) can run the command.

    How would I do this?

    BTW I save players ranks into a HashMap

    Rank - Class

    Code:
    import org.bukkit.ChatColor;
    
    public enum Rank
    {
      OWNER("Owner", ChatColor.DARK_RED, true),
      ADMIN("Admin", ChatColor.RED, true),
      MODERATOR("Mod", ChatColor.GREEN, true),
      HELPER("Helper", ChatColor.BLUE , true),
      LEGEND("Legend", ChatColor.GREEN, false),
      ELITE("Elite", ChatColor.AQUA, false),
      DEFAULT("Default", ChatColor.WHITE, false);
    
      private ChatColor Color;
      public String Name;
      public boolean IsStaff;
    
      private Rank(String name, ChatColor color, Boolean IsStaff)
      {
        this.Color = color;
        this.Name = name;
        this.IsStaff = IsStaff;
      }
    
      public String GetTag(boolean bold, boolean uppercase)
      {
        String name = this.Name;
        if (uppercase) {
          name = this.Name.toUpperCase();
        }
        if (bold) return this.Color + C.Bold + name;
        return this.Color + name;
      }
    
      public boolean IsStaff(Rank rank){
          return this.IsStaff;
      }
    }
     
  2. Offline

    teej107

    Well it looks like you sorted your ranks from highest - lowest. If you want to customize the rank numbers, save it in the enum OR you can use Enum#ordinal() since your enum listings are in order.
     
  3. Offline

    Freack100

    you could write a method in your enum that takes another Rank value and does kinda this:
    Code:
    public boolean has(Rank rank){
      return (compareTo(rank) <= 0);
    }
     
  4. Offline

    __Sour

    @Jamscott
    Did you just take that rank code from mineplex rankings system and edited the names of the ranks? I think you would need there permission to use that code.
     
  5. Offline

    Jamscott

    @__Sour Yes I did copy the code and changed it I will admit to that. Im not using this code shown above because I'm currently learning java and I noticed a GitHub page for the mineplex rank system and I wanted to learn how i could do this my self so I copied the code and changed it a little so it doesn't cause an argument.
    I respect the developers/Owners at minplex, They are great people and I wouldn't copy there code for my own

    Sorry for my poor Grammar.
     
  6. Offline

    Konato_K

    @Jamscott With respect to Mineplex developers, their code is bad.
     
  7. Offline

    __Sour

    @Konato_K @Jamscott Lol Mineplex... I really don't know why they needed to use all the static :p
     
  8. Offline

    nverdier

    They didn't. They just don't know what the hell an instance is.
     
    teej107 likes this.
Thread Status:
Not open for further replies.

Share This Page