Solved How to change the way names display to players

Discussion in 'Plugin Development' started by JonnyAxehandle, Jul 20, 2014.

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

    JonnyAxehandle

    So I'm making a plugin that has a friends list, enemy list, teams, etc. and I'm trying to change the way player names appear to each other in chat. For example, displaying an [F] tag next to friends or a [T] tag next to teammates. I've done a lot of searching but all I can find is info on changing the way names display for everyone. Is this even possible? If so, what do I need to research?
     
  2. Offline

    Epicballzy

    I'm pretty sure that you could do an if statement to check who is a friend and who is a teammate..
    Example:
    Code:java
    1. if(player is a teammate) {
    2. //do stuff
    3. } else {
    4. if(player is a friend) {
    5. //do stuff
    6. }
    7. }


    Don't get me wrong, but there may be different ways.
     
  3. Offline

    Pizza371

    JonnyAxehandle listen to AsyncPlayerChatEvent and set the message differently.
    Epicballzy this is correct but i dont think thats quite waht he was getting at XD also you can use else if rather than nesting them
     
  4. Offline

    JonnyAxehandle

    Thanks! I managed to throw together a solution. I'm posting it here in case anyone else needs it

    Code:java
    1. @EventHandler
    2. public void onPlayerChat( AsyncPlayerChatEvent e )
    3. {
    4. Player player = e.getPlayer();
    5. String message = e.getMessage();
    6.  
    7. for( Player recipient : e.getRecipients() )
    8. {
    9. // Here's where you would check for relation type between recipient and player and add your tags
    10. String tags = "";
    11. recipient.sendMessage(String.format("<%s%s> %s",player.getDisplayName(),tags,message));
    12. }
    13.  
    14. e.setCancelled(true);
    15. }


    Removed all the stuff that's only relevant to my plugin.
     
Thread Status:
Not open for further replies.

Share This Page