Remove the <> from name onchat

Discussion in 'Spigot Plugin Development' started by Doron1803, Nov 14, 2017 at 1:55 PM.

  1. hey!
    I was trying to make a thing which does instead of
    <username> message
    Displayname: <message>
    i tried doing:
    Code (Java):
        public void playerChat(AsyncPlayerChatEvent e){
                Bukkit.broadcastMessage((e.getPlayer().getDisplayName() + ChatColor.GRAY + e.getMessage()));
    doesn't work, what to do then?
  2. The event handler probably isn't working.
    • Is the handler registered properly?
    • Does the handler have an @EventHandler tag?
    • Useful Useful x 1
  3. Even then, this is still a bit of a gross way to do it. Can't you just change the format string in the event?
    • Agree Agree x 2
  4. While I agree, this is a thread regarding his event handler not working as expected, not a code quality check. I would simply suggest to get DeluxeChat and be done with it :p
  5. you didnt space between displayname and message, you didnt add the ":" thing after displayname, along with that have you registered the listeners and as stated above the eventhandler annotation?
  6. Code (Text):
    public void playerChat(AsyncPlayerChatEvent e) {
    e.setFormat("%1$s: %2$s");
    %1$s is the player display name
    %2$s is the message
  7. doesn't work
  8. Ahh do this.
    Code (Text):

    //Make sure your class implements Listener
        public void onChat(AsyncPlayerChatEvent e)
            //example code
            Player p = e.getPlayer();
            e.setFormat(ChatColor.WHITE + p.getDisplayName() + ChatColor.GRAY + " > " +  e.getMessage());
    In your main class:
    Code (Text):

    public void onEnable() {
               PluginManager pm = Bukkit.getServer().getPluginManager();
               pm.registerEvents(new YourEventClassName(), this);

    #8 SkyAcer009, Nov 14, 2017 at 4:56 PM
    Last edited: Nov 14, 2017 at 5:01 PM
    • Download Essentials
    • Download EssentialsChat
    • Go to essentials config
    • go to format
    • and change it from there
    • Funny Funny x 1
  9. setFormat requires there to be two "%s" to put the displayname and message. You should never use getDisplayName and getMessage inside of setFormat, it's not needed, and will cause an error IIRC.

    e.setFormat("%s: %s");

    The first %s will be replaced with the displayname, second %s will be replaced by the message.
    • Informative Informative x 1
  10. You are joking right?
    • Agree Agree x 1
  11. N
  12. I have made a a ranks plugin before and I already tried this. It works.

Share This Page