字母出现在控制台输出中,但不应该出现。 Bukkit.getConsoleSender().sendMessage(); 问题

Letter appears in console output, but shouldn't. problem with Bukkit.getConsoleSender().sendMessage();

我正在尝试拆分 classes 中的代码。此代码发送到行首带有 B 字母的控制台文本,但不应该。

代码:

static ConsoleWrapper cw = new ConsoleWrapper();
cw.notify("using url:" + database.sql_url);
cw.notify("Plugin loaded!");

在ConsoleWrapper.java

public class ConsoleWrapper {
    static String pluginName = App.pluginName;
    static ConsoleCommandSender console = Bukkit.getConsoleSender();

    public void notify(String msg) {
        // wrapper for console messages
        console.sendMessage(("§6[" + pluginName + "]" + msg));
    }
    
    public void alarm(String msg) {
        // wrapper for console messages
        console.sendMessage(("§c[" + pluginName + "]" + msg));
    }
}

但是如果 console.sendMessage(("§c[" + pluginName + "]" + msg)); 在 main class 中执行,字母 B 不会出现在控制台中。

output with cw.notify

[12:01:07 INFO]: В[EggCounter] Plugin is starting first time, or restoring!
[12:01:08 INFO]: В[EggCounter]using url:jdbc:MYSQL://192.168.0.186:9889/easter_eggs

output with console.sendMessage()

[12:13:21 INFO]: [EggCounter]using url:jdbc:MYSQL://192.168.0.186:9889/easter_eggs
[12:13:21 INFO]: [EggCounter]Plugin loaded!

不建议自己编写§,因为可能存在编码问题。

更喜欢使用 ChatColor 枚举,例如:

public class ConsoleWrapper {
    static String pluginName = App.pluginName;
    static ConsoleCommandSender console = Bukkit.getConsoleSender();

    public void notify(String msg) {
        // wrapper for console messages
        console.sendMessage(ChatColor.GOLD + "[" + pluginName + "]" + msg);
    }
    
    public void alarm(String msg) {
        // wrapper for console messages
        console.sendMessage(ChatColor.RED + "[" + pluginName + "]" + msg);
    }
}

您可以找到所有颜色代码 here