Solved Broadcast Color Question

Discussion in 'Plugin Development' started by LandonTheGeek, Nov 11, 2013.

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

    LandonTheGeek

    Hey, Beast here.

    I am wondering how I can let players enter their own color code for a broadcastMessage string. At the moment, players enter what they want their broadcast message color to be in the config, but I want that to be configurable in game. Let me show you.

    My method that I am using to get the method color is this here:
    Code:
    ChatColor.translateAlternateColorCodes('&', getConfig().getString("ManualMessageColor"))
    Although, I am wanting to allow players to do /<broadcastcommand> &COLORMessage

    Sorry if I am being difficult or confusing, thanks.
     
  2. Offline

    Qwertyness_

    The color codes that you are talking about are two characters including the '&'. To make this configurable, have them type it in the beginning of their message and then add all of the arguments from the command and send it through translateAlternateColorCodes() as before.
     
  3. Offline

    LandonTheGeek

    Qwertyness_
    Yes, I have that and my broadcast string. I just need to know what to throw into the method.

    Code:
    ChatColor.translateAlternateColorCodes('&', /*Yep, here.*/ ) + broadcastMessage
     
  4. Offline

    Qwertyness_

    You take all of the arguments from the player's command and add them into one string, send that string through the translateAlternateColorCodes() method, then broadcast it.
    If I'm not wrong, that SHOULD work :p

    EDIT: Btw, in your case the "player's command" has already been built, just send broadcastMessage through the method. (Sorry, didn't read your message carefully)
     
  5. Offline

    LandonTheGeek

    Qwertyness_
    As in this string? If so, do what with it?
    (Sorry, I am being difficult now. Lol)
    Code:
                    int i;
                    String broadcastMessage ="";
                    for (i = 0; i < args.length; i++) {
                    broadcastMessage += args[i] + " ";
     
  6. Offline

    Qwertyness_

    Is your broadcastMessage variable the player's desired message?
     
  7. Offline

    LandonTheGeek

    Qwertyness_

    Yes, I added that into my broadcast.
    Code:
    ChatColor.translateAlternateColorCodes('&', ) + broadcastMessage
    I just need to know what to pass through so that to colors work. :)
     
  8. Offline

    Qwertyness_

    then just do:
    Code:java
    1. ChatColor.translateColorCodes('&', broadcastMessage);
    2. Bukkit.broadcastMessage(broadcastMessage);

    Or something of that manner...
     
  9. Offline

    LandonTheGeek

    Qwertyness_

    Oh okay, I see. You are saying I could just combine the two?
     
  10. Offline

    Minecrell

    HelpfulBeast
    Do you only want to replace the first color? Because you could just use ChatColor.translateAlternateColorCodes('&', broadcastMessage) if you want to replace all colors in the message.
    Edit: Too slow :(
     
  11. Offline

    Qwertyness_

    If you combine them, you can use multiple color codes as Minecrell said, and it also makes it a WHOLE lot easier.
    (Lol Minecrell, had many a moment today that I was in the same situation :D )
     
    Minecrell likes this.
  12. Offline

    LandonTheGeek

    Qwertyness_
    Lol. I did some experimenting with what you did, and if I enter more than another argument I get my command usage error. Here:

    [​IMG]

    Here is my code.
    Code:java
    1. ChatColor.translateAlternateColorCodes('&', broadcastMessage);
    2. Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ManualPrefix")) + broadcastMessage);


    My string builder is still the same as is above.
     
  13. Offline

    Qwertyness_

    That's something to do with your declaration of broadcastMessage than.
    Can you post your command reading code?
     
  14. Offline

    Minecrell

    HelpfulBeast
    Make sure to replace the message by the colored one before broadcasting it. The method will return a new string and won't modify the old one.
    Code:java
    1. broadcastMessage = ChatColor.translateColorCodes('&', broadcastMessage);

    If you're interested, here's the code you could use for only replacing the first color:
    Code:java
    1. broadcastMessage = broadcastMessage.replaceFirst("&([0-9a-fk-or])", "\u00A7$1");
     
  15. Offline

    LandonTheGeek

    Qwertyness_

    Lol. Forget the argument error. I realized that was something I did wrong before (I fixed that).

    Now, whenever I try to enter a color code after my command, it just runs straight forward and does for e.x. "&9Hey" without the coloring. Dang.
     
  16. Offline

    Qwertyness_

    Forgot about that :D
    Can you be a little more descriptive...didn't understand what you meant :eek:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  17. Offline

    LandonTheGeek

  18. Offline

    Qwertyness_

    Cool. Please mark as solved! Keep this a good community...lol
     
    HelpfulBeast likes this.
  19. Offline

    LandonTheGeek

  20. Offline

    drtshock

    Minecrell likes this.
Thread Status:
Not open for further replies.

Share This Page