Escape formatting/color codes? #166


  • New
Open
  • L3thalBunny created this issue Mar 9, 2019

    To the best of my knowledge MyCmd does not possess any way to escape formatting codes like essentials does.

     

    Example:

     

    Code: &&c&c = Red

     

    MyCmd Output: & = Red

     

    Expected: &c = Red

    Expected source code: <escaped&>c&c = Red

     

    I'm thinking it'd be pretty easy (and useful) to add an '&' as an escape character so anytime there's '&&' it does not trigger a formatting.

     

    Typically i go about doing this in my plugins like so:

    public static String colorCode(String str)
    {
    	if (str != null) {
    		str = str.replaceAll("&&", "<ampersand>");
    		str = ChatColor.translateAlternateColorCodes('&', str);
    		str = str.replaceAll("<ampersand>", "&");
    		return str;
    	} else {
    		return null;
    	}
    }

     

  • L3thalBunny added a tag New Mar 9, 2019
  • L3thalBunny edited description Mar 9, 2019
  • ivanfromitaly posted a comment Mar 10, 2019

    For now you can use "$NoReplace" at the start of a string to not replace anything. Of course it's not  flexible like your suggestion, but i have to see if doing that i'm not going to break something or someone old command.

  • AnziSpace posted a comment Jul 7, 2020

    Bump, this could be extremely useful on my server. If you're worried about breaking something, you could always introduce it as a config option like

    experimental_colorescape = false

    or something ;P


To post a comment, please login or register a new account.