你可以做這樣的:
IChatBaseComponent comp = ChatSerializer
.a("{\"text\":\"" + "Choose one: " + "\",\"extra\":[{\"text\":\"" + "MOTD" + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + "/motd" + "\"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) <player>).getHandle().playerConnection.sendPacket(packet);
這將會給他們呈現出消息:
Choose one: MOTD
,當用戶點擊MOTD
,它會運行命令/motd
作爲玩家。下面是什麼,我們實際上正在做一個小故障:
IChatBaseComponent comp = ChatSerializer
.a("{\"text\":\"" + "<Ignored Message> " +
"\",\"extra\":[{\"text\":\"" + "<Message that will be clicked>" +
"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" +
"<Command to be run when message is clicked>" + "\"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) <player>).getHandle().playerConnection.sendPacket(packet);
上面的代碼將發送玩家:當玩家點擊<Message that will be clicked>
他們將運行命令
<Ignored Message> <Message that will be clicked>
和<Command to be run when a message is clicked>
,並且因爲它不以命令前綴開始,/
,它將強制他們聊天<Command to be run when a message is clicked>
。
不幸的是,據我所知,你只能把點擊事件每封郵件,所以你會做這樣的事情:
選擇一個:
MOTD
郵件
所以,你必須做的,其中變量player
是玩家:
player.sendMessage("Choose one:");
IChatBaseComponent comp = ChatSerializer
.a("{\"text\":\"" +
"\",\"extra\":[{\"text\":\"" + "MOTD" +
"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" +
"/motd" + "\"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
IChatBaseComponent comp2 = ChatSerializer
.a("{\"text\":\"" +
"\",\"extra\":[{\"text\":\"" + "Mail" +
"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" +
"/mail" + "\"}}]}");
PacketPlayOutChat packet2 = new PacketPlayOutChat(comp2, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet2);
當MOTD
被點擊時,/motd
將由玩家運行,當點擊Mail
時,/mail
將會運行。
正如一個側面說明,你將需要包括craftbukkit
在構建路徑,隨着bukkit
做到這一點
這個偉大的工程,真可惜有關每行,但它確實與我在你的文章上編輯過的微小修改一起工作。與「comp」 – zfb