Solved Help Idk why

Discussion in 'Spigot Plugin Development' started by Ean244, May 31, 2017.

  1. i want to format my chat color using this method but i failed heres the code:
    Code (Text):
    public static String formatChatColor(String s) {
            ChatColor.translateAlternateColorCodes('&', s);
            return s;
        }
    can any help ?
     
  2. You never used the return value of the method. Strings are immutable, any standard change to a string will be a new string object.
     
  3. Just do
    Code (Text):
    public static String formatChatColor(String s) {
            return ChatColor.translateAlternateColorCodes('&', s);
        }

    This works for me all the time :)
     
  4. What do you mean by failed? And, if you don't set the result of ChatColor operation back to s, it obviously won't work.
    Code (Text):
        public static String color(String s)
        {
            return ChatColor.translateAlternateColorCodes('&', s);
        }
       
    This will work better, otherwise

    Code (Text):
        public static String color(String s)
        {
            s=ChatColor.translateAlternateColorCodes('&', s);
            return s;
        }
    This is pretty basics of any programming language anyway
     
  5. Thanks guys I almost forget that Strings are immutable