So, I’ve been making a mod for Minecraft, where I need to check the server IP. I currently have the code in place, but I am getting a NoSuchFieldException because it’s a private field from another class. I am using ModLoaders getPrivateValue which uses reflection. I would rather not uses private values, and it needs to stay private.
Here’s the problem code:
public boolean isMCMEServer(EntityClientPlayerMP player) throws NoSuchFieldException {
NetworkManager manager = (NetworkManager) ModLoader.getPrivateValue(NetClientHandler.class, player.sendQueue, "netManager");
Socket socket = (Socket) ModLoader.getPrivateValue(NetworkManager.class, manager, "networkSocket");
InetAddress address = socket.getInetAddress();
if(address != null) {
String hostName = address.getHostName();
String hostAddress = address.getHostAddress();
if((hostAddress.equals(SERVER)) || (hostName.equals(SERVER))) {
return true;
}
}
return false;
}
I hope I’ve given enough info, thanks in advance
Still using private fields, but it turns out the problem was with obfuscation.