在充分研究后,我发现了几十种基本相同的方法;这是进入聊天。
但是..
public static void sendPlayer(Player p, String s){
if (sm.getPrefixUse()) {
// - Method 1
String string = s.replaceAll("(&([a-f0-9]))", "\u00A7$2");
p.sendMessage("[" + sm.getPrefixName().replaceAll("(&([a-f0-9]))", "\u00A7$2") + "]" + string);
// This is one method but does not work - no colour in chat
// - Method 2
p.sendMessage(ChatColor.translateAlternateColorCodes('&', sm.getPrefixName()) + ChatColor.translateAlternateColorCodes('&', s));
// Heres another- no colour in chat
// - Method 3
String working = "&4This works ".replaceAll("(&([a-f0-9]))", "\u00A7$2");
p.sendMessage(working);
// - Method 4
String thistoo = "&4This too works";
p.sendMessage(ChatColor.translateAlternateColorCodes('&', thistoo));
} else{
p.sendMessage(s);
}
}
当我从配置
获取字符串时,方法1和2在聊天中不显示颜色方法3和4工作,基本上与上面相同,但字符串在这里定义
如何从配置中获取字符串并将其发送给具有正确颜色的播放器
编辑: 让我们说这是我的配置
prefix:
use: true # By default it is true [true/false]
# true = Adds a prefix to the messages
# false = Doesnt add a prefix to the messages
name: &4Hub
# Plugin prefix - prefix to appear before messages
如果我向其添加颜色代码,它将返回null
public void onPlayerJoin(PlayerJoinEvent e){
if(sm.getMotdUse()){
ChatManager.sendPlayer(p, sm.getMotdMessage());
return;
}
.....某事......
然后
public static void sendPlayer(Player p, String s){
if (sm.getPrefixUse()) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', s));
p.sendMessage(s.replaceAll("&", "§"));
} else{
p.sendMessage(s);
}
}
基本摘要如果motd为true则发送motd彩色消息+前缀 但前缀返回null 消息返回少一个字
所以,如果motd消息是'& 4Welcome to server' 它发送'没有颜色的服务器'