I need some argument help

Discussion in 'Plugin Development' started by Hovertac, Jun 19, 2012.

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

    Hovertac

    Basically, my command is like this:

    /note <player> <comment>

    If I run:

    /note hovertac wow he's so sexy

    My string "comment" is "wow". How can I make it so the string "comment" is "wow he's so sexy"?

    Code:
    package com.hovertac.playernotes;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
     
    public void onEnable() {
    getLogger().info("PlayerNotes has been enabled!");
    }
     
    public void onDisable() {
    getLogger().info("PlayerNotes has been disabled!");
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    if(cmd.getName().equalsIgnoreCase("note")){
    if (args.length < 2){
    sender.sendMessage(ChatColor.WHITE + "[" + ChatColor.RED + "PlayerNotes" + ChatColor.WHITE + "] " + ChatColor.GREEN + "Usage: /note <player> <comment>");
    } else {
    }
    String player = args[0];
    String comment = args[1];
    sender.sendMessage("Command Sender: ");
    sender.sendMessage("Player: " + player);
    sender.sendMessage("Comment: " + comment);
    }
    }
    return false; 
    }
     
    }
    
     
  2. Offline

    m1enkrafft_man

    Args is a list. This list is the entire command, and it gets this by using something similar to:
    Code:
    String args[] = command.split(" ");
    So what you're asking is for (minus the actual command "note") the second ([1]) word in the list. That would give you "wow", in this case. Why don't you make a new list, loop through args[] via it's length, add in each word, then create a new string containing your newList[]? Just throwing out some ideas here.

    Further info: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
     
  3. Offline

    CorrieKay

    quick correction, args is a String array, not a list c:
     
  4. Offline

    m1enkrafft_man

    Sorry, I was busy in a Skype call, and almost put ArrayList. I realized my mistake, and removed the wrong half of the word. Although the rest of the post is valid.
     
  5. Offline

    Hovertac

    Erm, sorry, but this wasn't much help to me. I tried making a while loop with 2 variables, argscan and numofargs, where it would increase numofargs (starting from 1) then check if arg[numofargs]; with isEmpty(), and once it replied true the total number of args would be numofargs - 1, then set argscan to 0. But for some reason this didn't work.
     
Thread Status:
Not open for further replies.

Share This Page