PM with arguments?

Discussion in 'Plugin Development' started by Condolent, Feb 4, 2014.

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

    Condolent

    Hey, so I tried making a command to send PM to each other, I made it with arguments (which I realized wouldn't work too good since it'll only be able to transmit via 1 message-word...)
    This is the current code:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("pm")) {
    2. if(args.length == 1) {
    3. p.sendMessage("/pm <player> <message>");
    4. } else if(args.length < 2) {
    5. Player target = Bukkit.getServer().getPlayerExact(args[0]);
    6. if(target == null) {
    7. p.sendMessage(ChatColor.RED + "Couldn't find online player: " + args[0]);
    8. return false;
    9. }
    10. target.sendMessage(ChatColor.GREEN + "[" + p.getName() + "] -> [me] " + ChatColor.WHITE + args[1]);
    11. p.sendMessage(ChatColor.GREEN + "[me] -> [" + target.getName() + "] " + ChatColor.WHITE + args[1]);
    12. }
    13. }

    How can I solve this? Tried and only works with 1 word as message...
     
  2. Offline

    d0mov0i

    Code:
    if(args.length < 2){
      //insufficient param
    }else{
      //args[0] = name , args[1] to args[args.length-1] = message
    }
     
  3. Offline

    gomeow

    You are going to need to use a StringBuilder
     
  4. Offline

    Condolent

    tried that, only takes the last word I type in message and sends it.

    Exactly how do I do that? :| Make an example? :)
     
  5. Offline

    sgavster

    PHP:
    StringBuilder s = new StringBuilder();
    for(
    int i 1args.lengthi++) {
    s.append(args[i]).append(" ");
    }
    String message s.toString();
     
  6. Offline

    d0mov0i

    sigh, think about it. im not gonna just tell u the answer right away.
    heres a hint. for loop all args from args[1] to the last args. then append all of them

    EDIT: dang it svgawdafasd
     
  7. Offline

    1Rogue

    Code:
    String message = s.toString().trim();
    
     
  8. Offline

    Condolent

Thread Status:
Not open for further replies.

Share This Page