你可以做这样的:
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