Solved Player chat

Discussion in 'Plugin Development' started by Kartufle, Jan 19, 2017.

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

    Kartufle

    So im trying to make a plugin where if the specific player is saved somewhere in a hashmap he/she's chatcolor will be changed

    Could i somehow make the player just write in green or would i have to get the players msg and then customize it and then send it as a broadcastMessage?

    Ty :)
     
  2. Offline

    Alex_Cboy

    Im not really sure about that but, you should be able to get the message with asyncplayerchatev or something like that event and just use e.setMessage() here's an example:
    Code:
    public void onMsgSend(AsyncPlayerChatEvent e){
            //if condition{
               e.setMessage(ChatColor.GREEN + e.getMessage() +"");
           //}else...
            }
    
    Though, if it works for what you asked, please set this to solved, and do not reply to my with comment, edit your post, to do it as it's not allowed for some reason to reply but to edit the already existing thread.
     
    Last edited: Jan 19, 2017
  3. Code:
      public HashMap<Player, ChatColor> YourHashMap = new HashMap<Player,ChatColor>();
       @EventHandler
       public void on(AsyncPlayerChatEvent e){
         if(YourHashMap.containsKey(e.getPlayer())){
           String message = YourHashMap.get(e.getPlayer())+e.getMessage();
           e.setMessage(message);
         }
         }
       }
    I hope i got your question right...
     
    Last edited: Jan 19, 2017
  4. Offline

    Alex_Cboy

    I did not think of it like that but it seems good enough :):)
     
  5. Offline

    Kartufle

    ty Alex_Cboy works perfect right now :)
     
    Alex_Cboy likes this.
  6. Offline

    Alex_Cboy

    No problem man. Have fun playing around!
     
Thread Status:
Not open for further replies.

Share This Page