我想用他的已保存的朋友發送消息給玩家。這些朋友被保存在一個.yml文件中,但只是每個玩家的UUIDS。將玩家的UUID替換爲玩家的名字
然後我試圖取代UUID或將其轉換爲玩家名字顯示該消息時(如果這是有道理的)
CODE:
p.sendMessage("§7▄▄▄▄▄▄▄▄▄▄▄▄§aFriend System - page 1 of 1§7▄▄▄▄▄▄▄▄▄▄▄▄");
int i = 1;
int length = cfg.getList(p.getUniqueId() + ".Friends").size();
if (length != 0)
{
while (i <= length)
{
String uuid = (String)cfg.getList(p.getUniqueId() + ".Friends").get(i - 1);
ProxiedPlayer p2 = ProxyServer.getInstance().getPlayer(UUID.fromString(uuid));
if (p2 != null)
{
TextComponent prefix = new TextComponent(Main.prefix);
TextComponent join = new TextComponent("§a§lONLINE");
prefix.addExtra("§9" + p2.getName());
prefix.addExtra(" ");
prefix.addExtra(join);
p.sendMessage(prefix);
}
else
{
String name = getNamebyUUID(uuid);
if (name != null)
{
p.sendMessage(Main.prefix + "§9" + name + " §c§lOFFLINE");
Main.names.put(uuid, name);
}
else if (Main.names.containsKey(uuid))
{
p.sendMessage(Main.prefix + "§9" + (String)Main.names.get(uuid) + " §8[§c§lOFFLINE§8]");
}
else
{
p.sendMessage(Main.prefix + "§cThis is not a valid player!");
}
}
i++;
}
}
else
{
p.sendMessage(Main.prefix + "§cYou don't have any friends.");
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
Bukkit.getPlayer(UUID).getDisplayName(); – Kerooker