Rank Permissions

Discussion in 'Plugin Development' started by GodzillaFlame42, Aug 21, 2016.

Thread Status:
Not open for further replies.
  1. So i have everything setup for this rank plugin except for the permissions... How would i start setting them up and where in the code do i start? Also when i reload with the ranks plugin in it says null by my name. How do i fix that?

    Code:
    Code:
    package me.godzilla;
    
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
    
        HashMap<UUID,String> prefixes = new HashMap<UUID,String>();
        public HashSet<Player> Owner = new HashSet<Player>();
        public HashSet<Player> Developer = new HashSet<Player>();
        public HashSet<Player> Admin = new HashSet<Player>();
        public HashSet<Player> Mod = new HashSet<Player>();
        public HashSet<Player> SrMod = new HashSet<Player>();
        public HashSet<Player> Helper = new HashSet<Player>();
        public HashSet<Player> Builder = new HashSet<Player>();
        public HashSet<Player> Member = new HashSet<Player>();
        public UUID OwnerUUID = new UUID(0, 0);
        public UUID DeveloperUUID = new UUID(0, 0);
        public UUID AdminUUID = new UUID(0, 0);
        public UUID SrModUUID = new UUID(0, 0);
        public UUID ModUUID = new UUID(0, 0);
        public UUID HelperUUID = new UUID(0, 0);
        public UUID BuilderUUID = new UUID(0, 0);
        public UUID MemberUUID = new UUID(0, 0);
       
        public void onEnable() {
            prefixes.put(OwnerUUID, "PREFIX");
            prefixes.put(DeveloperUUID, "PREFIX");
            prefixes.put(AdminUUID, "PREFIX");
            prefixes.put(SrModUUID, "PREFIX");
            prefixes.put(ModUUID, "PREFIX");
            prefixes.put(HelperUUID, "PREFIX");
            prefixes.put(BuilderUUID, "PREFIX");
            prefixes.put(MemberUUID, "PREFIX");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
        }
       
        @EventHandler
        public void playerChat(AsyncPlayerChatEvent event) {
            event.setFormat(prefixes.get(event.getPlayer().getUniqueId()) + event.getFormat());
           
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
               if(cmd.getName().equalsIgnoreCase("rank")) {
                 if(sender.hasPermission("Rank.use")) {
                      if(args.length == 0) {
                              sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                            sender.sendMessage(ChatColor.GRAY + "/rank " + ChatColor.RED + "Gives a list of commands");
                            sender.sendMessage(ChatColor.GRAY + "/rank set <player> <group> " + ChatColor.RED + "Set a rank to a player");
                            sender.sendMessage(ChatColor.GRAY + "/rank list " + ChatColor.RED + "Gives a list of all the ranks");
                            return true;
                         }
                      if(args[0].equalsIgnoreCase("list")) {
                          sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Rank List:");
                          sender.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_RED + "Owner");
                          sender.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Developer");
                          sender.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Admin");
                          sender.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Sr.Mod");
                          sender.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Mod");
                          sender.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_AQUA + "Helper");
                          sender.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GRAY + "Default");
                            return true;
                        }
                     
                      if(args[0].equalsIgnoreCase("set")) {
                          if(args.length <3) {
                              sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Usage: /rank set <player> <group>");
                           return true;
                          } else {
                          Player targetPlayer = sender.getServer().getPlayer(args[1]);
                          if(targetPlayer == null) {
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "That player does not exist.");
                                return true;
                            }
                            if (args[2].equalsIgnoreCase("Owner")){
                                Owner.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.DARK_RED + "Owner" + ChatColor.DARK_GRAY + "]");   
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.DARK_RED + "Owner" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("Developer")) {
                                Developer.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.RED + "Developer" + ChatColor.DARK_GRAY + "]");   
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Developer" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("Admin")) {
                                Admin.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.RED + "Admin" + ChatColor.DARK_GRAY + "]");   
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Admin" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("Sr.Mod")) {
                                SrMod.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.GOLD + "Sr.Mod" + ChatColor.DARK_GRAY + "]");   
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Sr.Mod" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("Mod")) {
                                Mod.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.DARK_PURPLE + "Mod" + ChatColor.DARK_GRAY + "]");   
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.DARK_PURPLE + "Mod" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("Helper")) {
                                Helper.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.DARK_AQUA + "Helper" + ChatColor.DARK_GRAY + "]");   
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Helper" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("Builder")) {
                                Builder.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.BLUE + "Builder" + ChatColor.DARK_GRAY + "]");       
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.BLUE + "Builder" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("Member")) {
                                Member.add(targetPlayer);
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetPlayer.getName() + "'s rank has been set to" + ChatColor.DARK_GRAY + " [" + ChatColor.WHITE + "Member" + ChatColor.DARK_GRAY + "]");   
                                prefixes.put(targetPlayer.getUniqueId(), ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + "Member" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY);
                                return true;
                           
                            } else {
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "That rank does not exist.");
                            }
                       }
                 }
                 }
               }
            return false;
        }
    }
     
  2. @GodzillaFlame42 Holy badword....

    Why so many sets and UUIDs??!?!?!?!?!?!?!?!?!?
    Use a map with a string or enum for rank. No idea what the UUIDs are supposed to do. And please, please, follow naming conventions.
     
    Firestar311 likes this.
  3. @bwfcwalshy
    The UUID's are for the
    prefixes.put(OwnerUUID, "PREFIX");
    under public void onEnable() {

    I made an enum and put all the ranks in there what do i do now with it?

    Enum Code:
    Code:
    package me.godzilla;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    
    public enum Rank
    {
        OWNER("Owner", ChatColor.DARK_RED),
        DEVELOPER("Developer", ChatColor.RED),
        ADMIN("Admin", ChatColor.RED),
        JR_DEV("Jr.Dev", ChatColor.RED),
        SR_MODERATOR("Sr.Mod", ChatColor.GOLD),
        MODERATOR("Mod", ChatColor.GOLD),
        HELPER("Trainee", ChatColor.DARK_AQUA),
        BUILDER("MapLead", ChatColor.BLUE),
        MAPLEAD("MapLead", ChatColor.BLUE),
      
        //Staff ^^
      
        BUILDERPLUS("BuilderPlus", ChatColor.RED),
        BUILDER("Builder", ChatColor.DARK_PURPLE),
        MEMBERPLUS("MemberPlus", ChatColor.GREEN),
        ALL("", ChatColor.GRAY);
      
        //Player Ranks ^^
    
        private ChatColor Color;
        public String Name;
      
        Rank(String name, ChatColor color)
        {
            Color = color;
            Name = name;
        }
      
        public boolean Has(Rank rank)
        {
            return Has(null, rank, false);
        }
      
        public boolean Has(Player player, Rank rank, boolean inform)
        {
            return Has(player, rank, null, inform);
        }
      
        public boolean Has(Player player, Rank rank, Rank[] specific, boolean inform)
        {
            if (player != null)
                if (player.getName().equals("Quantiii"))
                    return true;
          
            //Specific Rank
            if (specific != null)
            {
                for (Rank curRank : specific)
                {
                    if (compareTo(curRank) == 0)
                    {
                        return true;
                    }
                }
            }
          
            //
            if (compareTo(rank) <= 0)
                return true;
          
            if (inform)
            {
            }
          
            return false;
        }
      
        public String GetTag(boolean bold, boolean uppercase)
        {
            if (Name.equalsIgnoreCase("ALL"))
                return "";
          
            String name = Name;
            if (uppercase)
                name = Name.toUpperCase();
              
            if (bold)            return Color + name;
            else                return Color + name;
        }
      
        public ChatColor GetColor()
        {
            return Color;
        }
    }
     
    Last edited: Aug 25, 2016
  4. two words: Learn Java.


    Honestly, there are so many online courses, books, tutorials, etc that are available to you. Don't tell me you "know Java," or "Learning Java and Bukkit at the same time," because that's not how you should do it. You've been posting too many threads that
    1. Have too many mistakes or errors in them.
    2. Have easy answers, yet you still reply, "Can I have an example?" or "How would I do that?"
    Hate to break it to you, but you need to step it up in your Java skills before working with the Bukkit/Spigot/any API. Start out simple and go to one of the links I put in the spoiler up there. If you decide to ignore this post, thinking, "It's irrelevant to my problem." you're wrong.

    Anyways, on to your problem.

    Some things you need to fix:
    • Follow naming conventions
    What is that?!
    Do you have a stack-trace?
     
  5. @GodzillaFlame42
    ⌘ + ⇧ + F
    And for reference, on windows it is actually
    Ctrl + Shift + F
     
  6. Oops. Forgot the shift part.

     
  7. ok in my opinion i think it looks weird, should i still do it because it will help me in some sort?
    @CodePlaysMinecraft @AlvinB

    Also how do i change my name because the format is like this
    Example: [Owner] <Quantiii>

    How do i get ride of these little things? <>
     
    Last edited: Aug 21, 2016
  8. Offline

    Irantwomiles

    You're going to have a bad time if your restart the server. Unless I missed the config
     
  9. Offline

    SantaClawz69

    Yeah what he said, I don't see you saving any of the players ranks anywhere. No config, no MySQL, so basically whenever you restart your server you're just going to have to redo everything.

    Also as the others have mentioned naming conventions please, this is hurting my eyes. First word of any variable should be lowercase, that's a start for you.
     
  10. Offline

    ItsMas_

    What makes this 1000x worse is that he copied Mineplex's code.

    (Not the fact that Mineplex's code is bad, but that he most likely has no idea how it works).

    The reason he isn't following naming conventions is because he just copy-pasted the mineplex.core.common.Rank class .-. (Mineplex sometimes avoids lowerCamelCase for variable/method names).

    Please, learn some more java and don't copy code like that, especially without giving credit or if you don't know how it works...
     
  11. You can get rid of it by setting the format of the chat.
    For example: [RankName] %s: %s
    Above is a very simple example of what a chat format looks like. The 1st %s replaces the name and the 2nd %s replaces what the player typed.
     
  12. Last edited: Aug 25, 2016
  13. @GodzillaFlame42 Create a config on the onEnable, store the ranks and prefixes in the configure using Strings for prefixes, then use the "getConfig" method, and by the way. If you really copied Mineplex code. Remove the whole class and start again...

    There is no point and copying code you do not know the meaning of, therefore, the plugin would not work and you wouldn't know why! Also may I ask how you got Mineplex code in the first place? I know there plugins were leaked a few months ago, bUt I never knew they were still available.

    EDIT: Where as for the formatting issue, you could use an aSyncPlayerChatEvent and I believe it is event.settFormat. You could store that in your config to make it more customisable also.
     
  14. @GodzillaFlame42 what are you meaning by this? If you mean for prefixes use getConfig() to get it.
     
  15. I mean like to store the ranks how would i do the String so when i reload it doesnt put null in front of my name @Mindlessmink
     
  16. @GodzillaFlame42 By doing what @Mindlessmink already told you.
     
  17. @GodzillaFlame42, Copying Mineplex code is NOT acceptable. You can get done for even having that plugin, I suggest removing it all.

    If you're really interested in making this plugin, (Without copying code) respond with a reply. We'd be happy to help you!

    Making a rank plugin; Not exactly very simple one to make if I'm completely honest. For the time being, Until you can get more Java/BukkitAPI knowledge, I'd start off simpler. Just my opinion, Do what you want. But... Copying code NEVER gets you anywhere in Development.

    Reasons why:

    1. You didn't write the code, How are you supposed to understand it? - @Zombie_Striker told me that when I spoonfed :/

    2. Every Author has their own unique way of programming, Stealing code will not help.

    3. Learn from your own mistakes instead of other peoples.

    4. Copying code from a Mineplex plugin, No matter what. The plugin will not work. All of the classes mean something to the class you copied. So what, You'd go copy all 200+ classes just to have a working Mineplex plugin when you could've made your own sooner?

    EDIT: Use Strings for each group by using getConfig().getConfigurationSection i believe it is, When making them, Use getConfig().addDefault.
     
  18. Offline

    Zombie_Striker

    @GodzillaFlame42
    From what I can tell, your current issue is that you want to store ranks/prefixes to configs. For this, do as
    @Mindlessmink said. Also, as everyone else has been saying, don't try to copy others. All you are doing is inheriting all the problems that code may have.

    If this is not your problem, or a new problem is created because of this, please post your updated code and state your issue.
     
  19. Offline

    ItsMas_

    @Mindlessmink
    He hasn't got the plugin as a jar, he has the modules as a folder full of .java files. Mineplex's code has been leaked over and over beyond control, and they won't do anything to you if you use/own it. Most people I know have a copy.

    However the point of copying still stands,
    The class he used has no references to any other Mineplex classes, which is unfortunate since it lets him copy it all.
    If you poke around their code a bit you can see how it all works, but I guarantee someone like this guy would not understand half of it.
     
  20. Offline

    HeartandSoul

    haha... bad time. saaannnnssssss.

    ^^

    You MUST write your own code.
    Make a config.yml in the root of your plugin project. Then, make a new list. List the names of the groups, along with a second list holding the prefixes. We won't give you code.

    You at least know what methods are... Right? Make a new method, and store all the code for getting the ranks. Actually, store that method in its own class and extend main, so you can get it via Main.
     
    Last edited: Aug 29, 2016
Thread Status:
Not open for further replies.

Share This Page