Solved How do I disable Clickable Links

Discussion in 'Spigot Plugin Development' started by fan87, Jul 12, 2021.

  1. So when you do ConsoleSender#sendMessage(String message) , it will detect if there's any URL in the message, after that, the URL will become clickable text, but how do I disable that?
    Not only sendMessage method, but every message that player got.
    Checked PacketPlayOutChat, and it contains clickable URL already, so it's not client stuff ( I guess?).

    EDIT: Solve, after 20 minutes of research, there are three ways to solve this problem:
    First, my English is not good, so there might be some grammar errors. but anyway, here's how you do it:
    1. Do a custom build of Spigot API
    If you are coding for a server, not a plugin, you will probably use this method.
    By building your own SpigotAPI, just run buildtools, it will prepare everything for you, and just go to the Spigot folder, and open pom.xml with your Java IDE as a project, then you can do custom builds.
    If you are using 1.17 or higher version of spigot, you'll probably want to remove Remap section in pom.xml, and you'll never want to decompile minecraft server cause I can't find any compiler that can decompile minecraft 1.17 correctly, I haven't try 1.16 yet, but I guess I'll use reflection + ASM to modify the minecraft server src.
    Back to topic, if you want to fix this issue, try and find sendRawMessage(String message_ method inside org.bukkit.craftbukkit.entity.CraftPlayer, there will be a for each loop inside the method. Remove that foreach loop, and add this line:
    getHandle().playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(message), ChatMessageType.SYSTEM, SystemUtils.b));
    It should work correctly.

    2. Modify PacketPlayOutChat packet
    You can do that by using ProtocolLib, or listen the packets by hooking player's packet channel (Using netty IO), it's not a big thing, just remove all clickable URLs inside the IChatBaseComponent, But it's harder than you thought, at least it's harder than I thought it is, you'll need around 5 minutes ~ 4 hours depends on how deep you understand NMS.

    3. ASM
    It's the worst way to do it, what it does is it will edit the bytecodes during runtime, and it's unsafe, and not that easy, but you can do it if you really want to.

    For me, the first one is the best opinion, cuz I'm coding for specific server, and I'm already using a custom build (To fix some bugs without using reflection), and I already set the Spigot workspace up, so it will only take me around 2 minutes to finish it.
    #1 fan87, Jul 12, 2021
    Last edited: Jul 14, 2021
  2. Are you asking how to prevent URL clicks?
  3. How to prevent from URL turning into clickable texts
    I was trying to do something like:
    player.sendMessage("{\"name\": \"commands.test.success\"}")
    Not actually this, but something like this, I use some illegal chars for this, and I decided to modify the packet via NMS even it's not an API (Yes, I know it's not an API, but the thing is it's for myself, so I don't need to care about server update cause it will always stay in 1.16.5)
    And the IChatBaseComponent just became a clickable test, and I can't use my code to read the language thing at all o _ o

    By the way, I can modify Spigot's SRC if I really need to, but I don't think that's the best way to do this.
    #3 fan87, Jul 12, 2021
    Last edited: Jul 12, 2021
  4. Turn off is possible within Minecraft.
    • Like Like x 1
  5. You have to look through the BaseComponent and remove the click event (tagged with the URL type) corresponding to any link text matching the standard link patter
    • Agree Agree x 1
  6. Good idea : D Thank you
    • Like Like x 1