Using arrays and colors in player.chat()

Discussion in 'Plugin Development' started by Tate413, Feb 17, 2014.

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

    Tate413

    how do I use arrays and colors in player.chat()?

    Code:
    player.chat("Hello world"); 
    when I do something like that, it'll make someone say "Hello world"

    but if I do this:
    Code:
    player.chat("Welcome" + words[1] + "to the world");
    or:
    Code:
    player.chat(ChatColor.RED + "Welcome" + words[1] + "to the world");
    I get internal error. Is there a way to use colors and arrays with player.chat or an alternative?

    Note: ChatColor is imported and I do have an array.
     
  2. Offline

    d3v1n302418

    Tate413 If the size of words is 1, check for words[0] because Java starts with 0.
     
  3. Offline

    Tate413

    @d3v1n302418 the way it works is, when someone types /ask <player> <item>, it get's broken into an array. I want to use their name, so it'd be words[1]. but player.chat() doesn't work when I put in the array or colors.
     
  4. Offline

    DonkeyTeeth2013

    Tate413 Actually, "ask" would be the label (Considering you do String label as one of your params for onCommand) and anything after that would be words[] (Consdering you do String[] words as a param in onCommand). So, if you wanted "ask" you would do cmd.getName().doStuff() or label.doStuff(). If you wanted <player> you would do words[0] and if you wanted <item> you would do words[1]
     
  5. Offline

    Tate413

    DonkeyTeeth2013 This isn't what I'm asking. I'm asking how do I get arrays and chat colors to work in player.chat().
     
  6. and he is telling you what your problem is!
     
  7. Offline

    Tate413

    TheAnswerIsMinecraft even if it is word[0] to get the players name, using word[1] should have given me the item name and not internal error.
     
  8. Offline

    Evoke

    Try
    Code:
    p.sendMessage(ChatColor.RED + "");
     
  9. Offline

    Tate413

    Evoke I did have that at first, but I'd like it to be for the person typing the command says it in chat. I guess if there's no way to make that work then I'll use sendMessage
     
Thread Status:
Not open for further replies.

Share This Page