Solved How to send a chat message as a certain player

Discussion in 'Plugin Development' started by StevenMG, Jan 30, 2013.

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

    StevenMG

    I am working on a plugin called BDchat that adds chat channels to your server, but I am trying to add a feature that would allow players to type /bdc <channel> <message> Currently You have to do /bdc <channel> and then type the message separately. So basically what I need is a way to convert a string into a chat message from a specified player. Does anyone know how this can be done?
     
  2. Offline

    EnvisionRed

    I think the player interface has a Chat(String) method. Not sure though.

    Edit: just read your post a little more thoroughly. Since you've got chat channels (I hope you've already got those working join/leave wise) you should be able to get all the players in the chat channel as a list/array. Just loop through all of those players and send each of them the string the player entered using the player.sendMessage(yourString) method. You can add a prefix with the channel and player name as well. If you've got a "ChatChannel" class or something similar, you could add a SendChannelMessage(String playerName, String message) method which will do handle it for you.
     
  3. Offline

    StevenMG

    EnvisionRed I thought of using player.sendMessage, but if I do that prefixes from other plugins will not show properly, and yes, I do have each of the channels working properly. How this plugin works is it sets the recipients of a message and formats the messages a bit. I do not want to do anything that will make that a message is no longer normal chat message and rather just a message from the server.

    Here is a link to the plugin by the way if anyone wants to check it out. I'm still not able to figure out how to send a chat message though so if anyone knows please let me know.

    http://dev.bukkit.org/server-mods/bdchat/

    EDIT: Figured it out now :D I had been using a CommandSender rather than a Player, lol, its surprisingly simple now :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page