How to check players client name?

Discussion in 'Plugin Development' started by Xores, Dec 10, 2017.

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

    Xores

    How to check players minecraft client name?
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Impossible... Unfortunately... All you can get is their version, ex. 1.8 and not for example 1.8-Optifine. If this was possible, hacked clients would get banned before they could even log in.
     
  4. Offline

    Unknown123

    @Xores @timtower @nathanthesnooper It's actually possible. Hack clients just return vanilla. Little spoonfeeding here ;D
    Add this in your onEnable
    register listener (open)

    Code:
    Messenger messenger = Bukkit.getMessenger();
    messenger.registerIncomingPluginChannel(this, "MC|Brand", new BrandPluginMessageListener());

    read client name (open)

    Code:
    package XYZ;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.messaging.PluginMessageListener;
    
    import java.io.UnsupportedEncodingException;
    
    public class BrandPluginMessageListener implements PluginMessageListener {
        @Override
        public void onPluginMessageReceived(String channel, Player p, byte[] msg) {
            try {
                p.sendMessage("Your client brand: " + new String(msg, "UTF-8").substring(1));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }

    Thats really odd but for spigot 1.8.8 (maybe on other versions too) you need to add this method
    addChannel method (open)

    Code:
        private static void addChannel(Player p, String channel) {
            try {
                p.getClass().getMethod("addChannel", String.class).invoke(p, channel);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
                    | SecurityException e) {
                e.printStackTrace();
            }
        }

    and add this into a PlayerJoinEvent
    Code:
    addChannel(p, "MC|BRAND");
     
    Last edited: Dec 23, 2017
  5. Online

    timtower Administrator Administrator Moderator

    @Unknown123 Won't give any usable results though due to client modifications.
     
  6. Offline

    Unknown123

    @timtower Like I already said hack clients will return vanilla. But forge for example will return something like forge.
     
  7. Online

    timtower Administrator Administrator Moderator

    Unless somebody installed a mod to change it.
     
  8. Offline

    Unknown123

  9. @Unknown123
    Which nearly all hacked clients have done.

    This discussion has been had time and time again. You will barely catch any hackers at all using this technique. You're much better off just installing a proper anti cheat plugin.
     
  10. Offline

    Unknown123

    @AlvinB Sure but that is still a valid answer.
     
Thread Status:
Not open for further replies.

Share This Page