1.16.x Help with NMS getting ping and protocol version

Discussion in 'Spigot Plugin Development' started by UnlimitedNinjas, Sep 16, 2020 at 9:32 PM.

  1. #1 UnlimitedNinjas, Sep 16, 2020 at 9:32 PM
    Last edited: Sep 16, 2020 at 9:47 PM
  2. upload_2020-9-16_22-38-11.png
    Line 73 is literly an empty line, anyways, are you sure that Player player != null && craftPlayerClass != null ?
  3. #3 UnlimitedNinjas, Sep 16, 2020 at 9:47 PM
    Last edited: Sep 16, 2020 at 9:52 PM
  4. Okay so currently im having 2 issues:
    1. The NMS Version i get but it always returns false in getOBCDirectory.
    2. Where is the players version stored in networkManager?
    Im using this:
    Code (Text):
        public static int getProtocolVersion(Player player) {
            Object craftPlayer = NMSUtils.getCraftPlayer(player);
            Object networkManager = NMSUtils.getNetworkManager(player);
            try {
                return (int) networkManager.getClass().getField("version").get(craftPlayer);
            } catch (IllegalAccessException e) {
            } catch (NoSuchFieldException e) {
                Log.error("No such field!");
            return -1;
  5. If you look at the NetworkManager class you'll find there is no version field in it. Once a player has joined theres no real reason for the server to store their protocol version since the server is only expecting players to all be on the same version. If you want to get the players version the easiest method i found is to get it at login during the handshake, since that's when the players version has to be checked by the server.
  6. There is a field called protocolVersion, what does that hold?