1.12.2 Clickable names in Chat

Discussion in 'Spigot Plugin Development' started by forgotth4ke, Feb 16, 2020.

  1. Hey guys.
    Is there anyway how i can get a click & hoverevent in names in Chat? (If Player X Sends a message,his Name should get the event)

    I just tried it with smth like this way
    (Not 100% correct,am on my Phone)

    OnChat( AsynvPlayerChatEvent e)

    Textcomponent x = New textcomponent(e.getPlayer().getDisplayname());


    Any1 got any ideas?:p
    Thy!
     
    • Friendly Friendly x 1
    • Friendly Friendly x 1
  2. Can you try this?
    Code (Java):
        public void OnChat(AsyncPlayerChatEvent e) {
            Player player = e.getPlayer();
            TextComponent x = new TextComponent(""+player.getName());      
        }
     
    #4 BlackNike6, Feb 16, 2020
    Last edited: Feb 16, 2020
    • Friendly Friendly x 1
  3. ill try it now,wait. :p
     

  4. Okay,still not working. :/
    Thanks anyway!
     
  5. Can you show your code?
     

  6. @EventHandler
    public void OnChat(AsyncPlayerChatEvent e) {
    Player player = e.getPlayer();
    TextComponent x = new TextComponent(""+player.getName());
    x.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("").create()));
    }

    (And ofc the Listener)
     
  7. You can try this:
    Code (Text):
    @EventHandler
        public void OnChat(AsyncPlayerChatEvent e) {
            Player player = e.getPlayer();
            TextComponent x = new TextComponent(player.getName());
            x.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Hello world").create()));
            x.addExtra(": "+e.getMessage());
           
            for (Player on : Bukkit.getOnlinePlayers()) {
                on.spigot().sendMessage(x);
            }
            e.setCancelled(true);
        }
     
    • Friendly Friendly x 1

  8. Hey!
    Just tried,didnt work,sadly.. :/
     
  9. It's weird that work for me. Did you register the listener?
     


  10. public class Main extends JavaPlugin implements Listener{


    @Override
    public void onEnable(){
    Bukkit.getPluginManager().registerEvents(this ,this);


    }

    Thats my Listener,should be fine,or did i something wrong there? :eek:
     
  11. Is your OnChat is in the Main class?
     
  12. Yes,just checked,it is. :eek:
     
  13. Did you have any error in the console? Is the plugin is correctly loaded? What do you see in the chat when you talk? Do you have another plugin?
     
  14. Console is : [click] Enabling click v1.0

    Im on my Testserver,so there is PemissionsEX ChatEX and my Plugin "click"
    version 1.12.2
     
  15. When youre saying its not working, what appears in the chat whem someone sends a message?
     
  16. Just the normal chatmassage.
    In this case,with PEX and ChatEX
    "Group Playername Message"
     
  17. That's because PEX and ChatEx are controlling the chat. You'll need to put a priority on your event if you want it to be the "main" one.
     
  18. How do i do that? :D