Solved Messaging plugin help

Discussion in 'Plugin Development' started by Pacothegint, Feb 5, 2014.

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

    Pacothegint

    OK so lets say I want a plugin where I can

    /Taunt <player> <message>

    /taunt paco Test

    I want paco to receive a chat message that says taunt
    I don't want it to say the senders name.
    Code:java
    1.  
    2.  
    3. else if(commandLabel.equalsIgnoreCase("taunt")){
    4. Player target = (Bukkit.getServer().getPlayer(args[0]));
    5. if(args.length <= 1){
    6. sender.sendMessage(new StringBuilder().append(ChatColor.RED).append("Usage: ").append(this.usageMessage).toString());
    7. }
    8.  

    How do I get the message and send it to the player?
    I have heard of a string builder but have no idea how to do that
     
  2. Offline

    xTrollxDudex

    Pacothegint
    Loop through the args past 0 and add them to a string builder or concactate the string.
     
  3. Offline

    Pacothegint

    thats the thing i dont know how to set up a string builder. Could you give me an example of one?

    edit: let me clarify how would i ho about looping through the arguments in the string builder?
     
  4. Offline

    xTrollxDudex

    Pacothegint
    PHP:
    StringBuilder sb =     new StringBuilder();
    sb.appendargs] );
    for ( 
    int in in <= ( args.length ) ; in++ ) {
        
    sb.append(" ").append(args[in]);
    }
    Then send the target sb.toString().
     
  5. Offline

    Weasel_Squeezer

    StringBuilder is just a more efficient way of String concatenation. What he means is to loop through the command args starting at the correct index, and appending each arg value to a single string (along with whitespace probably). so something like this:
    Code:java
    1. StringBuilder sb = new StringBuilder();
    2. for (int i=1; i<args.length; i++) {
    3. sb.append(args[i]).append(i + 1 < args.length ? " " : "");
    4. }
    5. return sb.toString();[/i]


    Oh sorry, I was too late lol

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page