Clickable Player Names in chat

Discussion in 'Plugin Development' started by T0pD0g, Dec 13, 2016.

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

    T0pD0g

    So I was trying to make Playernames in chat clickable. It basically works out the way i did i, but I guess it deletes all formating done by other Plugins to display the rank of players.

    Code:
        @EventHandler
        public void click(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
    
            comm = pl.getConfig().getString("source.command");
    
            IChatBaseComponent c1 = new ChatMessage(e.getPlayer().getDisplayName());
    
            c1.setChatModifier(new ChatModifier());
            c1.getChatModifier().setChatClickable(new ChatClickable(EnumClickAction.RUN_COMMAND, "/" + comm));
            IChatBaseComponent c2 = new ChatMessage(": " + e.getMessage());
            c1.addSibling(c2);
    
            p.setCustomName("");
            PlayerList list = MinecraftServer.getServer().getPlayerList();
            list.getPlayer(p.getName()).sendMessage(c1);
            p.setCustomName(p.getName());
            e.setCancelled(true);
        }
    Is there an easier way and also is it possible to take the format with you.
     
  2. Offline

    Wispyy

    Possibly this?
    Code:java
    1.  
    2. String format = e.getFormat();
    3. p.setCustomName(format + "name_that_you_want");
    4.  
     
  3. Offline

    A5H73Y

    Why are you doing this?
    Code:
    p.setCustomName("");
    Then this
    Code:
    p.setCustomName(p.getName());
    You're setting the custom name (the "formating done by other Plugins"), and setting it to just the players name.
     
Thread Status:
Not open for further replies.

Share This Page