Solved Adding Prefix to Chat Message

Discussion in 'Plugin Development' started by WiseHollow, Oct 13, 2013.

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

    WiseHollow

    Hey guys, how can I add a prefix to people's names on chat messages?
     
  2. Offline

    MiniDigger

    Just put this into a listener
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent e){
    3. e.setFormat("[PREFIX] %s : %s");
    4. }

    and replace [PREFIX] with the prefix of the user chatting.
     
  3. Offline

    WiseHollow

    Is there a reason why my messages are no-longer showing up in the Multicraft chat now? They are only showing up in console now o.o
     
  4. Offline

    MiniDigger

    since i dont know what multicraft is i cant help you :D.Is this a chat plugin? Then you have to look how you change the format with this plugin.
     
  5. Offline

    WiseHollow

    It is a server control panel actually.
    http://www.multicraft.org/
     
  6. Offline

    MiniDigger

    WiseHollow mmhh thats interesting... Does message get displayed in the console and in minecraft? Just not in multicraft?
     
  7. Offline

    WiseHollow

    MiniDigger It gets displayed in both yeah.

    Here is what my format is

    Code:
    private String mayorFormat = ChatColor.GOLD + "[Mayor]" + ChatColor.RESET + "%1$s: %2$s";
     
  8. Offline

    MineDoubleSpace

  9. Offline

    MiniDigger

    Then I think its a issue of multicraft since I dont know what you could do wrong :D. But if you post your listener here I can take a look on it.
     
  10. Offline

    WiseHollow

    MiniDigger MineDoubleSpace

    Here is my listener. I find it odd that it would do this because, permission-type plugins that add group-prefixes work perfectly xD

    Code:
    private String peasantFormat = ChatColor.GREEN + "[Peasant]" + ChatColor.RESET + "%1$s: %2$s";
    private String citizenFormat = ChatColor.BLUE + "[Citizen]" + ChatColor.RESET + "%1$s: %2$s";
    private String mayorFormat = ChatColor.GOLD + "[Mayor]" + ChatColor.RESET + "%1$s: %2$s";
     
    @EventHandler
        public void playerChat(AsyncPlayerChatEvent event)
        {
            if (Town.getPlayerTown(event.getPlayer().getName()) != null)
            {
                event.setFormat(mayorFormat);
                return;
            }
            if (ProjectUtilities.getPlayerHomeTown(event.getPlayer().getName()) != null)
            {
                event.setFormat(citizenFormat);
                return;
            }
         
            event.setFormat(peasantFormat);
        }
     
  11. Offline

    MiniDigger

    WiseHollow mmh that looking fine too. Ill take a look at how group manager does this :D

    WiseHollow it is using setFormat too. This has to be a bug in multicraft. You should contac their support and see what they say about this. I dont know how the chat tap work, so i cant help you with that

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
    WiseHollow likes this.
  12. Offline

    WiseHollow

    Thank you for taking a look at that for me :) I'll contact their support right away.
     
  13. Offline

    MiniDigger

  14. Offline

    TehVoyager

    WiseHollow
    Maybe you could cancel the message and then get it and broadcast it with
    Bukkit.broadcastmessage or bukkit.broadcast <---- don't know which one it is
     
  15. Offline

    WiseHollow

    MiniDigger I got a reply from Multicraft and they said,
    I wonder how it works with Group Manager but not when I do it...
     
  16. Offline

    MiniDigger

    WiseHollow they said you can change the parsing of the msgs in the .jar.conf file. Look into it and try to change it to [Prefix] <name> Message or something like this
     
  17. Offline

    FireBreath14

    Code:
    string dn = p.getDisplayName();
    p.setDisplayName("PREFIX_GOES_HERE"+dn);
     
    WiseHollow likes this.
  18. Offline

    MiniDigger

    FireBreath14 nice solution :D. Didnt thought about it since it works for me with changing the format
     
  19. Offline

    kevin3220

    Yeah but is it possible to make chat messages do not show up in console?
     
  20. Offline

    Skyost

  21. Offline

    WiseHollow

    You are brilliant. Thank you very much.
     
  22. Offline

    ChocolateChimp

    While this is solved, aswell as a very old post, I'd like to add on to this. While it's easy to use the "setDisplayName" method it can result in some problems. Minecraft usernames can be up to 17 characters long, any longer and it will mess up your server. The chat format message is a bit more difficult, yet it's results yield a better performing server.
    I posted this in case anyone else views this thread. I highly recommend you go with the chat format method.
     
Thread Status:
Not open for further replies.

Share This Page