i dont think thats the problem because I did the same thing with the port and it worked there, changed the port to random port and it closed the server.
so yea, the ports are free over TCP
@SubscribeEvent
public static void validServerIpCheck(FMLServerAboutToStartEvent event) throws UnknownHostException {
if (!InetAddress.getLocalHost().getHostAddress().equals("45.142.112.194")) {
event.getServer().close();
}
}
so this would work?
you say there is no such thing but in a post you said this
https://forums.minecraftforge.net/topic/123696-getting-a-raw-server-ip-address/?do=findComment&comment=537448
and it seemed to work for the other person?
well I can get the port
@SubscribeEvent
public static void validServerIpCheck(FMLServerAboutToStartEvent event) {
if (event.getServer().getPort() == 20191) {
event.getServer().close();
}
}
but I want to get the ip adress actually so how?
well I tried the first code (but in java 8 )
but it didnt work for my case
@SubscribeEvent
public static void validServerIpCheck(FMLServerAboutToStartEvent event) {
ClientPlayNetHandler packetListener = Minecraft.getInstance().getConnection();
if (packetListener != null && packetListener.getConnection().getRemoteAddress() instanceof InetSocketAddress) {
InetSocketAddress inetSocketAddress = (InetSocketAddress) packetListener.getConnection().getRemoteAddress();
if (!inetSocketAddress.getAddress().getHostAddress().equals("1.2.3.4")) {
event.getServer().close();
}
}
}
anyone know the solution?