Why this maven error

Discussion in 'Spigot Plugin Development' started by Kyllian, Apr 30, 2017.

  1. Hey,

    This is my maven error

    Code (Text):
    [ERROR] \Work Folder\Java\Translated\src\main\java\me\kyllian\Translated\utils\ColorTranslate.java:[14,48] error: unclosed character literal
    [ERROR] \Work Folder\Java\Translated\src\main\java\me\kyllian\Translated\utils\ColorTranslate.java:[14,50] error: illegal character: '\u00a7'
    [ERROR] \Work Folder\Java\Translated\src\main\java\me\kyllian\Translated\utils\ColorTranslate.java:[14,51] error: unclosed character literal
    [ERROR] \Work Folder\Java\Translated\src\main\java\me\kyllian\Translated\utils\ColorTranslate.java:[14,57] error: ';' expected
    And this is my colortranslate class:

    Code (Text):
    package me.kyllian.Translated.utils;

    import net.md_5.bungee.api.ChatColor;

    public class ColorTranslate {

        public static ColorTranslate ct = new ColorTranslate();

        public static ColorTranslate getInstance() {
            return ct;
        }

        public String cc(String msg) {
            return ChatColor.translateAlternateColorCodes('§', msg);
        }
    }
     
    dont mind me make stupid mistakes in maven, not good at it
     
  2. "net.md_5.bungee.api.ChatColor" and "org.bukkit.ChatColor" are different, in case you didn't know (Are you sure you need the bungeecord ChatColor?). Why would you translate the '§' letters? Don't you want to translate these: '&' ?
     
  3. Mas

    Mas

    It is recommended to use the Bukkit ChatColor import so your plugin can potentially work on Bukkit servers.
    Also, you can make that method static because it's pretty much a util method.
    As said above, use another symbol like '&', since the section symbol gets translated to colours anyway.
     
  4. Code (Text):
    package me.kyllian.Translated.utils;
    Your package naming doesn't match the conventions. package names should always be lowercase.
    Code (Text):
    import net.md_5.bungee.api.ChatColor;
    Your import is most likely wrong. You should import org.bukkit.ChatColor as the Bungee ChatColor does not exist in Bukkit.
    Code (Text):
    public class ColorTranslate {

        public static ColorTranslate ct = new ColorTranslate();

        public static ColorTranslate getInstance() {
            return ct;
        }
     
    Why do you make a getter for a public field that does nothing but returning it? If this is the whole class: Why do you even need to instantiate it?
    Code (Text):

        public String cc(String msg) {
            return ChatColor.translateAlternateColorCodes('§', msg);
        }
    }
     
    This is a very weak method name. It is impossible to get what it does intuitively. I can't think of any case where translating § into § would make sense. You shouldn't use non-ASCII chars in your code at all. However, this method is redundant anyway because it does nothing but performing a Bukkit method. You could use ChatColor.translateAlternateColorCodes('&', msg) whereever you use ColorTranslate#cc(msg).
     
  5. Maven did that, Not me.
    As I said, can't work with maven quite good yet (That's why I don't even know where I should change it without breaking it all again)

    But it's working now, thnx
     
  6. Maven doesn't have anything to do with your code. Your IDE might automatically generate a wrong package name based on a wrong artifactId. artifactIds are also supposed to be nothing but lowercase, while you may format the <name> as you please.
     
    • Like Like x 1