minecraft - How to make a clickable link that executes a command with bukkit -
i'm trying make bukkit plugin , can't seem find documentation on i've seen done, how input commands chat message user click on execute command on server "/motd" in form of clickable link url
if (commandlabel.equalsignorecase("cmd") { player.sendmessage("pick command: " + </motd> + ", " + </mail> ); }
replacing "" , "" output this:
and clicking them execute command server them. how this?
you this:
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);
this send them message showing:
choose one: motd
and when user clicked motd
, run command /motd
player. here's little breakdown of we're doing:
ichatbasecomponent comp = chatserializer .a("{\"text\":\"" + "<ignored message> " + "\",\"extra\":[{\"text\":\"" + "<message clicked>" + "\",\"clickevent\":{\"action\":\"run_command\",\"value\":\"" + "<command run when message clicked>" + "\"}}]}"); packetplayoutchat packet = new packetplayoutchat(comp, true); ((craftplayer) <player>).gethandle().playerconnection.sendpacket(packet);
the above code send player:
<ignored message> <message clicked>
and when player clicks <message clicked>
they run command <command run when message clicked>
, , because not start command prefix, /
, force them chat <command run when message clicked>
.
unfortunately, far know, can put 1 click event per message, have this:
choose one:
motd
so have do, variable player
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);
when motd
clicked, /motd
run player, , when mail
clicked, /mail
run.
just side note, need include craftbukkit
in build path, along bukkit
this
Comments
Post a Comment