Creating Arguments automatically

Discussion in 'Plugin Development' started by random_username, Nov 6, 2013.

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

    random_username

    Hello, I was wondering if it was possible to create a command like /rules for example, so that It can have /rules 2 just if a list in a configuration file has a certain number of strings. i.e. right now I'm making in my config:
    Code:
    Help1:
      - '&3Basic Commands:'
      - '&a/home : Takes you to your home.'
      - '&a/helpop : Messages all Staff, use this for Urgent cases please.'
      - '&a/tpa <player> : Sends a teleport request to a player.'
      - '&a/tpaccept : Accept a teleport request.'
      - '&a/tpdeny : Decline a teleport request.'
      - '&a/navigation : Gives you the Quick Navigation Tool.'
      - '&6/help 2 : Shows help second page.'
     
    Help2:
      - '&a/sethome : Sets you a home.'
      - '&a/Spawn : Takes you to spawn.'
      - '&a/afk : Sets you Away from Keyboard.'
      - '&a/sethome : Sets you a home.'
      - '&a/msg <player> <message> : Sends a message to a player.'
      - '&a/r : Replies to a message.'
      - '&a/rules : Shows you the Server rules.'
    and I have in my OnCommand:
    Code:java
    1. else if(cmd.getName().equalsIgnoreCase("help")){
    2. if(Sender.hasPermission("ecore.help")){
    3. if(args.length == 0){
    4. for(Object o : getConfig().getList("Help1"))
    5. {
    6. if(o instanceof String)
    7. {
    8. String s = (String)o;
    9. Sender.sendMessage(s.replace("&","§"));
    10. }
    11. }
    12. }if(args.length == 1 && args[0].equalsIgnoreCase("2")){
    13. for(Object o : getConfig().getList("Help2"))
    14. {
    15. if(o instanceof String)
    16. {
    17. String s = (String)o;
    18. Sender.sendMessage(s.replace("&","§"));
    19. }
    20. }
    21. }
    22. }else{
    23. Sender.sendMessage(prefix + noperm);
    24. }
    25. }

    Is it possible to use from the config just one "help:" list, and to make the arguments as 1,2,3 etc. automatically, after an amount of strings (i.e. 5 )? Thanks for your time :), sorry for the dumb question.
     
  2. Offline

    tommycake50

    Yes,
    check if the argument is numerical then parse them to an int. get the length of the list, do what dividing you need and select the appropriate range of strings.
    If it exceeds the amount of pages then do whatever you want.
     
  3. Offline

    random_username

    Can you give me an example please? :) Btw, Thanks for the reply
     
  4. Offline

    tommycake50

    Turns out I was an idiot and my math was wrong xD.
    Anyway maybe something like this.
    Code:java
    1.  
    2.  
    3. if(args[0] != null){
    4. if(args[0].matches("[0-9]*")){
    5. int page = Integer.parseInt(args[0]);
    6. int index = (page * 10) - 10; //I think
    7. if(index + 10 <= list.length){
    8. for(int i = index; i < index + 10; i++){
    9. sender.sendMessage(list.get(i));
    10. }
    11. }else{
    12. sender.sendMessage("That page does not exist!");
    13. }
    14. }else{
    15. sender.sendMessage("Argument must be numerical!");
    16. }
    17. }
    18.  
    19.  
     
Thread Status:
Not open for further replies.

Share This Page