Changing commands in a config file

Discussion in 'Plugin Development' started by mickverm, May 18, 2012.

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

    mickverm

    hey,

    I'm making a plugin in which I can add custom commands in the config file with its description, but I dont know how to get the command/description from the config so it works

    E.G

    this is what I want to get from the config
    name: server
    command: help
    description: shows the help page

    so, what i want it to do: if I type /server help i want it to say "shows the help page"
    and every command should start with /server

    I hope this is possible and I hope that you guys can help me
     
  2. Offline

    Craftiii4

    you want users to be able to pick their own commands?
     
  3. Offline

    mickverm

    basically yes
     
  4. Offline

    Craftiii4

    Just the host, or the users on the server?
     
  5. Offline

    mickverm

    the host so that when a user uses the command it displays the text that is defined in the config.yml
     
  6. Here is an exerpt of my code from ParagonWool before a custom modifier:
    Code:
    @Override
        public boolean onCommand(CommandSender sender,Command cmd, String Label, String[] args) {
            Player player = (Player) sender;
     
            if(cmd.getName().equalsIgnoreCase("wool") && player.getItemInHand().getType().equals(Material.WOOL) && checkPermission(player, "paragonwool.use")) {
                  if(args.length > 0){
                if(args[0].equalsIgnoreCase("list")){
                      player.sendMessage(ChatColor.BLUE + "  ~~~~~~~~~~~~" + ChatColor.YELLOW + "ParagonWool" + ChatColor.BLUE + "~~~~~~~~~~~~");
    
    Here it is after with a line in the config.yml file called "main_command":

    Code:
    String mainCMD = getConfig().getString("main_command");
    @Override
        public boolean onCommand(CommandSender sender,Command cmd, String Label, String[] args) {
            Player player = (Player) sender;
     
            if(cmd.getName().equalsIgnoreCase("[B]mainCMD"[/B]) && player.getItemInHand().getType().equals(Material.WOOL) && checkPermission(player, "paragonwool.use")) {
                  if(args.length > 0){
                if(args[0].equalsIgnoreCase("list")){
                      player.sendMessage(ChatColor.BLUE + "  ~~~~~~~~~~~~" + ChatColor.YELLOW + "ParagonWool" + ChatColor.BLUE + "~~~~~~~~~~~~");
    Where the "mainCMD" is in the code to need to manually type main then hit CTRL + Space and select the String or it enters the text instead.

    So yours might look like:

    Code:
    String mainCMD = getConfig().getString("main_command");
    String nameString = getConfig().getString("main_command");
    String descriptionString = getConfig().getString("main_command");
     
    @Override
        public boolean onCommand(CommandSender sender,Command cmd, String Label, String[] args) {
            Player player = (Player) sender;
       
            if(cmd.getName().equalsIgnoreCase("mainCMD")) {
                  if(args.length > 0){
     if(args[0].equalsIgnoreCase("list")){
                      player.sendMessage("nameString" + " " + "descriptionString");
    }
     if(args[0].equalsIgnoreCase("list")){
     //Code here
     }
    }
    }
     
  7. Offline

    russjr08


    I might be wrong here but I think..
    Code:Java
    1.  
    2. [FONT=Consolas]String mainCMD = getConfig().getString("main_command");[/FONT]
    3. [FONT=Consolas]String nameString = getConfig().getString("main_command");[/FONT]
    4. [FONT=Consolas]String descriptionString = getConfig().getString("main_command");[/FONT]
    5.  
    6. [FONT=Consolas]@Override[/FONT]
    7. [FONT=Consolas] public boolean onCommand(CommandSender sender,Command cmd, String Label, String[] args) {[/FONT]
    8. [FONT=Consolas] Player player = (Player) sender;[/FONT]
    9.  
    10. [FONT=Consolas] if(cmd.getName().equalsIgnoreCase("[B][U]mainCMD[/U][/B]")) {[/FONT]
    11. [FONT=Consolas] if(args.length > 0){[/FONT]
    12. [FONT=Consolas] if(args[0].equalsIgnoreCase("list")){[/FONT]
    13. [FONT=Consolas] player.sendMessage("nameString" + " " + "descriptionString");[/FONT]
    14. [FONT=Consolas]}[/FONT]
    15. [FONT=Consolas] if(args[0].equalsIgnoreCase("list")){[/FONT]
    16. [FONT=Consolas] //Code here[/FONT]
    17. [FONT=Consolas] }[/FONT]
    18. [FONT=Consolas]}[/FONT]
    19. [FONT=Consolas]}[/FONT]
    20.  

    Needs to be if(cmd.getName().equalsIgnoreCase(mainCMD)) { otherwise you're not passing the actual config string. :)
     
  8. idk but that is how I always did it and works...
     
Thread Status:
Not open for further replies.

Share This Page