Rank Plugin

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

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

    GodzillaFlame42

    so i am coding a ranks plugin and when i type /rank list it doesnt do anything and there are no errors in the console.

    Code:
    Code:
    package me.godzilla;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        public void onEnable() {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("rank")){
                Player player = (Player) sender;
                if(player.hasPermission("Rank.Help")) {
                    if (args.length == 0){
                    player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                    player.sendMessage(ChatColor.GRAY + "/rank " + ChatColor.RED + "Gives a list of commands");
                    player.sendMessage(ChatColor.GRAY + "/rank set <player> <group> " + ChatColor.RED + "Set a rank to a player");
                    player.sendMessage(ChatColor.GRAY + "/ranks " + ChatColor.RED + "Gives a list of all the ranks");
                    }else if (args[0].equalsIgnoreCase("set")){
                        if (args.length == 1){
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Usage: /rank set <player> <group>");
                        if (args.length == 2){
                            player = player.getServer().getPlayer(args[0]);
                            Player targetplayer = player.getServer().getPlayer(args[0]);
                    }else if (args[0].equalsIgnoreCase("list")){
                        if (args.length == 3) {
                        player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_RED + "Owner");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Developer");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Admin");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Sr.Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_AQUA + "Helper");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GRAY + "Default");
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
    }
     
  2. Offline

    Zombie_Striker

    Don't blidnly cast player. You are not checking if the sender is a player, so you do not know if it actually is a player. Do an instanceof check before casting.

    This requires there to be three args. Since you are only getting the first arg, the if statement it not needed.
     
  3. Offline

    FabeGabeMC

    @GodzillaFlame42
    Code:java
    1. if (args.length == 2){
    2. player = player.getServer().getPlayer(args[0]);
    3. Player targetplayer = player.getServer().getPlayer(args[0]);
    4. } // <--- You forgot this curly bracket here.


    And also,
    and ending brace for that if statement is unnecessary.

    @Zombie_Striker
    I agree, that was one of his problems, though not the critical one that didn't run his code.
    Nice catch, anyways. ;)
     
  4. Offline

    GodzillaFlame42

    @FabeGabeMC @Zombie_Striker It still isnt working when i type the command /rank list

    Code:
    package me.godzilla;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        public void onEnable() {
          
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("rank")){
                if(sender instanceof Player) {
                Player player = (Player) sender;
                if(player.hasPermission("Rank.Help")) {
                    if (args.length == 0){
                    player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                    player.sendMessage(ChatColor.GRAY + "/rank " + ChatColor.RED + "Gives a list of commands");
                    player.sendMessage(ChatColor.GRAY + "/rank set <player> <group> " + ChatColor.RED + "Set a rank to a player");
                    player.sendMessage(ChatColor.GRAY + "/ranks " + ChatColor.RED + "Gives a list of all the ranks");
                    }else if (args[0].equalsIgnoreCase("set")){
                        if (args.length == 1){
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Usage: /rank set <player> <group>");
                        if (args.length == 2){
                            player = player.getServer().getPlayer(args[0]);
                            Player targetplayer = player.getServer().getPlayer(args[0]);
                            }
                    }else if (args[0].equalsIgnoreCase("list")){
                        if (args.length == 3)
                        player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_RED + "Owner");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Developer");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Admin");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Sr.Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_AQUA + "Helper");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GRAY + "Default");
                                }
                            }
                        }
                    }
                }
            return false;
            }
        }
    Plugin.yml

    name: IncidiousRanks
    main: me.godzilla.Main
    version: 1.0

    commands:
    rank:
    description: Main Command.
    create:
    description: Set the players rank.
    usage: /rank set <player>
    create:
    description: List all the ranks
    usage: /rank list
     
  5. Offline

    Zombie_Striker

    @GodzillaFlame42
    Bracket mismatch: You frogto the else statement for the the line:
    1. if (args.length == 1){
    2. player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Usage: /rank set <player> <group>");
      if (args.length == 2){
      player = player.getServer().getPlayer(args[0]);

     
  6. Offline

    FabeGabeMC

    remove that from:
    also,
    missing curly bracket {
     
  7. Offline

    GodzillaFlame42

    @FabeGabeMC @Zombie_Striker Still not working for me... Sorry if im being newby about this problem that i am having i and i really appreciate you guys helping me

    Code:
    package me.godzilla;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        public void onEnable() {
        
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("rank")){
                if(sender instanceof Player) {
                Player player = (Player) sender;
                if(player.hasPermission("Rank.Help")) {
                    if (args.length == 0){
                    player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                    player.sendMessage(ChatColor.GRAY + "/rank " + ChatColor.RED + "Gives a list of commands");
                    player.sendMessage(ChatColor.GRAY + "/rank set <player> <group> " + ChatColor.RED + "Set a rank to a player");
                    player.sendMessage(ChatColor.GRAY + "/ranks " + ChatColor.RED + "Gives a list of all the ranks");
                    if (args[0].equalsIgnoreCase("set")){
                        if (args.length == 1){
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Usage: /rank set <player> <group>");
                        if (args.length == 2){
                            player = player.getServer().getPlayer(args[0]);
                            Player targetplayer = player.getServer().getPlayer(args[0]);
                            }
                    }else if (args[0].equalsIgnoreCase("list")){
                        if (args.length == 3){
                        player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_RED + "Owner");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Developer");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Admin");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Sr.Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_AQUA + "Helper");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GRAY + "Default");
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
    }
     
  8. Offline

    Zombie_Striker

    Change this to:
     
  9. Offline

    GodzillaFlame42

    @Zombie_Striker It still doesn't work and there is no error in console :/
     
  10. Offline

    FabeGabeMC

    @GodzillaFlame42
    add this:
    Code:java
    1. return;
    2. }

    after this:
    AND

    add this:
    Code:java
    1. } else if

    before:
    Code:java
    1. if(args.length == 2) {
     
  11. Offline

    GodzillaFlame42

    @FabeGabeMC @Zombie_Striker There is an error at return; when i do that and it does not still work. Im pretty sure i did everything you told me to do correctly.

    Code:
    Code:
    package me.godzilla;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        public void onEnable() {
       
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("rank")){
                if(sender instanceof Player) {
                Player player = (Player) sender;
                if(player.hasPermission("Rank.Help")) {
                    if (args.length == 0){
                    player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                    player.sendMessage(ChatColor.GRAY + "/rank " + ChatColor.RED + "Gives a list of commands");
                    player.sendMessage(ChatColor.GRAY + "/rank set <player> <group> " + ChatColor.RED + "Set a rank to a player");
                    player.sendMessage(ChatColor.GRAY + "/rank list " + ChatColor.RED + "Gives a list of all the ranks");
                    if (args[0].equalsIgnoreCase("set")){
                        if (args.length == 1){
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Usage: /rank set <player> <group>");
                    }else if (args.length == 2){
                            player = player.getServer().getPlayer(args[0]);
                            Player targetplayer = player.getServer().getPlayer(args[0]);
                            }
                    }else if (args[0].equalsIgnoreCase("list")){
                        if (args.length == 3){
                        player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_RED + "Owner");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Developer");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Admin");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Sr.Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_AQUA + "Helper");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GRAY + "Default");
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
    }
     
  12. Offline

    FabeGabeMC

  13. Offline

    GodzillaFlame42

    @FabeGabeMC @Zombie_Striker
    here is the code and i tried to make the groups so when you do /rank set <player> Owner it would say like you have set this player to owner but the message and nothing will show up. How do i fix that? and the /rank list will still not work :/

    Code:
    Code:
    package me.godzilla;
    
    import java.util.HashSet;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        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> Member = new HashSet<Player>();
       
        public void onEnable() {
       
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("rank")){
                if(sender instanceof Player) {
                Player player = (Player) sender;
                if(player.hasPermission("Rank.Help")) {
                    if (args.length == 0){
                    player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                    player.sendMessage(ChatColor.GRAY + "/rank " + ChatColor.RED + "Gives a list of commands");
                    player.sendMessage(ChatColor.GRAY + "/rank set <player> <group> " + ChatColor.RED + "Set a rank to a player");
                    player.sendMessage(ChatColor.GRAY + "/rank list " + ChatColor.RED + "Gives a list of all the ranks");
                    return true;
                    }
                    if (args[0].equalsIgnoreCase("set")){
                        if (args.length == 1){
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Usage: /rank set <player> <group>");
                    }else if (args.length == 2){
                            player = player.getServer().getPlayer(args[0]);
                            Player targetplayer = player.getServer().getPlayer(args[0]);
                            }
                    }else if (args[0].equalsIgnoreCase("list")){
                        if (args.length == 3){
                        player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Command List:");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_RED + "Owner");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Developer");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.RED + "Admin");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Sr.Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GOLD + "Mod");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.DARK_AQUA + "Helper");
                        player.sendMessage(ChatColor.DARK_GRAY + "» " + ChatColor.GRAY + "Default");
                        Player targetplayer = player.getServer().getPlayer(args[0]);
                        if (args[1] == "Owner"){
                            Owner.add(targetplayer);
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetplayer.getName() + "'s rank has been set to [" + ChatColor.DARK_RED + "Owner" + ChatColor.GRAY + "].");    
                            }
                        if (args[1] == "Developer") {
                            Developer.add(targetplayer);
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetplayer.getName() + "'s rank has been set to [" + ChatColor.RED + "Developer" + ChatColor.GRAY + "].");
                            }
                        if (args[1] == "Admin") {
                            Admin.add(targetplayer);
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetplayer.getName() + "'s rank has been set to [" + ChatColor.RED + "Admin" + ChatColor.GRAY + "].");
                            }
                        if (args[1] == "SrMod") {
                            SrMod.add(targetplayer);
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetplayer.getName() + "'s rank has been set to [" + ChatColor.GOLD + "Sr.Mod" + ChatColor.GRAY + "].");   
                            }
                        if (args[1] == "Mod") {
                            Mod.add(targetplayer);
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetplayer.getName() + "'s rank has been set to [" + ChatColor.DARK_PURPLE + "Mod" + ChatColor.GRAY + "].");   
                            }
                        if (args[1] == "Helper") {
                            Helper.add(targetplayer);
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetplayer.getName() + "'s rank has been set to [" + ChatColor.DARK_AQUA + "Helper" + ChatColor.GRAY + "].");   
                            }
                        if (args[1] == "Member") {
                            Member.add(targetplayer);
                            player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + targetplayer.getName() + "'s rank has been set to [" + ChatColor.WHITE + "Member" + ChatColor.GRAY + "].");   
                            }
                        }
                    }
                }
            }
        }
            return false;
        }
    }
     
  14. Offline

    DuaneTheDev_

    @GodzillaFlame42

    The problem is you're new to coding and everyone else is explaining in a way which may be confusing to you.

    When we use "Player player = (Player) sender;" we're getting the in-game player. This won't allow any sort of console access to this plugin as it'll return a error. Therefore for this scenario we'll scratch it.

    Let's go ahead and check for the command, permission and argument length.
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
       if(label.equalsIgnoreCase("rank")) {
         if(sender.hasPermission("Rank.use)) {
              if(args.length == 0) {
                 }  //end of arg
             } // end of perm
         } // end of command label
        return false;
    }
    Now if the argument is equal to 0 meaning the player only entered /rank, you may wanna return a message. You can write the messages for your plugin, but make sure after the last message below add "return true;"

    Outside of the argument length bracket we wanna check for the remainder of the commands. Ex: /rank <list> and /rank <set> <player> <group>

    So to grab the <set> and <list> argument, we'll be using Argument[0] representing the first action after /rank. (Yes, it may be confusing)

    It should be written like the following below. I'll be using list for the first example.

    Code:
    if(args[0].equalsIgnoreCase("list")) {
    //do stuff
        return true; //Returning true will let the plugin know that it went successful and doesn't need to keep checking.
    }
    The second example gets tricky as we'll need to get the Targetplayer, Group along with set. So following the same as list we'll be getting the first argument after /rank.

    This time around we're going to check if set contains all the arguments /rank set <player> <group> and if not let the player know this.

    Code:
    if(args[0].equalsIgnoreCase("set")) {
        if(args.length <3) {
          sender.SendMessage("Sorry pal, you entered that incorrectly.");
         return true;
    } // end of arg
    }
    Great, so now the plugin will constantly repeat that message unless we get all three arguments. So now using the end of arg bracket, we're going to add an else statement to define what happens after all three arguments have been found.

    So inside of that else statement we first wanna clarify the TargetPlayer and if they exist.
    Code:
    } else {
                              Player targetPlayer = sender.getServer().getPlayer(args[1]); //Argument[1] defines the second action after command
                                if(targetPlayer == null) {
                                    sender.sendMessage("blah blah blah no plaayer");
                                    return true;
                                }
    Good now if the player exists we wanna continue to check for Argument[2] the third action after command. Since the Argument[2] represents <group> we wanna repeat the same way we got list and set.

    Inside of this we can handle setting the Hashmaps for the targetPlayer but I'll leave that up to you. Remember to always return true.

    Code:
    if(args[2].equalsIgnoreCase("Developer")) {
                        sender.sendMessage("Updated to Developer");
                return true;
    }
    You can continue this action until you're finished with all of your ranks, just remember after the first if statement switch to else if and at the very end you can add an else statement to say "Sorry! It appears this rank doesn't exist".

    Code:
    if(args[2].equalsIgnoreCase("Developer")) {
                                  sender.sendMessage("Updated to Developer");
                                  return true;
                              }
                              else if(args[2].equalsIgnoreCase("SrMod")) {
                                  sender.sendMessage("Updated to SrMod");
                                  return true;
                              } else {
                                  //Say no more ranks exist... blah blah
                              }
                          }

    Keep in mind this is a basic example and explanation. Don't get snappy towards me, I'm just going to ignore it.
     
    Last edited: Aug 19, 2016
    Zombie_Striker likes this.
  15. Offline

    GodzillaFlame42

    @DuaneTheDev_ @FabeGabeMC @Zombie_Striker im not trying to get snappy towards you but... when i type the command /rank set Quantiii Owner it doesn't show any message :/

    Code:
    Code:
    package me.godzilla;
    
    import java.util.HashSet;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        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> Member = new HashSet<Player>();
       
        public void onEnable() {
       
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
               if(label.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_RED + "Owner" + 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.RED + "Developer" + 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.RED + "Admin" + ChatColor.GRAY + "].");
                                return true;
                                }
                            else if (args[2].equalsIgnoreCase("SrMod")) {
                                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.GOLD + "Sr.Mod" + 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_PURPLE + "Mod" + 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_AQUA + "Helper" + 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.WHITE + "Member" + ChatColor.GRAY + "].");   
                                return true;
                           
                            } else {
                                sender.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Ranks" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "That ranks does not exist.");
                            }
                       }
                 }
            }
            return false;
        }
    }
     
  16. Offline

    DuaneTheDev_

    @GodzillaFlame42

    When creating the else statement in set, let it follow the same bracket as the if statement. It should look like this...


    Code:
    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) {
                                //....
    
     
  17. Offline

    GodzillaFlame42

    @DuaneTheDev_ Alright, thank you so much! But one more thing... is there like a tutorial or something on how to setup the permissions and prefixes?
     
  18. Offline

    DuaneTheDev_

Thread Status:
Not open for further replies.

Share This Page