How does chat work?

Discussion in 'Plugin Development' started by phondeux, Feb 6, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    phondeux

    I'm making a simple team plugin where players can create teams, join them and get their achievements scored as a team, etc,... and I want to have a team chat for each team except I can't figure out base one to start at. I've seen a few mods with team chat and one even has a github source you can look at but I don't understand where the chatrooms are created, how to destroy a chat room, how to send commands to a specific room.

    My guess from looking at other code is that each chat room is an instance of a server? In that instance players are broadcasting messages to each other which aren't visible from the main server. Is that correct?
     
  2. Offline

    DThielke

    A chat room plugin simply creates some type of internal list of players that are considered to be part of a "channel" or "room" that can communicate to each other. The plugin will then listen for the onPlayerChat(PlayerChatEvent event). When the event fires, the plugin will check who sent the message and which players the message should be received by and then it sends the message to each of those players using player.sendMessage(String message). Lastly, the plugin has to cancel the event with event.setCancelled(boolean cancelled) so that the server doesn't handle the message any further.

    Commands are handled a bit differently, but in short, a command must be registered in the plugin's plugin.yml file and then listened for by onCommand(CommandSender sender, Command command, String commandLabel, String[] args) in the plugin's main class.
     
  3. Offline

    phondeux

    Thank you! HeroChat was one of the plugins I was digging through to try to figure this out. :) I think I made some wrong assumptions about how chat worked.
     
Thread Status:
Not open for further replies.

Share This Page