Bukkit - Send data back to people connected through RCON -
i have nodejs / socketio app connects minecraft server through rcon protocol , works perfectly, keep connection open , listens kind of data retrieved.
example, if type command isn't available, respond message.
now i'm trying whenever player on minecraft server chats, bukkit plugin take message , send through connected on rcon.
this part of bukkit plugin fires when player chats.
@eventhandler public void onplayerchat( asyncplayerchatevent e ) { bukkit.getlogger().info("test 1"); this.getlogger().info("test 2"); bukkit.getserver().getconsolesender().sendmessage("test 3"); this.getserver().getconsolesender().sendmessage("test 4"); }
the messages recorded in server log, though not through rcon protocol.
rcon used minecraft not have mechanism send messages after initial packets. if need mechanism this, need invent own protocol, or make command returns last chat log if it's executed.
to make command, can simple make queue<string>
putting our messages (like chat) into.
final queue<string> messages = new arraydeque<>(64); public void insertmessage(string message) { synchronized (messages) { messages.add(message); if (messages.size() == 64) // full messages.remove(); } }
we can hook method our chat event:
@eventhandler(priority=eventpriority.monitor,ignorecancelled=true) public void onchat(asyncplayerchatevent evt) { insertmessage("[chat] " + evt.getplayer() + " : " + evt.getmessage()); }
then need make command read out our messages list, easy make:
private string getmessage() { synchronized (messages) { return messages.poll(); } } @override public boolean oncommand(commandsender sender, command cmd, string label, string[] args) { if(!cmd.testpermissions()) { return true; } string message; while((message = getmessage()) != null) { sender.sendmessage(message); } }
this allows server log rcon typing in command or making client application executes command every second or so.
Comments
Post a Comment