Bold, Italic, Underline, Strike, Magic Chat colors help

Discussion in 'Plugin Development' started by IcyRelic, Aug 21, 2013.

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

    IcyRelic

    i have this

    Code:java
    1. str.replace("&l", ChatColor.BOLD+"").replace("&o", ChatColor.ITALIC+"").replace("&n", ChatColor.UNDERLINE+"").replace("&k", ChatColor.MAGIC+"").replace("&m", ChatColor.STRIKETHROUGH+"")


    but it doesnt do anything
     
  2. Try using:
    String str = "&4This is red!";
    str = ChatColor.translateAlternateColorCodes('&', str);
     
  3. Offline

    Trevor1134

    As Mersenne Twister said, but assuming your are using something they type, use a StringBuilder to create their string, then do translateAlternateColorCodes("&", sb.toString());

    StringBuilder:
    Code:
    StringBuilder sb = new StringBuilder();
     
    //To cast something to the builder do
    //sb.append(STUFF_TO_ADD);
    
     
  4. Offline

    IcyRelic

    didnt work here is my full code

    Code:java
    1. String motd = plugin.getConfig().getString("MOTD.Message").replace("%playername%", name).replaceAll("(&([a-f0-9]))", "\u00A7$2");
    2. String [] split = motd.split("/n");
    3.  
    4. int y = 0;
    5. while(y < split.length){
    6. split[y] = ChatColor.translateAlternateColorCodes('&', split[y]);
    7. p.sendMessage(split[y]);
    8. y++;
    9. }


    anything else

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

    IcyRelic

  6. Icyrelic
    Here is fully functioning code from one of my plugins. I added comments to help you understand everything in it :)

    Code:java
    1. StringBuilder str = new StringBuilder();
    2. for (int i = 0; i < args.length; i++){
    3. str.append(args[i] + " "); //this basically allows you to set an entire chat message as a string
    4.  
    5. }
    6.  
    7. String task = str.toString(); //creates a string
    8.  
    9. if (commandLabel.equalsIgnoreCase("example")){ //command
    10. if (args.length > 0){ //checks to make sure that you have more than 1 arguement
    11. if (sender.hasPermission("example.permission")){
    12. getConfig().set("Task", task); //sets a string in the config titled "Task" and sets your entire message after it
    13. saveConfig(); //saves the config. Must have this or nothing will be saved
    14. sender.sendMessage(ChatColor.GOLD + "Message set to: " + ChatColor.translateAlternateColorCodes('&', task)); //allows you to use standard chat colors that you're used to
    15.  
    16. //here is an example command of how to retrieve everything from the config
    17. if (commandLabel.equalsIgnoreCase("test")){ //command
    18. sender.sendMessage(ChatColor.WHITE + "Message: " + ChatColor.translateAlternateColorCodes('&', getConfig().getString("Task"))); //same idea as previous command, except here we get the Task string from the config
    19. }
    20.  
    21.  
    22. [/i]


    This should work for you (you may have to modify it for your needs, of course). If you have any questions feel free to ask :)


    Icyrelic

    Also, don't forget to add brackets in there when necessary. I forgot to add some when I typed that up :( Also, ignore that [/i] at line 22. Idk what that's there.

    EDIT: You need to add 3 brackets at line 15

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

    IcyRelic

    I have

    p.sendMessage(ChatColor.translateAlternateColorCodes('&', split[y]));

    and in the config i have

    MOTD: '&lTest'

    but it sends in chat a normal Test

    This doesnt even work
    Code:
    p.sendMessage(ChatColor.BOLD + split[y]);
    OOPS Yes it does im so stupid i this whole thread just turned into a joke... i just realized i had a hacked client on that had ttf font lol i took it off and it works fine

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

Share This Page